aboutsummaryrefslogtreecommitdiff
path: root/internal/auth/model.go
blob: 240b11bc075582c58877fabee0746b0d8183d209 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package auth

import (
	"time"

	"golang.org/x/oauth2"
)

// Profile profile and token
// Identifier + Token
type Profile struct {
	ID           string    `json:"sub"`
	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, id string) *Profile {
	return &Profile{
		id,
		t.AccessToken,
		t.TokenType,
		t.RefreshToken,
		t.Expiry,
	}
}