Skip to content

Commit 1e2443e

Browse files
authored
Merge pull request #16 from Azure-Samples/issue/11/update-readme
Updating READMEs [Issue #11]
2 parents c93b7d7 + 77c7213 commit 1e2443e

File tree

6 files changed

+2807
-2625
lines changed

6 files changed

+2807
-2625
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## [project-title] Changelog
1+
## React AAD MSAL Changelog
22

33
<a name="x.y.z"></a>
44
# x.y.z (yyyy-mm-dd)

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Contributing to [project-title]
1+
# Contributing to React AAD MSAL
22

33
This project welcomes contributions and suggestions. Most contributions require you to agree to a
44
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us

README.md

Lines changed: 69 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,55 @@
22

33
![build status](https://reactaad.visualstudio.com/_apis/public/build/definitions/1c71aebc-1683-48cd-9ab2-8663e6a4ec55/5/badge)
44

5-
## Overview
65
React AAD MSAL is a library to easily integrate the Microsoft Authentication Library with Azure Active Directory in your React app quickly and reliably. The library focuses on flexibility, allowing you to define how you want to interact with logins and logouts.
76

8-
## Sample Application
9-
A sample React-based Single Page Application (SPA) that uses this component is available in the [sample folder](sample/README.md).
7+
## Features
8+
9+
React AAD MSAL is a library that allows you to easily integrate auth using Azure Active Directory into your React application. The library focuses on flexibility, allowing you to define how you want to interact with logins and logouts.
10+
11+
The React AAD MSAL library provides the following features:
12+
13+
* Login using Azure Active Directory
14+
- create your own function that handles how login (using this AzureAD component) is triggered in your react app
15+
- create your own function that handles the login success. The AzureAD library will call this function when login is complete to pass back the user info.
16+
* Logout callback
17+
- create your own function to handle how logout (using this AzureAD component) is triggered in your react app
18+
* Optional use of redux store containing the token and user information returned from Active Directory
19+
20+
## Getting Started
21+
22+
### Prerequisites
23+
24+
- [node.js](https://nodejs.org/en/)
25+
26+
### Installation
27+
28+
- `npm install react-aad-msal`
29+
30+
### Quickstart
31+
32+
If you'd like a sample application running, please see the [sample readme](sample/README.md).
33+
34+
To build this component, follow these steps:
35+
36+
1. `git clone https://github.com/Azure-Samples/react-aad-msal.git`
37+
2. `cd ./react-aad-msal`
38+
3. Build the `react-aad-msal` component:
39+
- `npm install`
40+
- `npm run build`
1041

1142
## Setup
1243
In the render module of your component, make sure to create an AzureAD component with the arguments you need. This uses the functions that you will define. Once the user is successfully authenticated, the component will render the JSX returned by the `authenticatedFunction`, which in this case is called `logoutCallback`. This is where you should put the secure, user-specific parts of your app. `loginCallback` and `printUserInfo` can be any user defined functions.
1344

1445
Find the assignment for ClientID and replace the value with the Application ID for your application from the azure portal. The authority is the sign-in/signup policy for your application. Graph scopes is a list of scope URLs that you want to grant access to. You can find more information on the [active directory MSAL single page app azure sample](https://github.com/Azure-Samples/active-directory-b2c-javascript-msal-singlepageapp).
1546

16-
```javascript
47+
``` jsx
1748
// ...
1849

1950
return (
2051
<AzureAD
2152
clientID={'<Application ID for your application>'}
22-
scopes={['https://<your-tenant-name>.onmicrosoft.com/<your-application-name>/<scope (i.e. demo.read)>']}
53+
scopes={['<property (i.e. user.read)>', 'https://<your-tenant-name>.onmicrosoft.com/<your-application-name>/<scope (i.e. demo.read)>']}
2354
unauthenticatedFunction={this.loginCallback}
2455
authenticatedFunction={this.logoutCallback}
2556
userInfoCallback={this.printUserInfo}
@@ -31,42 +62,21 @@ Find the assignment for ClientID and replace the value with the Application ID f
3162

3263
## Component Properties
3364

34-
### Required
35-
36-
- `clientID`: String representing your Azure Active Directory Application ID
37-
38-
- `scopes`: Array of permission scopes you want to request from the application you are authenticating against. You can see possible [values for this property here](https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-v2-scopes)
39-
40-
- `authenticatedFunction`: A user defined callback function for the AzureAD component to consume. This function receives the AzureAD components logout function, and returns JSX containing the logged in portion of your app. You can use this received logout callback to attach it to any part of your logged in portion of your application.
41-
42-
- `unauthenticatedFunction`: A user defined callback function for the AzureAD component to consume. This function receives the AzureAD components login function which you can then use to trigger a login as you like
43-
44-
- `userInfoCallback`: A user defined callback function. The AzureAD library will calls this function when login is complete to pass back the user info in the following format:
45-
46-
``` javascript
47-
IUserInfo {
48-
jwtAccessToken: string,
49-
jwtIdToken: string,
50-
user: Msal.User
51-
}
52-
```
53-
54-
The format of [`Msal.User` can be found here](https://htmlpreview.github.io/?https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-js/dev/docs/classes/_user_.user.html)
55-
56-
- Child Component: You should provide a child component to the AzureAD component, this will be rendered when login is successful
57-
58-
### Optional
59-
60-
- `authority`: A string representing your Azure Active Directory application policy. Include if you are trying to authenticate against your Azure Active Directory application. If you're using a B2C AAD, it is usually in the format of: `https://login.microsoftonline.com/tfp/<your-tenant-name>.onmicrosoft.com/<your-sign-in-sign-up-policy>`
61-
62-
- `type`: `LoginType.Popup`. Popup is currently the only type available; redirect is currently buggy and disabled.
63-
64-
- `reduxStore`: If you want to use redux for auth, you can provide a redux store which the AzureAD component will dispatch a `AAD_LOGIN_SUCCESS` action, as well as a `payload` containing `IUserInfo`
65+
| Property | Description |
66+
| --- | --- |
67+
| `clientID` | String representing your Azure Active Directory Application ID |
68+
| `scopes` | Array of permission scopes you want to request from the application you are authenticating against. You can see possible [values for this property here](https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-v2-scopes) |
69+
| `authenticatedFunction` | A user defined callback function for the AzureAD component to consume. This function receives the AzureAD components logout function, and returns JSX containing the logged in portion of your app. You can use this received logout callback to attach it to any part of your logged in portion of your application |
70+
| `unauthenticatedFunction` | A user defined callback function for the AzureAD component to consume. This function receives the AzureAD components login function which you can then use to trigger a login as you like |
71+
| `userInfoCallback` | A user defined callback function. The AzureAD library will calls this function when login is complete to pass back the user info in the following format: <br /><br /> ``` UserInfo { jwtAccessToken: string, jwtIdToken: string, user: Msal.User }``` <br /> <br /> The format of `Msal.User` [can be found here](https://htmlpreview.github.io/?https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-js/dev/docs/classes/_user_.user.html) |
72+
| `authority` | **[Optional]** A string representing your Azure Active Directory application policy. Include if you are trying to authenticate against your Azure Active Directory application. If you're using a B2C AAD, it is usually in the format of: `https://login.microsoftonline.com/tfp/<your-tenant-name>.onmicrosoft.com/<your-sign-in-sign-up-policy>` |
73+
| `type` | **[Optional]** `LoginType.Popup`. Popup is currently the only type available; redirect is currently buggy and disabled. |
74+
| `reduxStore` | **[Optional]** If you want to use redux for auth, you can provide a redux store which the AzureAD component will dispatch a `AAD_LOGIN_SUCCESS` action, as well as a `payload` containing `IUserInfo` |
6575

6676
## Login
6777
To login, first create a callback function for the AzureAD component to consume. This function will be called when the component loads, and it will pass in the function to be called when the user wants to login. In this case, we create a button that will log the user in.
6878

69-
```javascript
79+
``` jsx
7080
import AzureAD from 'AzureAD'
7181

7282
loginCallback = (login) => {
@@ -78,14 +88,10 @@ loginCallback = (login) => {
7888

7989
Once they're logged in, the AzureAD library will call another function given with an `IUserInfo` instance. You can do whatever you want with this, but you should store it. In this example, we just print it out to console.
8090

81-
```javascript
82-
// ...
83-
91+
``` javascript
8492
printUserInfo = (userInfo) => {
8593
console.log(userInfo)
8694
};
87-
88-
// ...
8995
```
9096

9197
Once you've set this up, you should be able to set up a button to login that will hit an AAD instance. To set up your instance, check out the documentation on [Azure Active Directory](https://docs.microsoft.com/en-us/azure/active-directory/get-started-azure-ad) and on how to connect an [Identity Provider](https://docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-setup-msa-app) for that AAD instance.
@@ -94,7 +100,7 @@ Once you've set this up, you should be able to set up a button to login that wil
94100

95101
Logging out is just as easy.
96102

97-
```javascript
103+
``` jsx
98104
logoutCallback = (logout) => {
99105
return (
100106
<div>
@@ -107,21 +113,17 @@ logoutCallback = (logout) => {
107113
108114
You can, of course, include a component in either of these functions. This allows you to gate which view of your application users get, based on whether or not they are authenticated.
109115
110-
## Samples
111-
112-
If you want to run examples of this library out of the box, feel free to go to [the samples repo](https://reactaad.visualstudio.com/react-aad-msal/). There you'll find a couple implementations that leverage the library, as well as a tutorial of how to set up Azure Active Directory with an Identity Provider.
113-
114116
## Integrating with a Redux Store
115117
116118
The Azure AD component optionally accepts a ```reduxStore``` prop. On successful login, Azure AD will dispatch an action of type ```AAD_LOGIN_SUCCESS``` to the provided store, containing the token and user information returned from Active Directory. It does the same for logout events, but the action will not contain a payload.
117119
118120
Import your store into the file rendering the AzureAD component and pass it in:
119121
120-
```javascript
122+
``` jsx
121123
<AzureAD
122124
reduxStore={store}
123125
clientID={'<Application ID for your application>'}
124-
scopes={['https://<your-tenant-name>.onmicrosoft.com/<your-application-name>/demo.read']}
126+
scopes={['<property (i.e. user.read)>', 'https://<your-tenant-name>.onmicrosoft.com/<your-application-name>/<scope (i.e. demo.read)>']}
125127
unauthenticatedFunction={this.loginCallback}
126128
authenticatedFunction={this.logoutCallback}
127129
userInfoCallback={this.printUserInfo}
@@ -132,7 +134,7 @@ Import your store into the file rendering the AzureAD component and pass it in:
132134
133135
Add a case to handle ```AAD_LOGIN_SUCCESS``` and ```AAD_LOGOUT_SUCCESS``` actions in a reducer file:
134136
135-
```javascript
137+
``` javascript
136138
const initialState = {
137139
aadResponse: null,
138140
};
@@ -147,4 +149,20 @@ const sampleReducer = (state = initialState, action) => {
147149
return state;
148150
}
149151
};
150-
```
152+
```
153+
154+
## Demo
155+
156+
A sample React-based Single Page Application (SPA) that uses this component is available in the [sample folder](sample/README.md). There you'll find a couple implementations that leverage the library, as well as a tutorial of how to set up Azure Active Directory with an Identity Provider.
157+
158+
## Resources
159+
160+
- [React AAD MSAL NPM Module](https://www.npmjs.com/package/react-aad-msal)
161+
- [Get Started with Azure Active Directory](https://docs.microsoft.com/en-us/azure/active-directory/get-started-azure-ad)
162+
- [MSAL Documentation](https://htmlpreview.github.io/?https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-js/dev/docs/index.html)
163+
- [AAD v2 Scopes](https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-v2-scopes)
164+
- [AAD B22 Setup MSA App](https://docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-setup-msa-app)
165+
166+
## Problems or Suggestions
167+
168+
[Please create an issue.](/issues)

0 commit comments

Comments
 (0)