diff options
| author | Max Resnick <max@ofmax.li> | 2020-08-14 23:13:41 -0700 |
|---|---|---|
| committer | Max Resnick <max@ofmax.li> | 2020-11-08 07:57:13 -0800 |
| commit | 689a57ec4a444f8233fe2e5ec7ceb0903218218d (patch) | |
| tree | 1bcfe6786c38b4ae11997d5d97dc3c5fba747b97 /internal/auth/model.go | |
| parent | 77c2e6aca2dc0f851f55e30a0f49c9ee7c2c952e (diff) | |
| download | iserv-master.tar.gz | |
Diffstat (limited to '')
| -rw-r--r-- | internal/auth/model.go | 49 |
1 files changed, 49 insertions, 0 deletions
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, + } +} |