-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
OAuth2 Support in Cobra Through Integration or Libraries #2217
Comments
Interesting: it seems the design is sane. Your root command executes some of the components from the library which is how I've seen this type of flow work in other cases. One thing I've thought about and wondered if it makes sense to bring into cobra is an idea of command "middleware" that developers can build into all commands that have registered middleware.
From a |
I agree that Cobra is an incredibly powerful tool for building CLI applications, but there seems to be an opportunity to further enhance its extensibility. It would be fantastic if there was a built-in plugin feature that would allow users to easily extend their Cobra-based CLI apps without directly modifying the core codebase. Here’s an idea for a potential plugin interface that could be added: // Plugin is an interface that all plugins must implement
type Plugin interface {
// Initialize the plugin
Initialize() error
// AddCommands adds commands to the given root command
AddCommands(rootCmd *cobra.Command) error
} |
Yeah, this is something we faced when building Tanzu Community Edition at VMware: there's not a great way to extend the existing capabilities of a CLI without either a) modifying the core code / libraries Thoughts on a plugin system @marckhouzam ? What has Tanzu been doing more recently? |
While building an internal CLI tool with Cobra, I needed to integrate authentication with our backend services using OAuth2. Specifically, I was looking to implement the [device authorization flow](https://datatracker.ietf.org/doc/html/rfc8628). However, I found that there wasn’t an easy-to-use library for this purpose that integrates well with Cobra.
Suggestion
To address this, I started developing a library, [cobra-oauth2](https://github.com/nauthera/cobra-oauth2), aimed at simplifying the integration of OAuth2 flows into Cobra-based CLI tools. The library is in its early stages and currently supports basic features, but it is designed to be easy to use and extend.
Here’s a basic example of how to use
cobra-oauth2
:Example Usage
1. Main Application Setup
Define your main entry point and execute your Cobra CLI:
2. Root Command Setup
Set up the root command and initialize OAuth2 commands:
Question for the Community
Contribution
I’d love feedback on the design and implementation of
cobra-oauth2
. Contributions and ideas for extending its capabilities (e.g., support for additional OAuth2 flows, enhanced storage mechanisms, etc.) are welcome!Repo: https://github.com/nauthera/cobra-oauth2
The text was updated successfully, but these errors were encountered: