Skip to content

Latest commit

 

History

History
46 lines (32 loc) · 4.29 KB

File metadata and controls

46 lines (32 loc) · 4.29 KB

Javascript Web App Sample

For javascript web applications that want access to resources like VSTS REST API's, they will have to support an authentication flow for their users. The Azure Active Directory Authentication Library (ADAL) for JS enables javascript application developers to setup inerative authentication flows and obtain access tokens for API usage.

Sample Application

This buildable sample will walk you through the steps to create a single page javascript application which uses ADAL to authenticate a user via an interactive prompt and display all projects contained in a VSTS account/TFS collection.

To run this sample you will need:

Step 1: Clone or download vsts-auth-samples repository

From a shell or command line:

git clone https://github.com/Microsoft/vsts-auth-samples.git

Step 2: Register the sample application with you Azure Active Directory tenant

  1. Sign in to the Azure Portal.
  2. On the top bar, click on your account and under the Directory list, choose the Active Directory tenant where you wish to register your application.
  3. On the left hand navigation menu, select Azure Active Directory.
  4. Click on App registrations and select New application registration from the top bar.
  5. Enter a name for you application, ex. "Adal JS sample", choose Web app/API for application type, and enter http://localhost:8081 for the Redirect URI. Finally click create at the bottom of the screen.
  6. Save the Application ID from your new application registration. You will need it later in this sample.
  7. Grant permissions for VSTS. Click Required permissions -> add -> 1 Select an API -> type in and select Microsoft Visual Studio Team Services -> check the box for Delegated Permissions -> click Select -> click Done -> click Grant Permissions -> click Yes.

Step 3: Run the sample

  1. Open index.html in Visual Studio Code or another text editor or IDE.
  2. Inside index.html there is a section called Input Vars you will need to update to run the sample:
  3. Navigate to the ADAL JS sample in cloned repo vsts-auth-samples/JavascriptWebAppSample/ and start your http-server and set it to serve pages at localhost:8081 which will by default serve index.html at http://localhost:8081.
  4. Navigate to http://localhost:8081. Sign in with a user account from your AAD tenant which has access to the VSTS account specified in the vstsApi. All projects contained in the account should be displayed.