Skip to content

Commit a901096

Browse files
committed
updating api called for JS sample
1 parent 4f59a64 commit a901096

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

AdalJsSample/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The [Azure Active Directory Authentication Library (ADAL)](https://docs.microsof
44

55
## Sample Application
66

7-
This buildable sample will walk you through the steps to create single page javascript application which uses ADAL to authenticate a user via an interactive prompt and all VSTS known information associated with the signed in identity.
7+
This buildable sample will walk you through the steps to create single page javascript application which uses ADAL to authenticate a user via an interactive prompt and display all project contained in a VSTS account/TFS collection.
88

99
To run this sample you will need:
1010
* Http-server. You can download [NPM http server](https://www.npmjs.com/package/http-server) if you need one.
@@ -35,10 +35,10 @@ git clone https://github.com/Microsoft/vsts-auth-samples.git
3535
2. Inside `index.html` there is a section of `Input Vars` you can update to run the sample:
3636
* `clientId` - (Required) update this with the `application id` you saved from `portal.azure.com`
3737
* `replyUri` - (optional) update this if you are hosting `index.html` at an address other than `hottp://localhost:8080`
38-
* `vstsApi` - (optional) update this if you would like to the sample to run a different VSTS API
38+
* `vstsApi` - (Required) update this with your VSTS/TFS collection, e.g. http://myaccount.visualstudio.com/DefaultCollection/_apis/projects?api-version=2.0 for VSTS or http://myserver:8080/tfs/DefaultCollection/_apis/projects?api-version=2.0 for TFS. If you would like to the sample to run a different VSTS API please change the entire string
3939
* `vstsResourceId` - Do not change this value. It is used to receive VSTS ADAL authentication tokens
4040
3. Navigate to the ADAL JS sample in cloned repo `vsts-auth-samples/AdalJsSample/` and start your http-server which will serve `index.hmtl` at `http://localhost:8080`.
41-
4. Navigate to `http://localhost:8080`. Sign in with a user account from your AAD tenant which has access to at least 1 VSTS account. Displayed should be all VSTS known identity infromation about the signed in user account.
41+
4. Navigate to `http://localhost:8080`. 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.
4242

4343

4444

AdalJsSample/index.html

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,24 @@
1818
<pre id="api_response"></pre>
1919

2020
<script type="text/javascript">
21+
//========= Input Vars ================================
22+
var clientId = '57c5c51c-2036-433a-befa-ebefc7f10689'; //Update with your app regirstion's Application ID
23+
var replyUri = 'http://localhost:8080'; //Update if hosting webpage non-locally
24+
var vstsApi = 'https://myaccount.visualstudio.com/DefaultCollection/_apis/projects?api-version=2.0';//'https://app.vssps.visualstudio.com/_apis/profile/profiles/me?api-version=1.0';//Update if want to access a different vsts API
25+
var vstsResourceId = '499b84ac-1321-427f-aa17-267ca6975798'; //Do not change
26+
//=====================================================
27+
2128
// Set up ADAL
2229
var authContext = new AuthenticationContext({
23-
clientId: '57c5c51c-2036-433a-befa-ebefc7f10689',//Update with your app regirstion's Application ID
24-
postLogoutRedirectUri: 'http://localhost:8080' //Where you return upon signout
30+
clientId: clientId,
31+
postLogoutRedirectUri: replyUri //Where you return upon signout
2532
});
2633
// Make an AJAX request to the VSTS REST API and print the response as JSON.
27-
var getCurrentUser = function (access_token) {
34+
var getCurrentUserInfo = function (access_token) {
2835
document.getElementById('api_response').textContent = 'Calling API...';
2936
var xhr = new XMLHttpRequest();
30-
xhr.open('GET', 'https://app.vssps.visualstudio.com/_apis/profile/profiles/me?api-version=1.0', true); //API called with ADAL token
37+
//API called with ADAL token
38+
xhr.open('GET', vstsApi, true);
3139
xhr.setRequestHeader('Authorization', 'Bearer ' + access_token);
3240
xhr.onreadystatechange = function () {
3341
if (xhr.readyState === 4 && xhr.status === 200) {
@@ -47,7 +55,7 @@
4755
authContext.handleWindowCallback();
4856
var err = authContext.getLoginError();
4957
if (err) {
50-
// TODO: Handle errors signing in and getting tokens
58+
// Handle error
5159
document.getElementById('api_response').textContent =
5260
'ERROR:\n\n' + err;
5361
}
@@ -58,18 +66,17 @@
5866
document.getElementById('username').textContent = 'Signed in as: ' + user.userName;
5967
document.getElementById('api_response').textContent = 'Getting access token...';
6068

61-
// Get an access token to the Microsoft Graph API
69+
// Get an access token to VSTS
6270
authContext.acquireToken(
63-
'499b84ac-1321-427f-aa17-267ca6975798',
71+
vstsResourceId,
6472
function (error, token) {
6573
if (error || !token) {
66-
// TODO: Handle error obtaining access token
6774
document.getElementById('api_response').textContent =
6875
'ERROR:\n\n' + error;
6976
return;
7077
}
7178
// Use the access token
72-
getCurrentUser(token);
79+
getCurrentUserInfo(token);
7380
}
7481
);
7582
} else {

ManagedClientConsoleAppSample/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The [Azure Active Directory Authentication Library (ADAL)](https://docs.microsof
44

55
## Sample Application
66

7-
This buildable sample will walk you through the steps to create a client-side console application which uses ADAL to authenticate a user via an interactive prompt and return a list of all projects inside a selected VSTS account.
7+
This buildable sample will walk you through the steps to create a client-side console application which uses ADAL to authenticate a user via an interactive prompt and return a list of all projects inside a selected VSTS account/TFS collection.
88

99
To run this sample you will need:
1010
* Visual Studio 2017

0 commit comments

Comments
 (0)