Skip to content

Commit 8e178ea

Browse files
committed
switch to domain name for tenant ID + README update
1 parent 17618cb commit 8e178ea

File tree

4 files changed

+58
-75
lines changed

4 files changed

+58
-75
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
# CHANGELOG
22

3-
## 3/04/2020
3+
## 2020-03-21
4+
5+
* Switch to using the tenant domain name for the tenant ID in [config.js](config.js).
6+
* Update README to reflect current state of sample and the articles referenced on [docs.microsoft.com](https://docs.microsoft.com/azure/active-directory-b2c).
7+
8+
## 2020-03-04
49

510
* Dependencies updated.
611
* Configuration parameters separated.
7-
* Readme improved.
12+
* README improved.
813
* ES6 conventions introduced.

LICENSE copy

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

README.md

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -12,106 +12,105 @@ urlFragment: "active-directory-b2c-javascript-nodejs-webapi"
1212

1313
# Node.js Web API with Azure AD B2C
1414

15-
This sample demonstrates how to protect a Node.js web API with Azure AD B2C using the Passport.js library. The code here is pre-configured with a registered client ID. If you register your own app, you will need to replace the client ID.
15+
This sample demonstrates how to protect a Node.js web API with Azure AD B2C using the Passport.js library. The code here is pre-configured with a registered client ID. If you register your own app, replace the client ID.
1616

1717
To see how to call this web API from a client application, refer to this [B2C Single Page Application sample](https://github.com/Azure-Samples/active-directory-b2c-javascript-msal-singlepageapp).
1818

1919
## Contents
2020

21-
| File/folder | Description |
22-
|-------------------|--------------------------------------------|
23-
| `process.json` | Contains configuration parameters for logging via Morgan. |
24-
| `index.js` | Main application logic resides here. |
25-
| `config.js` | Contains configuration parameters for the sample. |
26-
| `.gitignore` | Defines what to ignore at commit time. |
27-
| `CHANGELOG.md` | List of changes to the sample. |
28-
| `CODE_OF_CONDUCT.md` | Code of Conduct information. |
29-
| `CONTRIBUTING.md` | Guidelines for contributing to the sample. |
30-
| `LICENSE` | The license for the sample. |
31-
| `package.json` | Package manifest for npm. |
32-
| `README.md` | This README file. |
33-
| `SECURITY.md` | Security disclosures. |
34-
35-
## Steps to Run
36-
37-
1. Clone the code.
21+
| File/folder | Description |
22+
|:---------------------|:----------------------------------------------------------|
23+
| `.gitignore` | Defines what to ignore at commit time. |
24+
| `CHANGELOG.md` | List of changes to the sample. |
25+
| `CODE_OF_CONDUCT.md` | Code of Conduct information. |
26+
| `config.js` | Contains configuration parameters for the sample. |
27+
| `CONTRIBUTING.md` | Guidelines for contributing to the sample. |
28+
| `index.js` | Main application logic resides here. |
29+
| `LICENSE` | The license for the sample. |
30+
| `package.json` | Package manifest for npm. |
31+
| `process.json` | Contains configuration parameters for logging via Morgan. |
32+
| `README.md` | This README file. |
33+
| `SECURITY.md` | Security disclosures. |
34+
``
35+
36+
## Steps to run
37+
38+
1. Clone this repository.
3839

3940
```console
4041
git clone https://github.com/Azure-Samples/active-directory-b2c-javascript-nodejs-webapi.git
41-
```
42+
```config
4243

43-
2. Make sure you've installed [Node.js](https://nodejs.org/en/download/).
44+
2. Install [Node.js](https://nodejs.org/en/download/) if you don't already have it.
4445

45-
3. Install the node dependencies:
46+
3. Install the Node dependencies:
4647

4748
```console
4849
npm install && npm update
4950
```
5051

51-
4. Run the Web API! By default it will run on `http://localhost:5000`
52+
4. Run the Web API. By default, it runs on `http://localhost:5000`
5253

5354
```console
5455
npm start
5556
```
5657

57-
## Next Steps
58+
## Using your own Azure AD B2C tenant
5859

59-
### Using your own Azure AD B2C Tenant
60+
To have a proper understanding of Azure AD B2C as a developer, follow the tutorials in the official [Azure AD B2C documentation](https://docs.microsoft.com/azure/active-directory-b2c/). In the rest of this guide, we summarize the steps you need to go through.
6061

61-
To have a proper understanding of Azure AD B2C as a developer, follow the tutorials on Azure [AD B2C documentation](https://docs.microsoft.com/en-us/azure/active-directory-b2c/). In the rest of this guide, we summarize the steps you need to go through.
62+
### Step 1: Get your own Azure AD B2C tenant
6263

63-
#### Step 1: Get your own Azure AD B2C Tenant
64+
You first need an Azure AD B2C tenant. If you don't already have one you can use for testing purposes, create your own by following the steps in [Tutorial: Create an Azure Active Directory B2C tenant](https://docs.microsoft.com/azure/active-directory-b2c/tutorial-create-tenant).
6465

65-
First, you'll need an Azure AD B2C tenant. If you don't have an existing Azure AD B2C tenant that you can use for testing purposes, you can create your own by following [these instructions](https://azure.microsoft.com/documentation/articles/active-directory-b2c-get-started).
66+
### Step 2: Create your own policies
6667

67-
#### Step 2: Create your own policies
68+
This sample uses a unified sign-up/sign-in policy. You can create [your own unified sign-up/sign-in policy](https://docs.microsoft.com/azure/active-directory-b2c/tutorial-create-user-flows). You may choose to include as many or as few identity providers as you wish.
6869

69-
This sample uses a unified sign-up/sign-in policy. You can create [your own unified sign-up/sign-in policy](https://azure.microsoft.com/documentation/articles/active-directory-b2c-reference-policies). You may choose to include as many or as few identity providers as you wish.
70-
71-
If you already have existing policies in your Azure AD B2C tenant, feel free to re-use those policies in this sample.
70+
If you already have existing policies in your Azure AD B2C tenant, feel free to reuse those policies in this sample.
7271

7372
#### Step 3: Register your own web API with Azure AD B2C
7473

75-
Follow the instructions at [register a Web API with Azure AD B2C](https://docs.microsoft.com/en-us/azure/active-directory-b2c/add-web-application?tabs=applications) to register the Node.js Web API sample with your tenant. Registering your Web API allows you to define the scopes that your single page application will request access tokens for.
74+
Follow the steps in [Protect and grant access to a Node.js web API](https://docs.microsoft.com/azure/active-directory-b2c/tutorial-single-page-app-webapi) to register the web API application in your tenant, define scopes, and grant a web application access to the API. By following the steps in the tutorial, you define the scopes that your single-page application will request access tokens for.
7675

7776
#### Step 4: Configure your application source code
7877

79-
You can now fill in the variables in the `config.js` file of the Node.js Web API sample with the parameters you've obtained from the Azure Portal during the steps above.
78+
You can now fill in the variables in the *config.js* file of the Node.js web API sample with the parameters you've obtained from the Azure portal by following the steps above.
8079

8180
Configure the following variables:
8281

8382
```javascript
84-
const clientID = "<Application ID for your Node.js Web API - found on Properties page in Azure portal e.g. 93733604-cc77-4a3c-a604-87084dd55348>";
85-
const b2cDomainHost = "<Domain of your B2C host eg. fabrikamb2c.b2clogin.com>";
86-
const tenantIdGuid = "<Application ID for your Node.js Web API - found on Properties page in Azure portal e.g. 775527ff-9a37-4307-8b3d-cc311f58d925>";
87-
const policyName = "<Name of your sign in / sign up policy, e.g. B2C_1_SUSI>";
83+
const clientID = "<Application (client) ID of your Node.js web API, e.g. 93733604-0000-0000-0000-87084dd55348>"
84+
const b2cDomainHost = "<Domain name of your B2C authority, e.g. fabrikamb2c.b2clogin.com>";
85+
const tenantId = "<Domain name of your B2C tenant, e.g. fabrikamb2c.onmicrosoft.com>";
86+
const policyName = "<Name of your sign in / sign up policy. Example: B2C_1_SUSI>";
8887
```
8988

9089
> **NOTE**
9190
>
92-
>Developers using the [Azure China Environment](https://docs.microsoft.com/en-us/azure/active-directory/develop/authentication-national-cloud), MUST use <your-tenant-name>.b2clogin.cn authority, instead of `login.chinacloudapi.cn`.
91+
> Developers using the [Azure China](https://docs.microsoft.com/azure/active-directory/develop/authentication-national-cloud) environment MUST use `<your-tenant-name>.b2clogin.cn` authority instead of `login.chinacloudapi.cn`.
9392
>
94-
> In order to use <your-tenant-name>.b2clogin.*, you will need to configure you application and set `validateAuthority: false`. Learn more about using [b2clogin](https://docs.microsoft.com/en-us/azure/active-directory-b2c/b2clogin#set-the-validateauthority-property).
93+
> To use `<your-tenant-name>.b2clogin.*`, you need set `validateIssuer: false`. Learn more about using [b2clogin.com](https://docs.microsoft.com/azure/active-directory-b2c/b2clogin).
94+
95+
### Step 5: Run the application
9596

96-
Lastly, to run your Node.js Web API, run the following command from your shell or command line
97+
Lastly, to run your Node.js Web API, execute the following commands in your shell or terminal:
9798

9899
```bash
99100
npm install && npm update
100101
npm start
101102
```
102103

103-
Your Node.js Web API sample is now running on Port 5000.
104+
Your Node.js web API is now running on port 5000.
104105

105-
## Questions & Issues
106+
## Questions & issues
106107

107-
Please file any questions or problems with the sample as a GitHub issue. You can also post on Stack Overflow with the tag `azure-ad-b2c`. For OAuth2.0 library issues, please see note below.
108+
Please file any questions or problems with the sample as a GitHub issue. You can also post on Stack Overflow with the tag `azure-ad-b2c`.
108109

109110
## Contributing
110111

111-
If you'd like to contribute to this sample, see [CONTRIBUTING.MD](./CONTRIBUTING.md).
112+
If you'd like to contribute to this sample, see [CONTRIBUTING.md](./CONTRIBUTING.md).
112113

113-
## Code of Conduct
114+
## Code of conduct
114115

115-
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
116-
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
117-
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
116+
For details, see [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md).

config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// Update these four variables with your values from the B2C portal
2-
const clientID = "93733604-cc77-4a3c-a604-87084dd55348";
1+
// Update these four variables with values from your B2C tenant in the Azure portal
2+
const clientID = "93733604-cc77-4a3c-a604-87084dd55348"; // Application (client) ID of your API's application registration
33
const b2cDomainHost = "fabrikamb2c.b2clogin.com";
4-
const tenantIdGuid = "775527ff-9a37-4307-8b3d-cc311f58d925"; // alternatively, you can use your tenant name as well
4+
const tenantId = "fabrikamb2c.onmicrosoft.com"; // Alternatively, you can use your Directory (tenant) ID (a GUID)
55
const policyName = "B2C_1_SUSI";
66

77
const config = {
8-
identityMetadata: "https://" + b2cDomainHost + "/" + tenantIdGuid + "/" + policyName + "/v2.0/.well-known/openid-configuration/",
8+
identityMetadata: "https://" + b2cDomainHost + "/" + tenantId + "/" + policyName + "/v2.0/.well-known/openid-configuration/",
99
clientID: clientID,
1010
policyName: policyName,
1111
isB2C: true,

0 commit comments

Comments
 (0)