-
Notifications
You must be signed in to change notification settings - Fork 0
/
login_identity.go
42 lines (37 loc) · 1006 Bytes
/
login_identity.go
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
39
40
41
42
package auth
import (
"github.com/pestanko/gouthy/app/domain/apps"
"github.com/pestanko/gouthy/app/domain/users"
"github.com/pestanko/gouthy/app/jwtlib"
"github.com/pestanko/gouthy/app/shared"
log "github.com/sirupsen/logrus"
)
type LoginIdentity struct {
UserId string `json:"user_id"`
ClientId string `json:"client_id"`
Scopes shared.Scopes `json:"scopes"`
}
func CreateLoginIdentityFromToken(token jwtlib.Jwt) *LoginIdentity {
if token == nil {
return nil
}
return &LoginIdentity{
UserId: token.UserId(),
ClientId: token.AppId(), // same as an audience
Scopes: token.Scopes(),
}
}
func NewLoginIdentity(user *users.User, app *apps.Application, scopes []string) *LoginIdentity {
return &LoginIdentity{
UserId: user.ID.String(),
ClientId: app.ClientId,
Scopes: scopes,
}
}
func (id *LoginIdentity) LogFields() log.Fields {
return log.Fields{
"login_client_id": id.ClientId,
"login_uid": id.UserId,
"login_scopes": id.Scopes,
}
}