forked from ory/fosite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.go
30 lines (25 loc) · 836 Bytes
/
helper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package oauth2
import (
"net/http"
"time"
"github.com/ory-am/fosite"
"golang.org/x/net/context"
)
type HandleHelper struct {
AccessTokenStrategy AccessTokenStrategy
AccessTokenStorage AccessTokenStorage
AccessTokenLifespan time.Duration
}
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(h.AccessTokenLifespan / time.Second)
responder.SetScopes(requester.GetGrantedScopes())
return nil
}