How to use the swagger-client.ApiKeyAuthorization 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 openstf / stf-appium-example / scripts / stf_disconnect.js View on Github external
var Swagger = require('swagger-client');

var SWAGGER_URL = 'http://localhost:7100/api/v1/swagger.json'
var AUTH_TOKEN  = '03f5e019a2f94a35b90c30e40829395b5a0d0f0e7fd14bc496a176b03e229540';


var client = new Swagger({
  url: SWAGGER_URL
, usePromise: true
, authorizations: {
    accessTokenAuth: new Swagger.ApiKeyAuthorization('Authorization', 'Bearer ' + AUTH_TOKEN, 'header')
  }
})

var serial = process.argv.slice(2)[0]

client.then(function(api) {
  return api.user.getUserDevices({
    serial: serial
  , fields: 'serial,present,ready,using,owner'
  }).then(function(res) {
      // check if device can be added or not
      var devices = res.obj.devices

      var hasDevice = false
      devices.forEach(function(device) {
        if(device.serial === serial) {
github se02035 / Viber-and-the-Microsoft-Bot-Framework / source / microsoftBotConnectorNew.js View on Github external
}).then((client) => {
                logger.debug('Swagger client ready');

                // add authorization header
                client.clientAuthorizations.add('AuthorizationBotConnector', new Swagger.ApiKeyAuthorization('Authorization', 'BotConnector ' + directLineSecret, 'header'));
                return client;
            }).catch((err) =>
                logger.error('Error initializing DirectLine client', err));
github microsoft / BotBuilder-Samples / Node / core-DirectLine / DirectLineClient / app.js View on Github external
.then(function (client) {
        // add authorization header to client
        client.clientAuthorizations.add('AuthorizationBotConnector', new Swagger.ApiKeyAuthorization('Authorization', 'Bearer ' + directLineSecret, 'header'));
        return client;
    })
    .catch(function (err) {
github wso2 / carbon-apimgt / components / web / apps / org.wso2.carbon.apimgt.publisher_originaluufapp / src / main / pages / src / app / data / api.js View on Github external
_requestMetaData(data = {}) {
        AuthClient.refreshTokenOnExpire();
        let access_key_header = "Bearer " + AuthClient.getCookie("WSO2_AM_TOKEN_1");
        let request_meta = {
            clientAuthorizations: {
                am_token1: new SwaggerClient.ApiKeyAuthorization("Authorization", access_key_header, "header")
            },
            requestContentType: data['Content-Type'] || "application/json"
        };
        let am_token2 = AuthClient.getCookie('WSO2_AM_TOKEN_MSF4J'); // This cookie is meant to be send via browser, Hence this will be overridden by browser
        if (am_token2) {
            request_meta.clientAuthorizations['am_token2'] = new SwaggerClient.ApiKeyAuthorization("Cookie", "WSO2_AM_TOKEN_MSF4J=" + am_token2, "header")
        }
        return request_meta;
    }
github wso2 / carbon-apimgt / features / apimgt / org.wso2.carbon.apimgt.publisher.feature / src / main / resources / publisher / source / src / app / data / api.js View on Github external
_requestMetaData(data = {}) {
        AuthClient.refreshTokenOnExpire();
        let access_key_header = "Bearer " + AuthClient.getUser().getPartialToken(); // Anti-CSRF token
        let request_meta = {
            clientAuthorizations: {
                am_token1: new SwaggerClient.ApiKeyAuthorization("Authorization", access_key_header, "header")
            },
            requestContentType: data['Content-Type'] || "application/json"
        };
        let am_token2 = Utils.getCookie('WSO2_AM_TOKEN_MSF4J'); // This cookie is meant to be send via browser, Hence this will be overridden by browser
        if (am_token2) {
            request_meta.clientAuthorizations['am_token2'] = new SwaggerClient.ApiKeyAuthorization("Cookie", "WSO2_AM_TOKEN_MSF4J=" + am_token2, "header")
        }
        return request_meta;
    }
github Objelisks / everypunk / bot.js View on Github external
function doThing() {
    var wordnik = new Swagger({
        url: 'http://api.wordnik.com/v4/resources.json',
        success: function() {
            wordnik.words.getRandomWord(randomParams, {responseContentType: 'application/json'}, function(res) {
                var word = res.obj.word + 'punk';
                post(word, function() { });
            });
        },
        authorizations: {
            'apiKey': new Swagger.ApiKeyAuthorization('api_key', creds.wordnik, 'query')
        }
    });
    console.log(wordnik);
}
github couchbaselabs / react-native-couchbase-lite / index.js View on Github external
.then(client => {
      var encodedCredentials = "Basic " + base64.encode(url.split("//")[1].split('@')[0]);
      client.clientAuthorizations.add("auth", new Swagger.ApiKeyAuthorization('Authorization', encodedCredentials, 'header'));
      manager = client;
      if (typeof callback == 'function') {
        callback(manager);
      }
    });
github RackHD / on-web-ui / src / monorail / views / Settings.js View on Github external
rackhdAPICheck = ({ resolve, reject }) => {
    let swaggerOptions = {
      usePromise: true,
      authorizations : {},
      url: this.rackhdProtocol + this.state.rackhdAPI + '/swagger'
    };
    if (this.state.enableAuth == true) {
      swaggerOptions.authorizations['Authentication-Token'] =
        new Swagger.ApiKeyAuthorization(
          'Authorization', 'JWT ' + this.state.rackhdAuthToken, 'header');
    }
    new Swagger(swaggerOptions).
      then(() => resolve('Connected to RackHD 2.0 endpoint!')).
      catch(() => reject('Failed to reach RackHD 2.0endpoint.'));
  };
github strongloop / loopback-connector-swagger / lib / swagger-connector.js View on Github external
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,
          secConfig.in
        );
        client.clientAuthorizations.add(secConfig.name, oauth);
        break;
    }
  }
github streamplace / streamplace / packages / sp-client / src / sp-client.js View on Github external
newToken(token) {
    this.token = token;
    this.client.clientAuthorizations.add(
      "SP",
      new Swagger.ApiKeyAuthorization("sp-auth-token", token, "header")
    );
  }