You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
7
6
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 trigger 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 trigger in your react app
18
+
* Optional use of redux store containing the token and user information returned from Active Directory
19
+
20
+
## Getting Started //TODO
21
+
22
+
### Prerequisites
23
+
24
+
(ideally very short, if any)
25
+
26
+
- OS
27
+
- Library version
28
+
- ...
29
+
30
+
### Installation
31
+
32
+
(ideally very short)
33
+
34
+
- npm install [package name]
35
+
- mvn install
36
+
- ...
37
+
38
+
### Quickstart
39
+
(Add steps to get up and running quickly)
40
+
41
+
1. git clone [repository clone url]
42
+
2. cd [respository name]
43
+
3. ...
10
44
11
45
## Setup
12
46
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.
13
47
14
48
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).
15
49
16
-
```javascript
50
+
```jsx
17
51
// ...
18
52
19
53
return (
@@ -66,7 +100,7 @@ Find the assignment for ClientID and replace the value with the Application ID f
66
100
## Login
67
101
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.
68
102
69
-
```javascript
103
+
```javascript
70
104
import AzureAD from 'AzureAD'
71
105
72
106
loginCallback = (login) => {
@@ -78,14 +112,10 @@ loginCallback = (login) => {
78
112
79
113
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.
80
114
81
-
```javascript
82
-
// ...
83
-
115
+
``` javascript
84
116
printUserInfo = (userInfo) => {
85
117
console.log(userInfo)
86
118
};
87
-
88
-
// ...
89
119
```
90
120
91
121
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 +124,7 @@ Once you've set this up, you should be able to set up a button to login that wil
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.
109
139
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
-
114
140
## Integrating with a Redux Store
115
141
116
142
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.
117
143
118
144
Import your store into the file rendering the AzureAD component and pass it in:
119
145
120
-
```javascript
146
+
``` jsx
121
147
<AzureAD
122
148
reduxStore={store}
123
149
clientID={'<Application IDfor your application>'}
@@ -132,7 +158,7 @@ Import your store into the file rendering the AzureAD component and pass it in:
132
158
133
159
Add a case to handle ```AAD_LOGIN_SUCCESS``` and ```AAD_LOGOUT_SUCCESS``` actions in a reducer file:
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.
181
+
182
+
## Resources //TODO
183
+
184
+
- [Azure Active Directory](https://docs.microsoft.com/en-us/azure/active-directory/get-started-azure-ad)
This repository contains a sample react application that demonstrates how to use the [`react-aad-msal`](https://www.npmjs.com/package/react-aad-msal) node module, an Azure Activity Directory react component.
4
4
5
-
## Features
6
-
7
-
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.
8
-
9
-
The React AAD MSAL library provides the following features:
10
-
11
-
* Login using Azure Active Directory
12
-
- create your own function that handles how login (using this AzureAD component) is trigger in your react app
13
-
- 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.
14
-
* Logout callback
15
-
- create your own function to handle how logout (using this AzureAD component) is trigger in your react app
16
-
* Optional use of redux store containing the token and user information returned from Active Directory
17
-
18
5
## Getting Started
19
-
- Build the `react-aad-msal` component: `npm install && npm run build`
20
-
- create a `.env.local` file, with the following variables:
21
-
```
22
-
REACT_APP_AAD_APP_CLIENT_ID=<client id guid>
23
-
REACT_APP_AUTHORITY=<authority url (optional)>
24
-
```
25
-
- Run the sample application: `npm install && npm run start`
26
-
27
-
The sample site should launch in a Web browser.
28
6
29
7
### Prerequisites
30
8
@@ -40,7 +18,6 @@ Documentation for AAD B2C Application:
For our `userInfoCallback` property, we setup a function that just saved the userInfo we get back to state.
134
+
135
+
``` javascript
136
+
userJustLoggedIn = receivedUserInfo => {
137
+
this.setState({ userInfo: receivedUserInfo })
122
138
}
123
139
```
124
140
125
-
//TODO: Logout documentation
141
+
For our `unauthenticatedFunction` property, we setup a function that returns a a div that lets the user know we are going to redirect them, and uses the login function provided by our AzureAD component to complete the login in a new window.
126
142
127
-
## Resources
143
+
``` javascript
144
+
unauthenticatedFunction = loginFunction => {
145
+
if (this.state.redirectEnabled && !this.interval) {
0 commit comments