-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
claim.go
110 lines (90 loc) · 2.12 KB
/
claim.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright 2020 Patrick Ascher <pat@fullhouse-productions.com>. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package jwt
import "github.com/dgrijalva/jwt-go"
// Claimer interface
type Claimer interface {
SetJid(string)
Jid() string
SetIss(string)
Iss() string
SetAud(string)
Aud() string
SetSub(string)
Sub() string
Iat() int64
SetIat(int64)
Exp() int64
SetExp(int64)
Nbf() int64
SetNbf(int64)
// Render should return the needed data for the frontend.
Render() interface{}
// Valid is defined in the jwt-go package but can get overwritten here.
Valid() error
}
// Claim that implements the Claimer interface.
type Claim struct {
jwt.StandardClaims
}
// SetJid set the JID of the token.
func (c *Claim) SetJid(id string) {
c.Id = id
}
// Jid get the JID of the token.
func (c *Claim) Jid() string {
return c.Id
}
// SetIss set the ISSUER of the token.
func (c *Claim) SetIss(iss string) {
c.Issuer = iss
}
// Iss get the ISSUER of the token.
func (c *Claim) Iss() string {
return c.Issuer
}
// SetAud set the AUDIENCE of the token.
func (c *Claim) SetAud(aud string) {
c.Audience = aud
}
// Aud get the AUDIENCE of the token.
func (c *Claim) Aud() string {
return c.Audience
}
// SetSub set the SUBJECT of the token.
func (c *Claim) SetSub(sub string) {
c.Subject = sub
}
// Sub get the SUBJECT of the token.
func (c *Claim) Sub() string {
return c.Subject
}
// SetIat set the ISSUED AT of the token.
func (c *Claim) SetIat(iat int64) {
c.IssuedAt = iat
}
// Iat get the ISSUED AT of the token.
func (c *Claim) Iat() int64 {
return c.IssuedAt
}
// SetExp set the EXPIRED of the token.
func (c *Claim) SetExp(exp int64) {
c.ExpiresAt = exp
}
// Exp get the EXPIRED of the token.
func (c *Claim) Exp() int64 {
return c.ExpiresAt
}
// SetNbf set the NOT BEFORE of the token.
func (c *Claim) SetNbf(nbf int64) {
c.NotBefore = nbf
}
// Nbf get the NOT BEFORE of the token.
func (c *Claim) Nbf() int64 {
return c.NotBefore
}
// Render should return the needed claim data for the frontend.
func (c *Claim) Render() interface{} {
return ""
}