package auth import ( "time" "golang.org/x/oauth2" ) // GoogleAuthProfile auth'd user profile // ProfileId, Email, Name, PictureURL type GoogleAuthProfile struct { ProfileID string `json:"sub"` Email string `json:"email"` Name string `json:"name"` PictureURL string `json:"picture"` } // Profile profile and token // Identifier + Token type Profile struct { ID string `json:"sub"` Email string `json:"email"` AccessToken string `json:"access_token"` TokenType string `json:"token_type,omitempty"` RefreshToken string `json:"refresh_token,omitempty"` Expiry time.Time `json:"expiry,omitempty"` } // Token token from profile func (ap *Profile) Token() (*oauth2.Token, error) { return &oauth2.Token{ AccessToken: ap.AccessToken, TokenType: ap.TokenType, RefreshToken: ap.RefreshToken, Expiry: ap.Expiry, }, nil } // NewAuthProfile merge token and profile func NewAuthProfile(t *oauth2.Token, u *GoogleAuthProfile) *Profile { return &Profile{ u.ProfileID, u.Email, t.AccessToken, t.TokenType, t.RefreshToken, t.Expiry, } }