github.com/jxgolibs/go-oauth2-server@v1.0.1/oauth/response.go (about) 1 package oauth 2 3 import ( 4 "github.com/RichardKnop/go-oauth2-server/models" 5 ) 6 7 // AccessTokenResponse ... 8 type AccessTokenResponse struct { 9 UserID string `json:"user_id,omitempty"` 10 AccessToken string `json:"access_token"` 11 ExpiresIn int `json:"expires_in"` 12 TokenType string `json:"token_type"` 13 Scope string `json:"scope"` 14 RefreshToken string `json:"refresh_token,omitempty"` 15 } 16 17 // IntrospectResponse ... 18 type IntrospectResponse struct { 19 Active bool `json:"active"` 20 Scope string `json:"scope,omitempty"` 21 ClientID string `json:"client_id,omitempty"` 22 Username string `json:"username,omitempty"` 23 TokenType string `json:"token_type,omitempty"` 24 ExpiresAt int `json:"exp,omitempty"` 25 } 26 27 // NewAccessTokenResponse ... 28 func NewAccessTokenResponse(accessToken *models.OauthAccessToken, refreshToken *models.OauthRefreshToken, lifetime int, theTokenType string) (*AccessTokenResponse, error) { 29 response := &AccessTokenResponse{ 30 AccessToken: accessToken.Token, 31 ExpiresIn: lifetime, 32 TokenType: theTokenType, 33 Scope: accessToken.Scope, 34 } 35 if accessToken.UserID.Valid { 36 response.UserID = accessToken.UserID.String 37 } 38 if refreshToken != nil { 39 response.RefreshToken = refreshToken.Token 40 } 41 return response, nil 42 }