generated from resonatecoop/id-server-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
response.go
45 lines (41 loc) · 1.38 KB
/
response.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package oauth
import (
"github.com/google/uuid"
"github.com/resonatecoop/id/util"
"github.com/resonatecoop/user-api/model"
)
// AccessTokenResponse ...
type AccessTokenResponse struct {
UserID string `json:"user_id,omitempty"`
AccessToken string `json:"access_token"`
ExpiresIn int `json:"expires_in"`
TokenType string `json:"token_type"`
Scope string `json:"scope"`
RefreshToken string `json:"refresh_token,omitempty"`
}
// IntrospectResponse ...
type IntrospectResponse struct {
UserID string `json:"user_id,omitempty"`
Active bool `json:"active"`
Scope string `json:"scope,omitempty"`
ClientID string `json:"client_id,omitempty"`
Username string `json:"username,omitempty"`
TokenType string `json:"token_type,omitempty"`
ExpiresAt int `json:"exp,omitempty"`
}
// NewAccessTokenResponse ...
func NewAccessTokenResponse(accessToken *model.AccessToken, refreshToken *model.RefreshToken, lifetime int, theTokenType string) (*AccessTokenResponse, error) {
response := &AccessTokenResponse{
AccessToken: accessToken.Token,
ExpiresIn: lifetime,
TokenType: theTokenType,
Scope: accessToken.Scope,
}
if util.IsValidUUID(accessToken.UserID.String()) && accessToken.UserID != uuid.Nil {
response.UserID = accessToken.UserID.String()
}
if refreshToken != nil {
response.RefreshToken = refreshToken.Token
}
return response, nil
}