Skip to content

Commit 9d9d71a

Browse files
committed
reorder file
1 parent 049bcc2 commit 9d9d71a

File tree

1 file changed

+27
-30
lines changed

1 file changed

+27
-30
lines changed

token/token.go

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,24 @@ import (
66
"github.com/redis/go-redis/v9/auth"
77
)
88

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.
1427
type Token struct {
1528
// username is the username of the user.
1629
username string
@@ -27,13 +40,11 @@ type Token struct {
2740
}
2841

2942
// BasicAuth returns the username and password for basic authentication.
30-
// It implements the auth.Credentials interface.
3143
func (t *Token) BasicAuth() (string, string) {
3244
return t.username, t.password
3345
}
3446

3547
// RawCredentials returns the raw credentials for authentication.
36-
// It implements the auth.Credentials interface.
3748
func (t *Token) RawCredentials() string {
3849
return t.rawToken
3950
}
@@ -43,33 +54,11 @@ func (t *Token) ExpirationOn() time.Time {
4354
return t.expiresOn
4455
}
4556

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.
6158
func (t *Token) Copy() *Token {
6259
return copyToken(t)
6360
}
6461

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-
7362
// compareCredentials two tokens if they are the same credentials
7463
func (t *Token) compareCredentials(token *Token) bool {
7564
return t.username == token.username && t.password == token.password
@@ -84,3 +73,11 @@ func (t *Token) compareRawCredentials(token *Token) bool {
8473
func (t *Token) compareToken(token *Token) bool {
8574
return t.compareCredentials(token) && t.compareRawCredentials(token)
8675
}
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

Comments
 (0)