How to use the ms-rest.BasicAuthenticationCredentials function in ms-rest

To help you get started, we’ve selected a few ms-rest 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 ritazh / slack-textmeme / app.js View on Github external
var restify = require('restify')
var msRest = require('ms-rest')
var Connector = require('botconnector')
const Memes = require('./lib/memes')
const memes = new Memes()

// Initialize server
var server = restify.createServer()
server.use(restify.authorizationParser())
server.use(restify.bodyParser())

// Initialize credentials for connecting to Bot Connector Service
var appId = process.env.appId || 'textmeme'
var appSecret = process.env.appSecret || 'ec470402ed6d4f2c9e40e597bc4cff73'
var credentials = new msRest.BasicAuthenticationCredentials(appId, appSecret)

// Handle incoming message
server.post('/v1/messages', verifyBotFramework(credentials), (req, res) => {
  var msg = req.body
  console.log(req.body.text)
  const [name] = req.body.text.split(';')
  sendMessage(name)

  if (name === 'memes') {
    console.log('get list of memes')
    return memes.returnAvailableMemes(req, msg, res)
  } else {
    console.log('get one meme')
    return memes.returnMeme(req, res)
  }
})
github microsoft / vscode-azuretools / appservice / src / TunnelProxy.ts View on Github external
private async checkTunnelStatus(): Promise {
        const password: string = nonNullProp(this._publishCredential, 'publishingPassword');
        const url: string = `https://${this._client.kuduHostName}/AppServiceTunnel/Tunnel.ashx?GetStatus&GetStatusAPIVer=2`;
        const request: requestUtils.Request = await requestUtils.getDefaultRequest(url, new BasicAuthenticationCredentials(this._publishCredential.publishingUserName, password));

        let tunnelStatus: ITunnelStatus;
        try {
            const responseBody: string = await requestUtils.sendRequest(request);
            ext.outputChannel.appendLog(`[Tunnel] Checking status, body: ${responseBody}`);

            // tslint:disable-next-line:no-unsafe-any
            tunnelStatus = JSON.parse(responseBody);
        } catch (error) {
            const parsedError: IParsedError = parseError(error);
            ext.outputChannel.appendLog(`[Tunnel] Checking status, error: ${parsedError.message}`);
            throw new Error(localize('tunnelStatusError', 'Error getting tunnel status: {0}', parsedError.errorType));
        }

        if (tunnelStatus.state === AppState.STARTED) {
            if ((tunnelStatus.port === 2222 && !this._isSsh) || (tunnelStatus.port !== 2222 && this._isSsh)) {
github microsoft / vscode-azuretools / appservice / src / SiteWrapper.ts View on Github external
private async getKuduClient(client: WebSiteManagementClient): Promise {
        const user: User = await this.getWebAppPublishCredential(client);
        if (!user.publishingUserName || !user.publishingPassword) {
            throw new ArgumentError(user);
        }

        const cred: BasicAuthenticationCredentials = new BasicAuthenticationCredentials(user.publishingUserName, user.publishingPassword);

        return new KuduClient(cred, `https://${this.appName}.scm.azurewebsites.net`);
    }
}
github microsoft / vscode-azuretools / appservice / src / getKuduClient.ts View on Github external
export async function getKuduClient(client: SiteClient): Promise {
    if (!client.kuduHostName) {
        const asp: AppServicePlan | undefined = await client.getAppServicePlan();
        const notSupportedLinux: string = localize('notSupportedLinux', 'This operation is not supported by App Service plans with kind "{0}" and sku tier "{1}".', client.kind, asp && asp.sku && asp.sku.tier);
        throw new Error(notSupportedLinux);
    }
    const user: User = await client.getWebAppPublishCredential();
    const cred: BasicAuthenticationCredentials = new BasicAuthenticationCredentials(user.publishingUserName, nonNullProp(user, 'publishingPassword'));

    const kuduClient: KuduClient = new KuduClient(cred, client.kuduUrl);
    addExtensionUserAgent(kuduClient);
    return kuduClient;
}
github microsoft / appcenter-cli / src / util / apis / create-client.ts View on Github external
fromUserNameAndPassword(userName: string, password: string, endpoint: string): AppCenterClient {
      debug(`Creating client from user name and password for endpoint ${endpoint}`);
      return new AppCenterClient(new BasicAuthenticationCredentials(userName, password), endpoint, createClientOptions());
    },