-
Notifications
You must be signed in to change notification settings - Fork 558
Publish Auth Interface #112
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
df58532
feat(auth): implement interface-based authentication for publishing
sridharavinash db809d9
fix(docs): correct command-line argument formatting in README
sridharavinash 4f3f4bd
fix(docs): remove obsoleted option
sridharavinash ce81bab
fix(docs): update example usage for GitHub OAuth Provider and improve…
sridharavinash 0af3c7f
fix(auth): better logging when an auth method is unsupported
sridharavinash 1a89435
fix(docs): update docs
sridharavinash 5d42d44
fix(docs): fix for consistency
sridharavinash 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 |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| # Authentication System | ||
|
|
||
| The publisher tool now uses an interface-based authentication system that allows for multiple authentication mechanisms. | ||
|
|
||
| ## Architecture | ||
|
|
||
| ### Provider Interface | ||
|
|
||
| The `Provider` interface is defined in `auth/interface.go` and provides the following methods: | ||
|
|
||
| - `GetToken(ctx context.Context) (string, error)` - Retrieves or generates an authentication token | ||
| - `NeedsLogin() bool` - Checks if a new login flow is required | ||
| - `Login(ctx context.Context) error` - Performs the authentication flow | ||
| - `Name() string` - Returns the name of the authentication provider | ||
|
|
||
| ### Available Authentication Providers | ||
|
|
||
| #### 1. GitHub OAuth Provider | ||
| - **Location**: `auth/github/oauth.go` | ||
| - **Usage**: Uses GitHub's device flow for authentication | ||
| - **Example**: `github.NewOAuthProvider(forceLogin, registryURL)` | ||
|
|
||
|
|
||
| ## How to Add New Authentication Providers | ||
|
|
||
| 1. Create a new package under `auth/` directory (e.g., `auth/custom/`) | ||
| 2. Implement the `Provider` interface | ||
| 3. Add any necessary configuration or initialization functions | ||
| 4. Update the main application to use the new provider | ||
|
|
||
| ### Example Implementation | ||
|
|
||
| ```go | ||
| package custom | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| ) | ||
|
|
||
| type CustomProvider struct { | ||
| // your custom fields | ||
| } | ||
|
|
||
| func NewCustomProvider(config string) *CustomProvider { | ||
| return &CustomProvider{ | ||
| // initialize your provider | ||
| } | ||
| } | ||
|
|
||
| func (cp *CustomProvider) GetToken(ctx context.Context) (string, error) { | ||
| // implement token retrieval logic | ||
| return "custom-token", nil | ||
| } | ||
|
|
||
| func (cp *CustomProvider) NeedsLogin() bool { | ||
| // implement login check logic | ||
| return false | ||
| } | ||
|
|
||
| func (cp *CustomProvider) Login(ctx context.Context) error { | ||
| // implement authentication flow | ||
| return nil | ||
| } | ||
|
|
||
| func (cp *CustomProvider) Name() string { | ||
| return "custom-auth" | ||
| } | ||
| ``` | ||
|
|
||
| ## Usage in Main Application | ||
|
|
||
| The main application automatically selects the appropriate authentication provider: | ||
|
|
||
| 1. Uses `GitHub OAuth Provider` by default | ||
| 2. Future providers can be added by extending the provider selection logic | ||
|
|
||
| ```go | ||
| // Create the appropriate auth provider based on configuration | ||
| var authProvider auth.Provider | ||
| switch authMethod { | ||
| case "github-oauth": | ||
| log.Println("Using GitHub OAuth for authentication") | ||
| authProvider = github.NewOAuthProvider(forceLogin, registryURL) | ||
| default: | ||
| log.Printf("Unsupported authentication method: %s\n", authMethod) | ||
| return | ||
| } | ||
|
|
||
| // Check if login is needed and perform authentication | ||
| ctx := context.Background() | ||
| if authProvider.NeedsLogin() { | ||
| err := authProvider.Login(ctx) | ||
| if err != nil { | ||
| log.Printf("Failed to authenticate with %s: %s\n", authProvider.Name(), err.Error()) | ||
| return | ||
| } | ||
| } | ||
|
|
||
| // Get the token | ||
| token, err := authProvider.GetToken(ctx) | ||
| ``` | ||
|
|
||
| This design allows for easy extension and testing of different authentication mechanisms while maintaining a clean separation of concerns. |
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.
Uh oh!
There was an error while loading. Please reload this page.