How to use the swagger-client.PasswordAuthorization function in swagger-client

To help you get started, we’ve selected a few swagger-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github asterisk / node-ari-client / lib / client.js View on Github external
return new Promise(function(resolve, reject) {

    swagger.authorizations.add(
      'basic-auth',
      new swagger.PasswordAuthorization(
        self._connection.hostname,
        self._connection.user,
        self._connection.pass
      )
    );

    // Connect to API using swagger and attach resources on Client instance
    var ariUrl = util.format(
      '%s//%s/ari/api-docs/resources.json',
      self._connection.protocol,
      self._connection.host
    );

    request(ariUrl, function (err) {
      if (err &&
        ['ETIMEDOUT', 'ENOTFOUND', 'ECONNREFUSED'].indexOf(err.code) !== -1) {
github kmi / node-red-contrib-swagger / swagger / node-red-contrib-swagger.js View on Github external
// ensure we have the same kind of credentials necessary
                var authType = node.credentials.authType;
                var user = node.credentials.user;
                var password = node.credentials.password;

                if (authType != undefined && scheme != undefined && authType === scheme.type) {
                    // Add the credentials to the client
                    switch(scheme.type) {
                        case 'apiKey':
                            node.swaggerClient.clientAuthorizations.add(scheme.name, new SwaggerClient.ApiKeyAuthorization(scheme.keyname, password, scheme.passAs));
                            break;

                        case 'basic':
                            // The first parameter for the password authorization is unclear to me (and not used by node.swagger-client?)
                            node.swaggerClient.clientAuthorizations.add(scheme.name, new SwaggerClient.PasswordAuthorization(scheme.type, user, password));
                            break;

                        //TODO: handle oauth2
                    }
                } else if (authType != undefined && authType !== scheme.type) {
                    // We can't provide the credentials. Warn?
                    node.warn("This API requires authentication of type " + scheme.type + " . No appropriate credentials have been provided. Please reconfigure the node.");
                }
            }
        }
    }
github asterisk / node-ari-client / Gruntfile.js View on Github external
var operations = '';
    var events = '';

    var operationTemplate = fs.readFileSync(
      './dev/operation.mustache',
      'utf-8'
    );
    var eventTemplate = fs.readFileSync(
      './dev/event.mustache',
      'utf-8'
    );

    var parsedUrl = url.parse(options.baseUrl);
    swagger.authorizations.add(
      'basic-auth',
      new swagger.PasswordAuthorization(
        parsedUrl.hostname,
        options.username,
        options.password
      )
    );

    // Connect to API using swagger and attach resources on Client instance
    var resourcesUrl = util.format(
      '%s//%s/ari/api-docs/resources.json',
      parsedUrl.protocol,
      parsedUrl.host
    );
    var swaggerClient = new swagger.SwaggerApi({
      url: resourcesUrl,
      success: swaggerLoaded,
      failure: swaggerFailed
github appcelerator / appc.swagger / lib / schema / fetchSchema.js View on Github external
schema: {},
      logger: logger || require('arrow').createLogger({}, {
        name: 'appc.swagger', useConsole: true, level: 'debug'
      }),
      options: options
    },
    tasks = [],
    clientOptions = {
      url: options.swaggerDocs
    }

	// Did they tell us how to login to the API? Great! Do so.
  if (options.login) {
    clientOptions.authorizations = {}
    if (options.login.username) {
      clientOptions.authorizations.Basic = new SwaggerClient.PasswordAuthorization(options.login.username, options.login.password || '')
    }
    if (options.login.apiKey) {
      clientOptions.authorizations.APIKey = new SwaggerClient.ApiKeyAuthorization(options.login.apiKey.name, options.login.apiKey.value, options.login.apiKey.type || 'query')
    }
  }

	// Download the swagger docs!
  tasks.push(function (next) {
    var client
    params.logger.trace('Downloading ' + options.swaggerDocs)

		/**
		 * Called when swagger client successfully grabbed the swagger API docs
		 */
    clientOptions.success = function () {
      params.swaggerObject = client.swaggerObject
github khangiskhan / swagger-commander / lib / apiOperationCommander.js View on Github external
function parsePasswordAuth(string) {
    var values = string.split(/,(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))/).map(_trim);
    if (values.length !== 3) {
        logger.error('Unexpected input for password auth');
        return false;
    }
    var authName = values[0],
        user = values[1],
        password = values[2],
        authObj = {};
    authObj[authName] = new Swagger.PasswordAuthorization(user, password);
    return authObj;
}
github strongloop / loopback-connector-swagger / lib / swagger-connector.js View on Github external
SwaggerConnector.prototype.setupAuth = function() {
  const client = this.client;

  if (this.settings.security) {
    const secConfig = this.settings.security || this.settings;
    if (debug.enabled) {
      debug('configuring security: %j', secConfig);
    }
    switch (secConfig.type) {
      case 'basic':
        client.clientAuthorizations.add(
          'basic',
          new SwaggerClient.PasswordAuthorization(secConfig.username,
            secConfig.password)
        );
        break;

      case 'apiKey':
        const authObj = new SwaggerClient.ApiKeyAuthorization(
          secConfig.name, secConfig.key, secConfig.in
        );
        client.clientAuthorizations.add(secConfig.name,
          authObj);
        break;

      case 'oauth2':
        const oauth = new oAuth.AccessTokenAuthorization(
          secConfig.name,
          secConfig.accessToken,