UNPKG

@axway/amplify-sdk

Version:

Axway Amplify SDK for Node.js

86 lines (77 loc) 1.9 kB
import Authenticator from './authenticator.js'; import crypto from 'crypto'; import '../errors.js'; import 'ejs'; import 'fs-extra'; import '../endpoints.js'; import 'jws'; import 'open'; import 'path'; import 'snooplogg'; import '../stores/token-store.js'; import 'pluralize'; import '../environments-C3ppEMBw.js'; import '@axway/amplify-request'; import '../server.js'; import 'get-port'; import 'http'; import 'url'; import '../util.js'; /** * Authentication scheme using a Proof Key for Code Exchange (PKCE) and an interactive login. */ class PKCE extends Authenticator { /** * A random string used by the server when creating the auth code during interactive * authentication and verified by the server when retrieving the access token. * @type {String} */ codeVerifier = null; /** * Initializes an PKCE authentication instance. * * @param {Object} opts - Various options. * @access public */ constructor(opts) { super(opts); this.codeVerifier = crypto.randomBytes(32) .toString('base64') .replace(/\+/g, '.') .replace(/[=/]/g, '_'); this.interactive = true; } /** * Parameters to include in the interactive authorization URL. * * @type {Object} * @access private */ get authorizationUrlParams() { const codeChallenge = crypto.createHash('sha256') .update(this.codeVerifier) .digest('base64') .split('=')[0] .replace(/\+/g, '-') .replace(/\//g, '_'); return { codeChallenge: codeChallenge, codeChallengeMethod: 'S256', grantType: Authenticator.GrantTypes.AuthorizationCode }; } /** * Parameters to include with authentication requests. * * @type {Object} * @access private */ get tokenParams() { return { codeVerifier: this.codeVerifier, grantType: Authenticator.GrantTypes.AuthorizationCode }; } } export { PKCE as default }; //# sourceMappingURL=pkce.js.map