Node.js package for Device Flow authentication to Visual Studio Team Services
Перейти к файлу
Chris Patterson 6bbee9d587
Merge pull request #3 from Microsoft/update-package-version
Update package version
2018-05-22 12:15:39 -07:00
.vscode Initial device flow for node.js implementation 2017-07-11 15:38:25 -04:00
src Adding break in loop 2018-05-22 15:07:31 -04:00
test-integration Fixed getTenantId to ignore status code, updated typings 2018-05-22 12:41:48 -04:00
.gitattributes Initial device flow for node.js implementation 2017-07-11 15:38:25 -04:00
.gitignore Add .npmignore 2017-07-11 16:39:30 -04:00
.npmignore Add .npmignore 2017-07-11 16:39:30 -04:00
.vscodeignore Initial device flow for node.js implementation 2017-07-11 15:38:25 -04:00
CONTRIBUTING.md Initial device flow for node.js implementation 2017-07-11 15:38:25 -04:00
LICENSE.txt Initial device flow for node.js implementation 2017-07-11 15:38:25 -04:00
README.md Initial device flow for node.js implementation 2017-07-11 15:38:25 -04:00
ThirdPartyNotices.txt Initial device flow for node.js implementation 2017-07-11 15:38:25 -04:00
gulpfile.js Generate typings files during gulp build 2017-07-11 17:36:01 -04:00
package-lock.json update package version to current milestone 2018-05-22 15:13:39 -04:00
package.json Upping package version to match current milestone 2018-05-22 15:11:52 -04:00
tsconfig.json Generate typings files during gulp build 2017-07-11 17:36:01 -04:00
tslint.json Initial device flow for node.js implementation 2017-07-11 15:38:25 -04:00

README.md

Visual Studio Team Services Device Flow Authentication for Node.js

vsts-device-flow-auth is a small library that helps your Node.js application's users interactively authenticate to Visual Studio Team Services. It supports both Azure Active Directory-backed (AAD) and Microsoft Account-backed (MSA) Team Services accounts. When the authentication is complete, the Node.js application receives a personal access token to use on the Team Services user's behalf.

Install

$ npm install --save vsts-device-flow-auth

Usage

Create a DeviceFlowAuthenticator with the URI of the user's Team Services account. You will also need to provide your application's client id and redirect Uri. For information on how to register an application with Azure, see How to register an app with the v2.0 endpoint for details.

const authOptions: IDeviceFlowAuthenticationOptions = {
    clientId: '00000000-0000-0000-0000-000000000000',
    redirectUri: 'https://some-url.com'
};
const dfa: DeviceFlowAuthenticator = new DeviceFlowAuthenticator("https://my-corporate-account.visualstudio.com", authOptions);

Call GetDeviceFlowDetails() to acquire the device_code, verification_url and optional message for the user to authenticate with Team Services.

const obj: DeviceFlowDetails = await dfa.GetDeviceFlowDetails();

Call WaitForPersonalAccessToken() to get the token to use on the user's behalf.

const pat: string = await dfa.WaitForPersonalAccessToken();

Below is a short TypeScript example of how to use the package. A complete example can be found in the GitHub repository.

import { DeviceFlowAuthenticator, DeviceFlowDetails, IDeviceFlowAuthenticationOptions, IDeviceFlowTokenOptions } from 'vsts-device-flow-auth';

async function run() {
    const resourceUri: string = `https://my-corporate-account.visualstudio.com`;
    //const resourceUri: string = `https://my-personal-account.visualstudio.com`;

    const authOptions: IDeviceFlowAuthenticationOptions = {
        clientId: '00000000-0000-0000-0000-000000000000',
        redirectUri: 'https://some-url.com'
    };
    const tokenOptions: IDeviceFlowTokenOptions = {
        tokenDescription: `vsts-device-flow-auth test app: ${resourceUri} on ${os.hostname()}`,
    };
    const dfa: DeviceFlowAuthenticator = new DeviceFlowAuthenticator(resourceUri, authOptions, tokenOptions);

    const obj: DeviceFlowDetails = await dfa.GetDeviceFlowDetails();
    console.log(`message: ${obj.Message}`);
    console.log(`user code: ${obj.UserCode}`);
    console.log(`verify url: ${obj.VerificationUrl}`);

    console.log(`Go do the Device Flow authentication...`);
    console.log(``);

    const pat: string = await dfa.WaitForPersonalAccessToken();
    console.log(pat);
}

run();

Support

Support for this project is provided on our GitHub Issue Tracker. You can submit a bug report, a feature request or participate in discussions.

Contributing

To contribute to this project, see the Contributing Guide.

Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Privacy Statement

The Microsoft Visual Studio Product Family Privacy Statement describes the privacy statement of this software.

License

This extension is licensed under the MIT License. Please see the third-party notices file for additional copyright notices and license terms applicable to portions of the software.