optimizely-oauth2
v1.0.5
Published
A tiny module for Optimizely X OAuth2
Downloads
3
Readme
Optimizely OAuth2
Why?
To provide a small and lightweight client for Optimizely X OAuth2. This is used in conjunction with the Optimizely X CLI. I thought splitting the two could provide more reusable code, and more value to the community.
Usage
Start by including the client.
const OptxOauth = require('./lib/optx-oauth')()
Optionally, you can also set the following parameters, defaults are provided.
const OptxOauth = require('./lib/optx-oauth')({
redirectUri: // Defaults to 'http://localhost'
redirectPort: // Defaults to '8080'
redirectPath: '/path/for/callback' // Defaults to /authorize
clientId: 'YOUR_OPTIMIZELY_CLIENT_ID' // This doesn't have to be set on initialization
clientSecret: 'YOUR_OPTIMIZELY_CLIENT_SECRET' // This doesn't have to be set on initialization
timeout: 30000 // Otherwise the servers' default timeout is used
})
Only two functions are available in this client, Authorize
and Refresh
. Nice and simple!
// Opens a new browser window and requests Optimizely authorization.
OptxOauth.Authorize({
clientId: 'YOUR_OPTIMIZELY_CLIENT_ID', // If you didn't already provide it on initialization
clientSecret: 'YOUR_OPTIMIZELY_CLIENT_SECRET', // If you didn't already provide it on initialization
accountId: '4123412' // Your account ID, this is OPTIONAL
})
.then(result => console.log(result))
//{ statusCode: 200,
// statusMessage: 'OK',
// body:
// { access_token: 'GENERATED_ACCESS_TOKEN',
// token_type: 'bearer',
// expires_in: 7200,
// succeeded: true,
// refresh_token: '2:ea348521f4f44289949ad416503193dc' } }
// Use your refresh token to generate a new access code. Don't have a refresh token? OptxOauth.Authorize and start the process over.
OptxOauth.Refresh({
clientId: 'YOUR_OPTIMIZELY_CLIENT_ID', // If you didn't already provide it on initialization
clientSecret: 'YOUR_OPTIMIZELY_CLIENT_SECRET', // If you didn't already provide it on initialization
refreshToken: 'THE_GENERATED_REFRESH_TOKEN'
})
.then(result => console.log(result))
//{ statusCode: 200,
// statusMessage: 'OK',
// body:
// { access_token: 'GENERATED_ACCESS_TOKEN',
// token_type: 'bearer',
// expires_in: 7200,
// succeeded: true } }