forked from RichardKnop/go-oauth2-server
/
response.go
42 lines (38 loc) · 1.24 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
package oauth
import (
"github.com/RichardKnop/go-oauth2-server/models"
)
// AccessTokenResponse ...
type AccessTokenResponse struct {
UserID uint `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 {
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 *models.OauthAccessToken, refreshToken *models.OauthRefreshToken, lifetime int, theTokenType string) (*AccessTokenResponse, error) {
response := &AccessTokenResponse{
AccessToken: accessToken.Token,
ExpiresIn: lifetime,
TokenType: theTokenType,
Scope: accessToken.Scope,
}
if accessToken.User != nil {
response.UserID = accessToken.User.MetaUserID
}
if refreshToken != nil {
response.RefreshToken = refreshToken.Token
}
return response, nil
}