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

Commit fb46341

Browse files
authored
Merge pull request #62 from Azure-Samples/derisen-refactoring
bump msal to 1.3.1
2 parents 7a15fde + 18828ff commit fb46341

File tree

5 files changed

+75
-19
lines changed

5 files changed

+75
-19
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# CHANGELOG
22

3+
## 5/19/2020
4+
5+
* Updated to ## MSAL.js 1.3.1.
6+
* Removed 'path' package from dependencies.
7+
* Further clarifications in README.md
8+
39
## 4/28/2020
410

511
* Updated to ## MSAL.js 1.3.0.

JavaScriptSPA/authPopup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function signIn() {
1212
updateUI();
1313
}
1414

15-
}).catch(function (error) {
15+
}).catch(error => {
1616
console.log(error);
1717

1818
// Error handling

JavaScriptSPA/index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
<title>AAD B2C | MSAL.JS Vanilla JavaScript SPA</title>
77

88
<!-- msal.min.js can be used in the place of msal.js; included msal.js to make debug easy -->
9-
<script type="text/javascript" src="https://alcdn.msauth.net/lib/1.3.0/js/msal.js" integrity="sha384-xeOjp8/l8VazdeNFRbrC9LWPR1InyrS8E1Na/0lv6V2r09iwX6vJC47FXlczokMi" crossorigin="anonymous"></script>
9+
<script type="text/javascript" src="https://alcdn.msauth.net/lib/1.3.1/js/msal.js" integrity="sha384-YjtcEEqiYcRGh2K/ehq07C6Bk9jKrKoMgdFy9YGfTxtrmzV3GyNi0DDgwhmcCNrE" crossorigin="anonymous"></script>
10+
1011
<!-- msal.js with a fallback to backup CDN -->
1112
<script type="text/javascript">
12-
if(typeof Msal === 'undefined')document.write(unescape("%3Cscript src='https://alcdn.msftauth.net/lib/1.3.0/js/msal.js' type='text/javascript' integrity='sha384-xeOjp8/l8VazdeNFRbrC9LWPR1InyrS8E1Na/0lv6V2r09iwX6vJC47FXlczokMi' crossorigin='anonymous'%3E%3C/script%3E"));
13+
if(typeof Msal === 'undefined')document.write(unescape("%3Cscript src='https://alcdn.msftauth.net/lib/1.3.1/js/msal.js' type='text/javascript' %3E%3C/script%3E"));
1314
</script>
14-
15+
1516
<!-- adding Bootstrap 4 for UI components -->
1617
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
1718
</head>

README.md

Lines changed: 63 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,39 @@ urlFragment: "active-directory-b2c-javascript-msal-singlepageapp"
1414
1515
This simple sample demonstrates how to use the [Microsoft Authentication Library for JavaScript (msal.js)](https://github.com/AzureAD/microsoft-authentication-library-for-js) to get an access token and call an API secured by Azure AD B2C.
1616

17+
**Note:** A quickstart guide covering this sample can be found [here](https://docs.microsoft.com/azure/active-directory-b2c/quickstart-single-page-app).
18+
19+
**Note:** A more detailed tutorial covering this sample can be found [here](https://docs.microsoft.com/azure/active-directory-b2c/tutorial-single-page-app).
20+
21+
22+
## Contents
23+
24+
| File/folder | Description |
25+
|-------------------|--------------------------------------------|
26+
| `JavaScriptSPA` | Contains sample source files. |
27+
| `authPopup.js` | Main authentication logic resides here (using Popup flow). |
28+
| `authRedirect.js` | Use this instead of `authPopup.js` for authentication with redirect flow. |
29+
| `authConfig.js` | Contains configuration parameters for the sample. |
30+
| `api.js` | Provides a helper function for calling the web API. |
31+
| `apiConfig.js` | Contains API endpoint and scope. |
32+
| `ui.js` | Contains UI logic. |
33+
| `policies.js` | Contains policies and authority strings. |
34+
| `index.html` | Contains the UI of the sample. |
35+
| `.gitignore` | Defines what to ignore at commit time. |
36+
| `CHANGELOG.md` | List of changes to the sample. |
37+
| `CODE_OF_CONDUCT.md` | Code of Conduct information. |
38+
| `CONTRIBUTING.md` | Guidelines for contributing to the sample. |
39+
| `LICENSE` | The license for the sample. |
40+
| `package.json` | Package manifest for npm. |
41+
| `README.md` | This README file. |
42+
| `SECURITY.md` | Security disclosures. |
43+
| `server.js` | Implements a simple Node server to serve index.html. |
44+
45+
## Prerequisites
46+
47+
- [Node](https://nodejs.org/en/) must be installed to run this sample.
48+
- A modern web browser. This sample uses **ES6** conventions and will not run on **Internet Explorer**.
49+
1750
## How to run this sample
1851

1952
There are two ways to run this sample:
@@ -87,26 +120,19 @@ Now in the sample code, you can replace the single page application's demo envir
87120

88121
1. Open the `authConfig.js` file.
89122
2. Find the assignment for `clientId` and replace the value with the Application ID for the single page application you registered earlier, for example the Application ID found in `My Test SPA` application in the Azure portal.
90-
3. Find the assignment for `authority` and replacing `b2c_1_susi` with the name of the policy you created in Step 2, and `fabrikamb2c.onmicrosoft.com` by the name of your Azure AD B2C tenant, for example `https://<your-tenant-name>.b2clogin.com/<your-tenant-name>.onmicrosoft.com/<your-sign-in-sign-up-policy>`
91-
4. Open the `apiConfig.js` file.
92-
5. Find the assignment for the scopes `b2cScopes` replacing the URL by the scope URL you created for the Web API, e.g. `b2cScopes: ["https://<your-tenant-name>.onmicrosoft.com/helloapi/demo.read"]`
93-
6. Find the assignment for API URL `webApi` replacing the current URL by the URL where you deployed your Web API in Step 4, e.g. `webApi: http://localhost:5000/hello`
123+
3. Open the `policies.js` file.
124+
4. Find the entries for `names` and `authorities` and replacing, as appropriate, with the names of the policies you created in Step 2, and `fabrikamb2c.onmicrosoft.com` by the name of your Azure AD B2C tenant, for example `https://<your-tenant-name>.b2clogin.com/<your-tenant-name>.onmicrosoft.com/<your-sign-in-sign-up-policy>`
125+
5. Open the `apiConfig.js` file.
126+
6. Find the assignment for the scopes `b2cScopes` replacing the URL by the scope URL you created for the Web API, e.g. `b2cScopes: ["https://<your-tenant-name>.onmicrosoft.com/helloapi/demo.read"]`
127+
7. Find the assignment for API URL `webApi` replacing the current URL by the URL where you deployed your Web API in Step 4, e.g. `webApi: http://localhost:5000/hello`
94128

95129
Your resulting code should look as follows:
96130

97-
```javascript
98-
const apiConfig = {
99-
b2cScopes: ["https://fabrikamb2c.onmicrosoft.com/helloapi/demo.read"],
100-
webApi: "https://fabrikamb2chello.azurewebsites.net/hello"
101-
};
102-
103-
```
104-
105131
```javascript
106132
const msalConfig = {
107133
auth: {
108134
clientId: "e760cab2-b9a1-4c0d-86fb-ff7084abd902",
109-
authority: "https://fabrikamb2c.b2clogin.com/fabrikamb2c.onmicrosoft.com/b2c_1_susi",
135+
authority: b2cPolicies.authorities.signUpSignIn.authority,
110136
validateAuthority: false
111137
},
112138
cache: {
@@ -124,6 +150,30 @@ const tokenRequest = {
124150
};
125151
```
126152

153+
```javascript
154+
const b2cPolicies = {
155+
names: {
156+
signUpSignIn: "b2c_1_susi",
157+
forgotPassword: "b2c_1_reset"
158+
},
159+
authorities: {
160+
signUpSignIn: {
161+
authority: "https://fabrikamb2c.b2clogin.com/fabrikamb2c.onmicrosoft.com/b2c_1_susi",
162+
},
163+
forgotPassword: {
164+
authority: "https://fabrikamb2c.b2clogin.com/fabrikamb2c.onmicrosoft.com/b2c_1_reset",
165+
},
166+
},
167+
}
168+
```
169+
170+
```javascript
171+
const apiConfig = {
172+
b2cScopes: ["https://fabrikamb2c.onmicrosoft.com/helloapi/demo.read"],
173+
webApi: "https://fabrikamb2chello.azurewebsites.net/hello"
174+
};
175+
```
176+
127177
#### Step 3: Run the sample
128178

129179
1. Install the node dependencies if this is your first time running the app (e.g. if you skipped running in the demo environment):

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
"main": "server.js",
66
"dependencies": {
77
"express": "^4.12.3",
8-
"morgan": "^1.5.2",
9-
"path": "^0.11.14"
8+
"morgan": "^1.5.2"
109
},
1110
"scripts": {
1211
"start": "node server.js",

0 commit comments

Comments
 (0)