Skip to content

Instantly share code, notes, and snippets.

@cskiwi
Created November 16, 2025 12:01
Show Gist options
  • Select an option

  • Save cskiwi/5cc454240201479c4531e6a50d777f26 to your computer and use it in GitHub Desktop.

Select an option

Save cskiwi/5cc454240201479c4531e6a50d777f26 to your computer and use it in GitHub Desktop.
Apollo Auth0 Pre-Flight script
const issuer = explorer.environment.get('AUTH0_ISSUER_URL')
const audience = explorer.environment.get('AUTH0_AUDIENCE')
const client_id = explorer.environment.get('AUTH0_CLIENT_ID')
const client_secret = explorer.environment.get('AUTH0_CLIENT_SECRET')
const config = {
client_id,
client_secret,
audience,
scope: 'openid profile email offline_access',
}
function validateConfig(cfg) {
for (const k of Object.keys(cfg)) {
if (!cfg[k]) throw new Error(`Missing config value for ${k}`)
}
}
validateConfig(config)
let futureDate = explorer.environment.get('futureDate')
const now = Date.now()
if (!futureDate || now >= futureDate) {
const authUrl = `https://${issuer}/authorize`
const result = await explorer.oauth2Request(authUrl, {
client_id: config.client_id,
client_secret: config.client_secret,
audience: config.audience,
scope: config.scope,
response_type: 'token',
})
const token = result.access_token
const parsed = JSON.parse(atob(token.split('.')[1]));
explorer.environment.set('Authorization', token);
explorer.environment.set('futureDate', `${parsed.exp}000`)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment