-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat: Introducing StreamingCredentialsProvider for token based authentication #3320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ndyakov
wants to merge
26
commits into
master
Choose a base branch
from
ndyakov/token-based-auth
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
5410adb
wip
ndyakov 9ef438b
Merge remote-tracking branch 'origin/master' into ndyakov/token-based…
ndyakov df9bfce
update documentation
ndyakov 140a278
add streamingcredentialsprovider in options
ndyakov d3a25f9
Merge branch 'master' into ndyakov/token-based-auth
ndyakov 7f5d87b
fix: put back option in pool creation
ndyakov fa59cce
add package level comment
ndyakov c248425
Merge branch 'master' into ndyakov/token-based-auth
ndyakov 847f1f9
Merge branch 'master' into ndyakov/token-based-auth
ndyakov 40a89c5
Initial re authentication implementation
ndyakov d0a8c76
Change function type name
ndyakov e0c224d
Merge branch 'master' into ndyakov/token-based-auth
ndyakov 44628c5
add tests
ndyakov 4ab4980
fix race in tests
ndyakov 420c4fb
fix example tests
ndyakov 5fac913
wip, hooks refactor
ndyakov 2a97f2e
fix build
ndyakov f103a7d
update README.md
ndyakov 6e17fb4
Merge branch 'master' into ndyakov/token-based-auth
ndyakov 3acfb1c
update wordlist
ndyakov 7eea9e7
update README.md
ndyakov 5f91e66
Merge branch 'master' into ndyakov/token-based-auth
ndyakov d0bfdab
refactor(auth): early returns in cred listener
ndyakov f6f892d
Merge branch 'master' into ndyakov/token-based-auth
ndyakov 544bdb2
fix(doctest): simulate some delay
ndyakov cff6b9b
Merge branch 'master' into ndyakov/token-based-auth
ndyakov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ testdata/* | |
redis8tests.sh | ||
coverage.txt | ||
**/coverage.txt | ||
.vscode | ||
.vscode | ||
tmp/* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Package auth package provides authentication-related interfaces and types. | ||
// It also includes a basic implementation of credentials using username and password. | ||
package auth | ||
|
||
// StreamingCredentialsProvider is an interface that defines the methods for a streaming credentials provider. | ||
// It is used to provide credentials for authentication. | ||
// The CredentialsListener is used to receive updates when the credentials change. | ||
type StreamingCredentialsProvider interface { | ||
// Subscribe subscribes to the credentials provider for updates. | ||
// It returns the current credentials, a cancel function to unsubscribe from the provider, | ||
// and an error if any. | ||
// TODO(ndyakov): Should we add context to the Subscribe method? | ||
Subscribe(listener CredentialsListener) (Credentials, UnsubscribeFunc, error) | ||
} | ||
|
||
// UnsubscribeFunc is a function that is used to cancel the subscription to the credentials provider. | ||
// It is used to unsubscribe from the provider when the credentials are no longer needed. | ||
type UnsubscribeFunc func() error | ||
|
||
// CredentialsListener is an interface that defines the methods for a credentials listener. | ||
// It is used to receive updates when the credentials change. | ||
// The OnNext method is called when the credentials change. | ||
// The OnError method is called when an error occurs while requesting the credentials. | ||
type CredentialsListener interface { | ||
OnNext(credentials Credentials) | ||
OnError(err error) | ||
} | ||
|
||
// Credentials is an interface that defines the methods for credentials. | ||
// It is used to provide the credentials for authentication. | ||
type Credentials interface { | ||
// BasicAuth returns the username and password for basic authentication. | ||
BasicAuth() (username string, password string) | ||
// RawCredentials returns the raw credentials as a string. | ||
// This can be used to extract the username and password from the raw credentials or | ||
// additional information if present in the token. | ||
RawCredentials() string | ||
} | ||
|
||
type basicAuth struct { | ||
username string | ||
password string | ||
} | ||
|
||
// RawCredentials returns the raw credentials as a string. | ||
func (b *basicAuth) RawCredentials() string { | ||
return b.username + ":" + b.password | ||
} | ||
|
||
// BasicAuth returns the username and password for basic authentication. | ||
func (b *basicAuth) BasicAuth() (username string, password string) { | ||
return b.username, b.password | ||
} | ||
|
||
// NewBasicCredentials creates a new Credentials object from the given username and password. | ||
func NewBasicCredentials(username, password string) Credentials { | ||
return &basicAuth{ | ||
username: username, | ||
password: password, | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's mention this is still an experimental feature