1
1
package auth
2
2
3
+ // StreamingCredentialsProvider is an interface that defines the methods for a streaming credentials provider.
4
+ // It is used to provide credentials for authentication.
5
+ // The CredentialsListener is used to receive updates when the credentials change.
3
6
type StreamingCredentialsProvider interface {
4
- // Subscribe subscribes to the credentials provider and returns a channel that will receive updates.
5
- // The first response is blocking, then data will be pushed to the channel.
7
+ // Subscribe subscribes to the credentials provider for updates.
8
+ // It returns the current credentials, a cancel function to unsubscribe from the provider,
9
+ // and an error if any.
6
10
Subscribe (listener CredentialsListener ) (Credentials , CancelProviderFunc , error )
7
11
}
8
12
13
+ // CancelProviderFunc is a function that is used to cancel the subscription to the credentials provider.
14
+ // It is used to unsubscribe from the provider when the credentials are no longer needed.
9
15
type CancelProviderFunc func () error
10
16
17
+ // CredentialsListener is an interface that defines the methods for a credentials listener.
18
+ // It is used to receive updates when the credentials change.
19
+ // The OnNext method is called when the credentials change.
20
+ // The OnError method is called when an error occurs while requesting the credentials.
11
21
type CredentialsListener interface {
12
22
OnNext (credentials Credentials )
13
23
OnError (err error )
14
24
}
15
25
26
+ // Credentials is an interface that defines the methods for credentials.
27
+ // It is used to provide the credentials for authentication.
16
28
type Credentials interface {
29
+ // BasicAuth returns the username and password for basic authentication.
17
30
BasicAuth () (username string , password string )
31
+ // RawCredentials returns the raw credentials as a string.
32
+ // This can be used to extract the username and password from the raw credentials or
33
+ // additional information if present in the token.
18
34
RawCredentials () string
19
35
}
20
36
@@ -23,15 +39,18 @@ type basicAuth struct {
23
39
password string
24
40
}
25
41
42
+ // RawCredentials returns the raw credentials as a string.
26
43
func (b * basicAuth ) RawCredentials () string {
27
44
return b .username + ":" + b .password
28
45
}
29
46
47
+ // BasicAuth returns the username and password for basic authentication.
30
48
func (b * basicAuth ) BasicAuth () (username string , password string ) {
31
49
return b .username , b .password
32
50
}
33
51
34
- func NewCredentials (username , password string ) Credentials {
52
+ // NewBasicCredentials creates a new Credentials object from the given username and password.
53
+ func NewBasicCredentials (username , password string ) Credentials {
35
54
return & basicAuth {
36
55
username : username ,
37
56
password : password ,
0 commit comments