-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.go
39 lines (33 loc) · 1.09 KB
/
models.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
package models
import (
"time"
"github.com/paczulapiotr/goauth2/security"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// User struct for mapping mongo data
type User struct {
ID primitive.ObjectID `bson:"_id,omitempty"`
Login string `bson:"login,omitempty"`
PasswordHash string `bson:"passwordHash,omitempty"`
Auth OAuth2 `bson:"auth"`
}
// CheckPassword check password for UserDao struct
func (user User) CheckPassword(password string) bool {
return security.CheckPasswordHash(user.PasswordHash, password)
}
// OAuth2 struct for JWT data
type OAuth2 struct {
Code string `bson:"code"`
CodeValidUntil time.Time `bson:"codeValidUntil"`
AccessToken string `bson:"accessToken"`
ValidUntil time.Time `bson:"validUntil"`
RefreshToken string `bson:"refreshToken"`
RefreshValidUntil time.Time `bson:"refreshValidUntil"`
Claims []Claim `bson:"claims"`
LastAuth time.Time `bson:"lastAuth"`
}
// Claim struct for JWT claims
type Claim struct {
Key string
Value string
}