From 689a57ec4a444f8233fe2e5ec7ceb0903218218d Mon Sep 17 00:00:00 2001 From: Max Resnick Date: Fri, 14 Aug 2020 23:13:41 -0700 Subject: feat: working login gauth --- internal/auth/model.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 internal/auth/model.go (limited to 'internal/auth/model.go') diff --git a/internal/auth/model.go b/internal/auth/model.go new file mode 100644 index 0000000..c51ff05 --- /dev/null +++ b/internal/auth/model.go @@ -0,0 +1,49 @@ +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, + } +} -- cgit v1.2.3