aboutsummaryrefslogtreecommitdiff
path: root/internal/auth/model.go
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--internal/auth/model.go49
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,
+ }
+}