|
18 | 18 | <pre id="api_response"></pre>
|
19 | 19 |
|
20 | 20 | <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 | + |
21 | 28 | // Set up ADAL
|
22 | 29 | 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 |
25 | 32 | });
|
26 | 33 | // 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) { |
28 | 35 | document.getElementById('api_response').textContent = 'Calling API...';
|
29 | 36 | 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); |
31 | 39 | xhr.setRequestHeader('Authorization', 'Bearer ' + access_token);
|
32 | 40 | xhr.onreadystatechange = function () {
|
33 | 41 | if (xhr.readyState === 4 && xhr.status === 200) {
|
|
47 | 55 | authContext.handleWindowCallback();
|
48 | 56 | var err = authContext.getLoginError();
|
49 | 57 | if (err) {
|
50 |
| - // TODO: Handle errors signing in and getting tokens |
| 58 | + // Handle error |
51 | 59 | document.getElementById('api_response').textContent =
|
52 | 60 | 'ERROR:\n\n' + err;
|
53 | 61 | }
|
|
58 | 66 | document.getElementById('username').textContent = 'Signed in as: ' + user.userName;
|
59 | 67 | document.getElementById('api_response').textContent = 'Getting access token...';
|
60 | 68 |
|
61 |
| - // Get an access token to the Microsoft Graph API |
| 69 | + // Get an access token to VSTS |
62 | 70 | authContext.acquireToken(
|
63 |
| - '499b84ac-1321-427f-aa17-267ca6975798', |
| 71 | + vstsResourceId, |
64 | 72 | function (error, token) {
|
65 | 73 | if (error || !token) {
|
66 |
| - // TODO: Handle error obtaining access token |
67 | 74 | document.getElementById('api_response').textContent =
|
68 | 75 | 'ERROR:\n\n' + error;
|
69 | 76 | return;
|
70 | 77 | }
|
71 | 78 | // Use the access token
|
72 |
| - getCurrentUser(token); |
| 79 | + getCurrentUserInfo(token); |
73 | 80 | }
|
74 | 81 | );
|
75 | 82 | } else {
|
|
0 commit comments