Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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) {
}).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));
.then(function (client) {
// add authorization header to client
client.clientAuthorizations.add('AuthorizationBotConnector', new Swagger.ApiKeyAuthorization('Authorization', 'Bearer ' + directLineSecret, 'header'));
return client;
})
.catch(function (err) {
_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;
}
_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;
}
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);
}
.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);
}
});
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.'));
};
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;
}
}
newToken(token) {
this.token = token;
this.client.clientAuthorizations.add(
"SP",
new Swagger.ApiKeyAuthorization("sp-auth-token", token, "header")
);
}