Skip to content

Commit 08a94ef

Browse files
authored
Merge pull request #19 from mmacy/mmacy-config-update-tenantid
switch to domain name for tenant ID + README update
2 parents 17618cb + 182f9d3 commit 08a94ef

File tree

4 files changed

+54
-72
lines changed

4 files changed

+54
-72
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: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,106 +12,104 @@ 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. |
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. |
3434

35-
## Steps to Run
35+
## Steps to run
3636

37-
1. Clone the code.
37+
1. Clone this repository.
3838

3939
```console
4040
git clone https://github.com/Azure-Samples/active-directory-b2c-javascript-nodejs-webapi.git
4141
```
4242

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

45-
3. Install the node dependencies:
45+
3. Install the Node dependencies:
4646

4747
```console
4848
npm install && npm update
4949
```
5050

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

5353
```console
5454
npm start
5555
```
5656

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

59-
### Using your own Azure AD B2C Tenant
59+
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.
6060

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.
61+
### Step 1: Get your own Azure AD B2C tenant
6262

63-
#### Step 1: Get your own Azure AD B2C Tenant
63+
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).
6464

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).
65+
### Step 2: Create your own policies
6666

67-
#### Step 2: Create your own policies
67+
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.
6868

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.
69+
If you already have existing policies in your Azure AD B2C tenant, feel free to reuse those policies in this sample.
7270

7371
#### Step 3: Register your own web API with Azure AD B2C
7472

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.
73+
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.
7674

7775
#### Step 4: Configure your application source code
7876

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.
77+
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.
8078

8179
Configure the following variables:
8280

8381
```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>";
82+
const clientID = "<Application (client) ID of your Node.js web API, e.g. 93733604-0000-0000-0000-87084dd55348>"
83+
const b2cDomainHost = "<Domain name of your B2C authority, e.g. fabrikamb2c.b2clogin.com>";
84+
const tenantId = "<Domain name of your B2C tenant, e.g. fabrikamb2c.onmicrosoft.com>";
85+
const policyName = "<Name of your sign in / sign up policy. Example: B2C_1_SUSI>";
8886
```
8987

9088
> **NOTE**
9189
>
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`.
90+
> 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`.
9391
>
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).
92+
> 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).
93+
94+
### Step 5: Run the application
9595

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

9898
```bash
9999
npm install && npm update
100100
npm start
101101
```
102102

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

105-
## Questions & Issues
105+
## Questions & issues
106106

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.
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`.
108108

109109
## Contributing
110110

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

113-
## Code of Conduct
113+
## Code of conduct
114114

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.
115+
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)