//GetAccessToken returns the access token from the authorization header or from the query parameters.
// If the authorization header starts with "bearer", "" is returned
332177
func (om *OAuth2Middleware) GetAccessToken(r *http.Request) string {

	authorizationHeader := r.Header.Get("Authorization")

	if authorizationHeader == "" {
		accessTokenQueryParameter := r.URL.Query().Get("access_token")
		return accessTokenQueryParameter
	}
	if strings.HasPrefix(authorizationHeader, "bearer ") || strings.HasPrefix(authorizationHeader, "Bearer ") {
		return ""
	}
	accessToken := strings.TrimSpace(strings.TrimPrefix(authorizationHeader, "token"))
	return accessToken
}
772936
func (self *OAuth2Mixin) GetAccessToken(r *http.Request) (*oauth2.Token, error) {

	code := r.URL.Query().Get("code")
	if len(code) == 0 {
		return nil, errors.New("No Access Code in the Request URL")
	}

	accessToken, err := self.Client.GrantToken(code)
	if err != nil {
		return nil, err
	}

	return accessToken, err
}
980748
func (cl *Client) GenerateAccessToken(c context.Context, serviceAccount string, scopes []string, delegates []string, lifetime time.Duration) (*oauth2.Token, error) {
	var body struct {
		Delegates []string `json:"delegates"`
		Scope     []string `json:"scope"`
		Lifetime  string   `json:"lifetime,omitempty"`
	}

	body.Scope = scopes
	body.Delegates = delegates

	// Default lifetime is 3600 seconds according to API documentation.
	// Requesting longer lifetime will cause an API error which is
	// forwarded to the caller.
	if lifetime > 0 {
		body.Lifetime = lifetime.String()
	}

	var resp struct {
		AccessToken string `json:"accessToken"`
		ExpireTime  string `json:"expireTime"`
	}
	if err := cl.credentialsAPIRequest(c, fmt.Sprintf("projects/-/serviceAccounts/%s", url.QueryEscape(serviceAccount)), "generateAccessToken", &body, &resp); err != nil {
		return nil, err
	}

	expires, err := time.Parse(time.RFC3339, resp.ExpireTime)
	if err != nil {
		err = fmt.Errorf("Unable to parse 'expireTime': %s", resp.ExpireTime)
		logging.WithError(err).Errorf(c, "Bad token endpoint response, unable to parse expireTime")
		return nil, err
	}

	return &oauth2.Token{
		AccessToken: resp.AccessToken,
		TokenType:   tokenType,
		Expiry:      expires.UTC(),
	}, nil

}
1132479
func (p *ecrTokenGetter) GetAuthorizationToken(input *ecr.GetAuthorizationTokenInput) (*ecr.GetAuthorizationTokenOutput, error) {
	return p.svc.GetAuthorizationToken(input)
}
73640
func (twilio *Twilio) NewAccessToken() *AccessToken {
	return &AccessToken{
		AccountSid:   twilio.AccountSid,
		APIKeySid:    twilio.APIKeySid,
		APIKeySecret: twilio.APIKeySecret,
	}
}
1039460
func (c *Client) GetToken() (string, error) {
	token, err := c.config.TokenSource.Token()
	if err != nil {
		return "", fmt.Errorf("Error getting bearer token: %v", err)
	}
	return "bearer " + token.AccessToken, nil
}
825551
func (ctx *Context) GetComponentAccessToken() (string, error) {
	accessTokenCacheKey := fmt.Sprintf("component_access_token_%s", ctx.AppID)
	val := ctx.Cache.Get(accessTokenCacheKey)
	if val == nil {
		return "", fmt.Errorf("cann't get component access token")
	}
	return val.(string), nil
}
35123
func (s *ForgetDeviceInput) SetAccessToken(v string) *ForgetDeviceInput {
	s.AccessToken = &v
	return s
}
391125
func (s *ListDevicesInput) SetAccessToken(v string) *ListDevicesInput {
	s.AccessToken = &v
	return s
}
465322
func (s *DeleteUserInput) SetAccessToken(v string) *DeleteUserInput {
	s.AccessToken = &v
	return s
}
30993
func UpdateAccessToken(t *AccessToken) error {
	_, err := x.Id(t.ID).AllCols().Update(t)
	return err
}
782421
func (s *SetUserMFAPreferenceInput) SetAccessToken(v string) *SetUserMFAPreferenceInput {
	s.AccessToken = &v
	return s
}
533375
func (s *GetUserInput) SetAccessToken(v string) *GetUserInput {
	s.AccessToken = &v
	return s
}
115009
func (m *MockClientCredentialsGrantStorage) GetAccessTokenSession(arg0 context.Context, arg1 string, arg2 fosite.Session) (fosite.Requester, error) {
	ret := m.ctrl.Call(m, "GetAccessTokenSession", arg0, arg1, arg2)
	ret0, _ := ret[0].(fosite.Requester)
	ret1, _ := ret[1].(error)
	return ret0, ret1
}
1135412
func (a *AccessTokenGenDefault) GenerateAccessToken(data *AccessData, generaterefresh bool) (accesstoken string, refreshtoken string, err error) {
	token := uuid.NewRandom()
	accesstoken = base64.RawURLEncoding.EncodeToString([]byte(token))

	if generaterefresh {
		rtoken := uuid.NewRandom()
		refreshtoken = base64.RawURLEncoding.EncodeToString([]byte(rtoken))
	}
	return
}
298858
func (r *repo) FindByAccessToken(accessToken string) (at service.Access, err error) {
	if err := dbconn.DB.Where("access_token = ?", accessToken).First(&at).Error; err != nil {
		return service.Access{}, err
	}
	return
}
867149
func GetOAuthToken(client httpClient, clientID, clientSecret, code, redirectURI string) (accessToken string, scope string, err error) {
	return GetOAuthTokenContext(context.Background(), client, clientID, clientSecret, code, redirectURI)
}