本文整理匯總了Golang中github.com/ory-am/fosite.AccessResponder.SetScopes方法的典型用法代碼示例。如果您正苦於以下問題:Golang AccessResponder.SetScopes方法的具體用法?Golang AccessResponder.SetScopes怎麽用?Golang AccessResponder.SetScopes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/ory-am/fosite.AccessResponder
的用法示例。
在下文中一共展示了AccessResponder.SetScopes方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: PopulateTokenEndpointResponse
// PopulateTokenEndpointResponse implements https://tools.ietf.org/html/rfc6749#section-6
func (c *RefreshTokenGrantHandler) PopulateTokenEndpointResponse(ctx context.Context, req *http.Request, requester fosite.AccessRequester, responder fosite.AccessResponder) error {
if !requester.GetGrantTypes().Exact("refresh_token") {
return errors.Wrap(fosite.ErrUnknownRequest, "")
}
accessToken, accessSignature, err := c.AccessTokenStrategy.GenerateAccessToken(ctx, requester)
if err != nil {
return errors.Wrap(fosite.ErrServerError, err.Error())
}
refreshToken, refreshSignature, err := c.RefreshTokenStrategy.GenerateRefreshToken(ctx, requester)
if err != nil {
return errors.Wrap(fosite.ErrServerError, err.Error())
}
signature := c.RefreshTokenStrategy.RefreshTokenSignature(req.PostForm.Get("refresh_token"))
if err := c.RefreshTokenGrantStorage.PersistRefreshTokenGrantSession(ctx, signature, accessSignature, refreshSignature, requester); err != nil {
return errors.Wrap(fosite.ErrServerError, err.Error())
}
responder.SetAccessToken(accessToken)
responder.SetTokenType("bearer")
responder.SetExpiresIn(getExpiresIn(requester, fosite.AccessToken, c.AccessTokenLifespan, time.Now()))
responder.SetScopes(requester.GetGrantedScopes())
responder.SetExtra("refresh_token", refreshToken)
return nil
}
示例2: IssueAccessToken
func (h *HandleHelper) IssueAccessToken(ctx context.Context, req *http.Request, requester fosite.AccessRequester, responder fosite.AccessResponder) error {
token, signature, err := h.AccessTokenStrategy.GenerateAccessToken(ctx, requester)
if err != nil {
return err
} else if err := h.AccessTokenStorage.CreateAccessTokenSession(ctx, signature, requester); err != nil {
return err
}
responder.SetAccessToken(token)
responder.SetTokenType("bearer")
responder.SetExpiresIn(getExpiresIn(requester, fosite.AccessToken, h.AccessTokenLifespan, time.Now()))
responder.SetScopes(requester.GetGrantedScopes())
return nil
}
示例3: PopulateTokenEndpointResponse
func (c *AuthorizeExplicitGrantHandler) PopulateTokenEndpointResponse(ctx context.Context, req *http.Request, requester fosite.AccessRequester, responder fosite.AccessResponder) error {
// grant_type REQUIRED.
// Value MUST be set to "authorization_code".
if !requester.GetGrantTypes().Exact("authorization_code") {
return errors.Wrap(fosite.ErrUnknownRequest, "")
}
code := req.PostForm.Get("code")
signature := c.AuthorizeCodeStrategy.AuthorizeCodeSignature(code)
authorizeRequest, err := c.AuthorizeCodeGrantStorage.GetAuthorizeCodeSession(ctx, signature, requester.GetSession())
if err != nil {
return errors.Wrap(fosite.ErrServerError, err.Error())
} else if err := c.AuthorizeCodeStrategy.ValidateAuthorizeCode(ctx, requester, code); err != nil {
return errors.Wrap(fosite.ErrInvalidRequest, err.Error())
}
access, accessSignature, err := c.AccessTokenStrategy.GenerateAccessToken(ctx, requester)
if err != nil {
return errors.Wrap(fosite.ErrServerError, err.Error())
}
for _, scope := range authorizeRequest.GetGrantedScopes() {
requester.GrantScope(scope)
}
var refresh, refreshSignature string
if authorizeRequest.GetGrantedScopes().Has("offline") {
refresh, refreshSignature, err = c.RefreshTokenStrategy.GenerateRefreshToken(ctx, requester)
if err != nil {
return errors.Wrap(fosite.ErrServerError, err.Error())
}
}
if err := c.AuthorizeCodeGrantStorage.PersistAuthorizeCodeGrantSession(ctx, signature, accessSignature, refreshSignature, requester); err != nil {
return errors.Wrap(fosite.ErrServerError, err.Error())
}
responder.SetAccessToken(access)
responder.SetTokenType("bearer")
responder.SetExpiresIn(getExpiresIn(requester, fosite.AccessToken, c.AccessTokenLifespan, time.Now()))
responder.SetScopes(requester.GetGrantedScopes())
if refresh != "" {
responder.SetExtra("refresh_token", refresh)
}
return nil
}