Skip to content

Commit 906e4c4

Browse files
committed
use token instead of authCredentials
1 parent 3f5cdcd commit 906e4c4

File tree

3 files changed

+7
-39
lines changed

3 files changed

+7
-39
lines changed

credentials.go

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1 @@
11
package entraid
2-
3-
import (
4-
auth "github.com/redis/go-redis/v9/auth"
5-
)
6-
7-
// authCredentials implements the auth.Credentials interface.
8-
var _ auth.Credentials = (*authCredentials)(nil)
9-
10-
// authCredentials represents the authentication credentials used to access the Entraid API.
11-
// It contains the username, password, and raw credentials.
12-
// The authCredentials struct is used to store the authentication credentials
13-
type authCredentials struct {
14-
username string
15-
password string
16-
rawCredentials string
17-
}
18-
19-
// BasicAuth returns the username and password for basic authentication.
20-
func (a *authCredentials) BasicAuth() (username string, password string) {
21-
return a.username, a.password
22-
}
23-
24-
// RawCredentials returns the raw credentials for authentication.
25-
func (a *authCredentials) RawCredentials() string {
26-
return a.rawCredentials
27-
}

credentials_provider.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@ func (e *entraidCredentialsProvider) onTokenNext(token *Token) {
3131
defer e.rwLock.RUnlock()
3232
// Notify all listeners with the new token.
3333
for _, listener := range e.listeners {
34-
listener.OnNext(&authCredentials{
35-
username: token.Username,
36-
password: token.Password,
37-
rawCredentials: token.RawToken,
38-
})
34+
listener.OnNext(token)
3935
}
4036
}
4137

@@ -78,15 +74,8 @@ func (e *entraidCredentialsProvider) Subscribe(listener auth.CredentialsListener
7874
return nil, nil, err
7975
}
8076

81-
// Create a new credentials object.
82-
credentials := &authCredentials{
83-
username: token.Username,
84-
password: token.Password,
85-
rawCredentials: token.RawToken,
86-
}
87-
8877
// Notify the listener with the credentials.
89-
listener.OnNext(credentials)
78+
listener.OnNext(token)
9079

9180
cancel := func() error {
9281
// Remove the listener from the list of listeners.

token.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package entraid
22

33
import (
44
"time"
5+
6+
"github.com/redis/go-redis/v9/auth"
57
)
68

79
// Token represents the authentication token used to access the Entraid API.
@@ -53,6 +55,9 @@ func (t *Token) ExpirationOn() time.Time {
5355
return t.expiresOn
5456
}
5557

58+
// Token implements the auth.Credentials interface.
59+
var _ auth.Credentials = (*Token)(nil)
60+
5661
// NewToken creates a new token with the specified username, password, raw token, expiration time, received at time, and time to live.
5762
func NewToken(username, password, rawToken string, expiresOn, receivedAt time.Time, ttl int64) *Token {
5863
return &Token{

0 commit comments

Comments
 (0)