11package auth
22
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.
36type 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.
610 Subscribe (listener CredentialsListener ) (Credentials , CancelProviderFunc , error )
711}
812
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.
915type CancelProviderFunc func () error
1016
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.
1121type CredentialsListener interface {
1222 OnNext (credentials Credentials )
1323 OnError (err error )
1424}
1525
26+ // Credentials is an interface that defines the methods for credentials.
27+ // It is used to provide the credentials for authentication.
1628type Credentials interface {
29+ // BasicAuth returns the username and password for basic authentication.
1730 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.
1834 RawCredentials () string
1935}
2036
@@ -23,15 +39,18 @@ type basicAuth struct {
2339 password string
2440}
2541
42+ // RawCredentials returns the raw credentials as a string.
2643func (b * basicAuth ) RawCredentials () string {
2744 return b .username + ":" + b .password
2845}
2946
47+ // BasicAuth returns the username and password for basic authentication.
3048func (b * basicAuth ) BasicAuth () (username string , password string ) {
3149 return b .username , b .password
3250}
3351
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 {
3554 return & basicAuth {
3655 username : username ,
3756 password : password ,
0 commit comments