GithubHelp home page GithubHelp logo

microsoft / vsts-device-flow-auth Goto Github PK

View Code? Open in Web Editor NEW
4.0 33.0 10.0 54 KB

Node.js package for Device Flow authentication to Visual Studio Team Services

License: MIT License

JavaScript 6.51% TypeScript 93.49%

vsts-device-flow-auth's Introduction

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 [email protected] 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.

vsts-device-flow-auth's People

Contributors

chrispat avatar jpricket avatar microsoftopensource avatar msftgits avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vsts-device-flow-auth's Issues

deviceflow.ts: Getting TypeError: Failed to fetch on every Response

Hello :),

at first: Thank you sooo much for the deviceflow.ts file! I learned a lot about the pending and so on for the Microsoft Device Code Authentication Flow.

But my problem is, that I am getting in my Angular Client an TypeError: Failed to fetch with Status Code: 400. I know that the status Code 400 means, that the User doesn't authenticate yet, but i don't get the Error Code "authorization_pending" Status-Message.

I tried to avoid that by always telling him in an error: PENDING. But after I authenticated with my Mobile Phone, there is also an Error: 401 Unauthorized!

I got the same code like in:
waitOnResponseAccessToken(...)
and
WaitForPersonalAccessToken()

And yes i setup the right interval like 5 * 1000 (so every 5 seconds) like my device code response also says interval: 5.

I also tried the angular/http Methods and response-promise besides your response-promise-native plugin, but all the same: I don't get the AccessToken in the right moment :(.

Please heeeelp xD

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.