Skip to content
This repository has been archived by the owner. It is now read-only.

Commit 8ebd49f

Browse files
committed
further improvements
1 parent 0362d84 commit 8ebd49f

File tree

6 files changed

+23
-21
lines changed

6 files changed

+23
-21
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@
99
* Corrected README.md.
1010
* Added login with redirect.
1111
* Authentication decoupled from access token request.
12+
13+
## 3/06/2020

JavaScriptSPA/api.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,4 @@ function callApiWithAccessToken(endpoint, token) {
1717
}).catch(error => {
1818
logMessage("Error calling the Web api:\n" + error);
1919
});
20-
}
21-
22-
//calls the resource API with the token
23-
function callApi() {
24-
getTokenPopup(tokenRequest)
25-
.then(tokenResponse => {
26-
console.log('access_token acquired at: ' + new Date().toString());
27-
try {
28-
logMessage("Request made to Web API:")
29-
callApiWithAccessToken(apiConfig.webApi, tokenResponse.accessToken);
30-
} catch(err) {
31-
console.log(err);
32-
}
33-
});
3420
}

JavaScriptSPA/apiConfig.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,4 @@
22
const apiConfig = {
33
b2cScopes: ["https://fabrikamb2c.onmicrosoft.com/helloapi/demo.read"],
44
webApi: "https://fabrikamb2chello.azurewebsites.net/hello"
5-
};
6-
7-
// request to acquire a token for resource access
8-
const tokenRequest = {
9-
scopes: apiConfig.b2cScopes
10-
};
5+
};

JavaScriptSPA/authConfig.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ const msalConfig = {
1313
// request to sign-in (returns an idToken)
1414
const loginRequest = {
1515
scopes: ["openid", "profile"],
16+
};
17+
18+
// request to acquire a token for resource access
19+
const tokenRequest = {
20+
scopes: apiConfig.b2cScopes
1621
};

JavaScriptSPA/authPopup.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,18 @@ function getTokenPopup(request) {
3636
console.log(error);
3737
});
3838
});
39+
}
40+
41+
//calls the resource API with the token
42+
function passTokenToApi() {
43+
getTokenPopup(tokenRequest)
44+
.then(tokenResponse => {
45+
console.log('access_token acquired at: ' + new Date().toString());
46+
try {
47+
logMessage("Request made to Web API:")
48+
callApiWithAccessToken(apiConfig.webApi, tokenResponse.accessToken);
49+
} catch(err) {
50+
console.log(err);
51+
}
52+
});
3953
}

JavaScriptSPA/authRedirect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ return myMSALObj.acquireTokenSilent(request)
6060

6161

6262
// calls the resource API with the token
63-
function callApi() {
63+
function passTokenToAPI() {
6464
if (accessToken === null || accessToken === undefined) {
6565
getTokenRedirect(tokenRequest);
6666
} else {

0 commit comments

Comments
 (0)