UNPKG

@axway/amplify-sdk

Version:

Axway Amplify SDK for Node.js

118 lines (105 loc) 2.75 kB
import Authenticator from './authenticator.js'; import errors from '../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 'crypto'; import 'get-port'; import 'http'; import 'url'; import '../util.js'; const { AuthorizationCode, ClientCredentials } = Authenticator.GrantTypes; /** * Authentication scheme using a pre-shared secret token. By default, the authentication process is * interactive unless it is a service account. */ class ClientSecret extends Authenticator { /** * Initializes an client secret authentication instance. * * @param {Object} opts - Various options. * @param {String} opts.clientSecret - The secret token to use to authenticate. * @param {Boolean} [opts.serviceAccount=false] - When `true`, indicates authentication is being * requested by a service instead of a user. * @access public */ constructor(opts) { if (!opts || typeof opts !== 'object') { throw errors.INVALID_ARGUMENT('Expected options to be an object'); } if (!opts.clientSecret || typeof opts.clientSecret !== 'string') { throw errors.INVALID_ARGUMENT('Expected client secret to be a non-empty string'); } super(opts); this.shouldFetchOrgs = !opts.serviceAccount; Object.defineProperty(this, 'clientSecret', { value: opts.clientSecret }); } /** * Parameters to include in the authenticated account object. Note that these values are * stripped when the Amplify SDK returns the account object. * * @type {Object} * @access private */ get authenticatorParams() { return { clientSecret: this.clientSecret }; } /** * Parameters to include in the interactive authorization URL. * * @type {Object} * @access private */ get authorizationUrlParams() { return { grantType: this.interactive ? AuthorizationCode : ClientCredentials }; } /** * Parameters to base the authenticator hash on. * * @type {Object} * @access private */ get hashParams() { return { clientSecret: this.clientSecret }; } /** * Parameters to include with authentication requests. * * @type {Object} * @access private */ get tokenParams() { return { clientSecret: this.clientSecret, grantType: this.interactive ? AuthorizationCode : ClientCredentials }; } /** * Parameters to include with refresh requests. * * @type {Object} * @access private */ get refreshTokenParams() { return { clientSecret: this.clientSecret }; } } export { ClientSecret as default }; //# sourceMappingURL=client-secret.js.map