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