Auth0-spa-js: Request additional scopes

Created on 16 Nov 2020  路  3Comments  路  Source: auth0/auth0-spa-js

I would like to be able to specify the scopes required when authenticating

I've tried using advanced options default scope but I can only seem to use this to remove scopes. I want to add the google calendar read-only scope

            this.auth0Client = await createAuth0Client({
                domain: options.domain,
                client_id: options.clientId,
                audience: options.audience,
                redirect_uri: redirectUri,
                advancedOptions: {
                    defaultScope: 'profile email https://www.googleapis.com/auth/calendar.readonly'
                }
            });

I know I could use incremental authorization and use getTokenSilently but I'd rather request them all upfront.

Thank you

feature request

All 3 comments

I would like to be able to specify the scopes required when authenticating

Have you tried using scope on createAuth0Client (https://auth0.github.io/auth0-spa-js/interfaces/auth0clientoptions.html#scope) ?

createAuth0Client({ scope: 'https://www.googleapis.com/auth/calendar.readonly' })

Alternatively you can provide scope when calling loginWithRedirect (https://auth0.github.io/auth0-spa-js/interfaces/redirectloginoptions.html#scope) or loginWithPopup (https://auth0.github.io/auth0-spa-js/interfaces/popuploginoptions.html#scope):

loginWithRedirect({ scope: 'https://www.googleapis.com/auth/calendar.readonly' })
loginWithPopup({ scope: 'https://www.googleapis.com/auth/calendar.readonly' })

Does this help?

I've tried using advanced options default scope but I can only seem to use this to remove scopes.

I am not sure I understand what you mean with this.

I think what you are looking for would be to use connection_scope, as mentioned here : https://auth0.com/docs/connections/adding-scopes-for-an-external-idp#2-pass-scopes-to-authorize-endpoint which u can pass to loginWithRedirect as follows:

loginWithRedirect({ connection_scope: 'https://www.googleapis.com/auth/calendar.readonly' })

Thank you @frederikprijck, This worked

loginWithRedirect({ scope: 'https://www.googleapis.com/auth/calendar.readonly' })
loginWithPopup({ scope: 'https://www.googleapis.com/auth/calendar.readonly' })

I appreciate your help :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Hopchenko picture Hopchenko  路  6Comments

ed-sparkes picture ed-sparkes  路  7Comments

Dig-Doug picture Dig-Doug  路  5Comments

chbert picture chbert  路  5Comments

jackoliver picture jackoliver  路  5Comments