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

Commit 0362d84

Browse files
committed
deleting policies.js, moving callAPI to api.js
1 parent bc2062e commit 0362d84

File tree

7 files changed

+22
-26
lines changed

7 files changed

+22
-26
lines changed

JavaScriptSPA/api.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,18 @@ 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+
});
2034
}

JavaScriptSPA/authConfig.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const msalConfig = {
22
auth: {
3-
clientId: "e760cab2-b9a1-4c0d-86fb-ff7084abd902", //This is your client ID
4-
authority: "https://fabrikamb2c.b2clogin.com/fabrikamb2c.onmicrosoft.com/" + b2cPolicies.signUpSignIn, //This is your tenant info
3+
clientId: "e760cab2-b9a1-4c0d-86fb-ff7084abd902",
4+
authority: "https://fabrikamb2c.b2clogin.com/fabrikamb2c.onmicrosoft.com/b2c_1_susi",
55
validateAuthority: false
66
},
77
cache: {

JavaScriptSPA/authPopup.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,4 @@ function getTokenPopup(request) {
3636
console.log(error);
3737
});
3838
});
39-
}
40-
41-
//calls the resource API with the token
42-
function callApi() {
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-
});
5339
}

JavaScriptSPA/authRedirect.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const myMSALObj = new Msal.UserAgentApplication(msalConfig);
44

55
let accessToken;
6+
67
// Register Callbacks for Redirect flow
78
myMSALObj.handleRedirectCallback(authRedirectCallBack);
89

JavaScriptSPA/index.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@
2020
</head>
2121

2222
<body>
23+
24+
<!-- Navbar -->
2325
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
2426
<a class="navbar-brand" href="/">Azure AD B2C</a>
2527
<div class="btn-group ml-auto dropleft">
2628
<button type="button" id="signIn" class="btn btn-secondary" onclick="signIn()">Sign In</button>
2729
<button type="button" id="signOut" class="btn btn-success" onclick="logout()" style="display:none">Sign Out</button>
2830
</div>
2931
</nav>
32+
33+
<!-- Content -->
3034
<div class="card">
3135
<h5 class="card-header text-center">Getting an access token with Azure AD B2C and calling a Web API</h5>
3236
<div class="card-body text-center">
@@ -42,12 +46,10 @@ <h5 id="label" class="card-title">Sign-in with Microsoft Azure AD B2C</h5>
4246
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
4347

4448
<!-- importing app scripts -->
45-
<script type="text/javascript" src="./policies.js"></script>
4649
<script type="text/javascript" src="./authConfig.js"></script>
4750
<script type="text/javascript" src="./apiConfig.js"></script>
4851
<script type="text/javascript" src="./ui.js"></script>
49-
50-
<!-- replace with authRedirect if you would like to use redirect flow -->
52+
<!-- replace next with authRedirect if you would like to use redirect flow -->
5153
<script type="text/javascript" src="./authPopup.js"></script>
5254
<script type="text/javascript" src="./api.js"></script>
5355
</body>

JavaScriptSPA/policies.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

JavaScriptSPA/ui.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// UI elements to work with
22
const signInButton = document.getElementById('signIn');
33
const signOutButton = document.getElementById('signOut');
4-
54
const callWebApiButton = document.getElementById('callApiButton');
6-
75
const label = document.getElementById('label');
86
const response = document.getElementById("response");
97

0 commit comments

Comments
 (0)