Skip to content

Commit 4c74f10

Browse files
Merge pull request #6 from zentered/fix/offline-access
fix: set offline_access scope for /authorize call
2 parents 13d9d99 + 069839d commit 4c74f10

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/api/callback.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ async function auth0FetchOAuthToken(code, state, redirectUrl, organization) {
2323
`https://${process.env.VITE_AUTH0_DOMAIN}/oauth/token`
2424
)
2525

26-
const formData = new URLSearchParams()
2726
const scopes = ['openid', 'profile', 'email']
27+
if (process.env.VITE_AUTH0_OFFLINE_ACCESS === 'true') {
28+
scopes.push('offline_access')
29+
}
30+
31+
const formData = new URLSearchParams()
2832
formData.append('grant_type', 'authorization_code')
2933
formData.append('client_id', process.env.VITE_AUTH0_CLIENT_ID)
3034
formData.append('client_secret', process.env.AUTH0_CLIENT_SECRET)
3135
formData.append('code', code)
3236
formData.append('state', state)
3337
formData.append('redirect_uri', redirectUrl)
34-
35-
if (process.env.VITE_AUTH0_OFFLINE_ACCESS === 'true') {
36-
scopes.push('offline_access')
37-
}
3838
formData.append('scope', scopes.join(' '))
3939

4040
if (organization) {

src/index.jsx

+6
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,18 @@ export function Auth0(props) {
2424
const [userId, setUserId] = createSignal()
2525
const [organization, setOrganization] = createSignal()
2626

27+
const scopes = ['openid', 'profile', 'email']
28+
if (process.env.VITE_AUTH0_OFFLINE_ACCESS === 'true') {
29+
scopes.push('offline_access')
30+
}
31+
2732
const webAuthnConfig = {
2833
_sendTelemetry: false,
2934
domain: auth0config.domain,
3035
clientID: auth0config.clientId,
3136
audience: auth0config.audience,
3237
redirectUri: auth0config.redirectUri,
38+
scopes: scopes.join(' '),
3339
responseType: 'code'
3440
}
3541

0 commit comments

Comments
 (0)