@@ -6,11 +6,24 @@ import (
6
6
"github.com/redis/go-redis/v9/auth"
7
7
)
8
8
9
- // Token represents the authentication token used to access the Entraid API.
10
- // It contains the username, password, expiration time, time to live, and the raw token.
11
- // The token is used to authenticate the user and authorize access to the API.
12
- // The token is typically obtained from an identity provider and is used to access the Entraid API.
13
- // The token is valid for a limited time and must be refreshed periodically.
9
+ // Ensure Token implements the auth.Credentials interface.
10
+ var _ auth.Credentials = (* Token )(nil )
11
+
12
+ // New creates a new token with the specified username, password, raw token, expiration time, received at time, and time to live.
13
+ // NOTE: This won't do any validation on the token, expiresOn, receivedAt, or ttl. It will simply create a new token instance.
14
+ func New (username , password , rawToken string , expiresOn , receivedAt time.Time , ttl int64 ) * Token {
15
+ return & Token {
16
+ username : username ,
17
+ password : password ,
18
+ expiresOn : expiresOn ,
19
+ receivedAt : receivedAt ,
20
+ ttl : ttl ,
21
+ rawToken : rawToken ,
22
+ }
23
+ }
24
+
25
+ // Token represents parsed authentication token used to access the Redis server.
26
+ // It implements the auth.Credentials interface.
14
27
type Token struct {
15
28
// username is the username of the user.
16
29
username string
@@ -27,13 +40,11 @@ type Token struct {
27
40
}
28
41
29
42
// BasicAuth returns the username and password for basic authentication.
30
- // It implements the auth.Credentials interface.
31
43
func (t * Token ) BasicAuth () (string , string ) {
32
44
return t .username , t .password
33
45
}
34
46
35
47
// RawCredentials returns the raw credentials for authentication.
36
- // It implements the auth.Credentials interface.
37
48
func (t * Token ) RawCredentials () string {
38
49
return t .rawToken
39
50
}
@@ -43,33 +54,11 @@ func (t *Token) ExpirationOn() time.Time {
43
54
return t .expiresOn
44
55
}
45
56
46
- // Token implements the auth.Credentials interface.
47
- var _ auth.Credentials = (* Token )(nil )
48
-
49
- // New creates a new token with the specified username, password, raw token, expiration time, received at time, and time to live.
50
- func New (username , password , rawToken string , expiresOn , receivedAt time.Time , ttl int64 ) * Token {
51
- return & Token {
52
- username : username ,
53
- password : password ,
54
- expiresOn : expiresOn ,
55
- receivedAt : receivedAt ,
56
- ttl : ttl ,
57
- rawToken : rawToken ,
58
- }
59
- }
60
-
57
+ // Copy creates a copy of the token.
61
58
func (t * Token ) Copy () * Token {
62
59
return copyToken (t )
63
60
}
64
61
65
- // copyToken creates a copy of the token.
66
- func copyToken (token * Token ) * Token {
67
- if token == nil {
68
- return nil
69
- }
70
- return New (token .username , token .password , token .rawToken , token .expiresOn , token .receivedAt , token .ttl )
71
- }
72
-
73
62
// compareCredentials two tokens if they are the same credentials
74
63
func (t * Token ) compareCredentials (token * Token ) bool {
75
64
return t .username == token .username && t .password == token .password
@@ -84,3 +73,11 @@ func (t *Token) compareRawCredentials(token *Token) bool {
84
73
func (t * Token ) compareToken (token * Token ) bool {
85
74
return t .compareCredentials (token ) && t .compareRawCredentials (token )
86
75
}
76
+
77
+ // copyToken creates a copy of the token.
78
+ func copyToken (token * Token ) * Token {
79
+ if token == nil {
80
+ return nil
81
+ }
82
+ return New (token .username , token .password , token .rawToken , token .expiresOn , token .receivedAt , token .ttl )
83
+ }
0 commit comments