-
Notifications
You must be signed in to change notification settings - Fork 55
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
DXCDT-296: Supporting additional scopes when authenticating as user #561
Conversation
// Start kicks-off the device authentication flow by requesting | ||
// a device code from Auth0. The returned state contains the | ||
// URI for the next step of the flow. | ||
func (a *Authenticator) Start(ctx context.Context) (State, error) { |
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.
A bit of a refactor here. Removing the Start
function because it only exists as a function wrapper for getDeviceCode
. Further, the name wasn't descriptive of what the function did.
// GetDeviceCode kicks-off the device authentication flow by requesting | ||
// a device code from Auth0. The returned state contains the | ||
// URI for the next step of the flow. | ||
func (a *Authenticator) GetDeviceCode(ctx context.Context, additionalScopes []string) (State, error) { |
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.
The only functional change here is the addition of the additionalScopes
argument, which enables the passing of additional scopes when requesting a grant.
internal/auth/auth.go
Outdated
if err != nil { | ||
return State{}, fmt.Errorf("failed to create the request: %w", err) | ||
} | ||
scopesToRequest := append(requiredScopes, additionalScopes...) |
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.
Change to note – combining the required scopes with additional scopes.
…auth0-cli into DXCDT-296-dynamic-scoping
…auth0-cli into DXCDT-296-dynamic-scoping
@@ -27,6 +28,7 @@ auth0 login --domain <tenant-domain> --client-id <client-id> --client-secret <cl | |||
--client-secret string Client secret of the application when authenticating via client credentials. | |||
--domain string Tenant domain of the application when authenticating via client credentials. | |||
-h, --help help for login | |||
--scopes strings Additional scopes to request when authenticating via device code flow. By default, only scopes for first-class functions are requested. Primarily useful when using the api command to execute arbitrary Management API requests. |
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.
Any way we can support the use case mentioned in #556 (only X scopes when scripting)? Note that as we add support for more and more resources, the number of scopes requested initially will keep going up. This is probably fine for human usage, but for machine usage we'll probably want to find an alternative.
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.
Absolutely. However, that is a separate task. This PR only pertains to scoping with respect to device code flow, whereas #556 is concerned with client credentials. I think that work is better suited for its own PR.
* DXCDT-287: Remove format flag in favor of json flag (#533) * DXCDT-288: Add perms alias for permissions subcommand (#534) * DXCDT-286: Relegate --force flag from global context (#535) * DXCDT-286: Hide global flags from commands when not applicable (#536) * [1/4] DXCDT-266: Move domains subcommand one level up the hierarchy (#539) * [2/4] DXCDT-266: Bring branding emails command under email templates (#540) * Back-merging `main` into `v1` (#543) DXCDT-293: Access token management for client credentials (#537) * Storing and refreshing access token for client credentials * Removing unnecessary comment * Removing tenant name from being stored, removing flag declarations * Removing tenant name from being stored * Fixing erroneous delete * Simplifying ExpiresAt assignment * Remove duplicate addTenant in tenants add command * Remove setting scopes on tenant when using client credentials * Refactor how we check for token expiration while preparing the tenant * Refactor cli.prepareTenant func * Refactor cli.setup func Co-authored-by: Will Vedder <[email protected]> Co-authored-by: Sergiu Ghitea <[email protected]> Co-authored-by: Will Vedder <[email protected]> Co-authored-by: Sergiu Ghitea <[email protected]> * [3/4] DXCDT-266: Rename branding cmd to universal-login (#541) * [4/4] DXCDT-266: Update docs after branding command refactor (#542) * DXCDT-283: Remove `config` command (#532) Co-authored-by: Will Vedder <[email protected]> * DXCDT-267: Consolidate `auth0 add tenants` into `auth0 login` (1/x) (#546) Co-authored-by: Will Vedder <[email protected]> Co-authored-by: Sergiu Ghitea <[email protected]> * DXCDT-267: Graceful handling of access token regeneration (2/x) (#547) Co-authored-by: Rita Zerrizuela <[email protected]> Co-authored-by: Will Vedder <[email protected]> Co-authored-by: Sergiu Ghitea <[email protected]> * DXCDT-298: Interactive login prompt (3/x) (#551) Co-authored-by: Rita Zerrizuela <[email protected]> Co-authored-by: Will Vedder <[email protected]> Co-authored-by: Sergiu Ghitea <[email protected]> Co-authored-by: Sergiu Ghitea <[email protected]> * DXCDT-295: Refactor quickstarts command to use quickstart meta URL (#553) * DXCDT-297: Remove env var ingestion (#554) Removing environment variable ingestion, removing unnecessary comment Co-authored-by: Will Vedder <[email protected]> * DXCDT-271: Add ci step to check that docs are up to date (#560) * DXCDT-271: Move bundle install out of make docs and into docs-start (#562) * DXCDT-296: Supporting additional scopes when authenticating as user (#561) * Adding additional scopes support via --scopes flag * Adding additional scopes support via --scopes flag * Removing logging * Uncommenting scope, removing Start function * Condensing error to single line * Fixing linting errors * Changing test * Updating docs * Unpluralizing text, setting nil default value * Fixing bad help text * Tiny refactors on the login cmd * Fixing linting error * Update internal/auth/auth.go Co-authored-by: Will Vedder <[email protected]> Co-authored-by: Rita Zerrizuela <[email protected]> Co-authored-by: Sergiu Ghitea <[email protected]> Co-authored-by: Sergiu Ghitea <[email protected]> * DXCDT-271: Fix generated docs (#563) * Rename build_doc to doc-gen * Downgrade json flag from persistent to local * Update doc pages * DXCDT-272 Add install script and update README (#564) Co-authored-by: Will Vedder <[email protected]> Co-authored-by: Will Vedder <[email protected]> * DXCDT-273: Authentication documentation (#565) Co-authored-by: Will Vedder <[email protected]> * Updating README * Targeting main branch before we forget to change back Co-authored-by: Sergiu Ghitea <[email protected]> Co-authored-by: Will Vedder <[email protected]> Co-authored-by: Sergiu Ghitea <[email protected]> Co-authored-by: Rita Zerrizuela <[email protected]>
🔧 Changes
In #538 we added nearly all of the Management API scopes to enable out-the-box support for the
api
command. In hindsight, this over-provisioning of scopes was unnecessary and at worse a liability for some. Instead, we're only provisioning scopes for first-class CLI features during initial grant, additional scopes can be requested with the--scopes
flag duringauth0 login
. Example:This flag provides a flexible means of providing feature parity through the
api
command while not overtly violating the principle of least privilege. Also, a nice side effect of this change is that new Management API features that come with accompanying scopes have immediate support, no need to wait for those scopes to be added to the code base.In addition to supporting this behavior, 403 "insufficient scope" errors are detected and a crafted error message is made to guide the user to rectify using the
--scopes
flag. See:📚 References
Related PRs:
🔬 Testing
📝 Checklist