Skip to content

Commit e17fa47

Browse files
liliankasemlbochenek
authored andcommitted
Updating README to add component property details (#2)
* Updating README to add logout details
1 parent 6c358d7 commit e17fa47

File tree

1 file changed

+71
-21
lines changed

1 file changed

+71
-21
lines changed

README.md

Lines changed: 71 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,124 @@
1-
## React AAD MSAL
1+
# React AAD MSAL
22

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

5-
### Overview
5+
## Overview
66
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-
### Setup
8-
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 OnAuthenticationComponent given. This is where you should put the secure, user-specific parts of your app. `loginCallback` and `printUserInfo` can be any user defined functions.
97

8+
## Setup
9+
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.
1010

1111
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).
12+
1213
```javascript
13-
// ...
14+
// ...
1415

1516
return (
1617
<AzureAD
1718
clientID={'<Application ID for your application>'}
18-
graphScopes={['https://<your-tenant-name>.onmicrosoft.com/hello/demo.read']}
19+
scopes={['https://<your-tenant-name>.onmicrosoft.com/<your-application-name>/<scope (i.e. demo.read)>']}
1920
unauthenticatedFunction={this.loginCallback}
2021
authenticatedFunction={this.logoutCallback}
2122
userInfoCallback={this.printUserInfo}
2223
authority={'https://login.microsoftonline.com/tfp/<your-tenant-name>.onmicrosoft.com/<your-sign-in-sign-up-policy>'}
2324
type={LoginType.Popup}>
24-
<OnAuthenticationComponent />
2525
</AzureAD>
2626
);
2727
```
28-
### Login
28+
29+
## Component Properties
30+
31+
### Required
32+
33+
- `clientID`: String representing your Azure Active Directory Application ID
34+
35+
- `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)
36+
37+
- `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.
38+
39+
- `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
40+
41+
- `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:
42+
43+
``` javascript
44+
IUserInfo {
45+
jwtAccessToken: string,
46+
jwtIdToken: string,
47+
user: Msal.User
48+
}
49+
```
50+
51+
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)
52+
53+
- Child Component: You should provide a child component to the AzureAD component, this will be rendered when login is successful
54+
55+
### Optional
56+
57+
- `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>`
58+
59+
- `type`: `LoginType.Popup`. Popup is currently the only type available; redirect is currently buggy and disabled.
60+
61+
- `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`
62+
63+
## Login
2964
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.
65+
3066
```javascript
3167
import AzureAD from 'AzureAD'
3268
3369
loginCallback = (login) => {
3470
return <button onclick={login}>Login</button>;
3571
};
72+
3673
// ...
3774
```
75+
3876
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.
77+
3978
```javascript
40-
//...
41-
printUserInfo = (userInfo) => {console.log(userInfo)};
42-
//...
79+
// ...
80+
81+
printUserInfo = (userInfo) => {
82+
console.log(userInfo)
83+
};
84+
85+
// ...
4386
```
4487
45-
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-b2c/) 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.
88+
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.
89+
90+
## Logout
4691
47-
### Logout
92+
Logging out is just as easy.
4893
49-
Logging out is just as easy.
5094
```javascript
5195
logoutCallback = (logout) => {
52-
return <button onclick={logout}>Logout</button>;
96+
return (
97+
<div>
98+
You're logged in!
99+
<button onclick={logout}>Logout</button>
100+
</div>
101+
);
53102
};
54103
```
104+
55105
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.
56106
57-
### Samples
107+
## Samples
58108
59109
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.
60110

61-
### Integrating with a Redux Store
111+
## Integrating with a Redux Store
62112

63-
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.
113+
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.
64114

65115
Import your store into the file rendering the AzureAD component and pass it in:
66116

67117
```javascript
68118
<AzureAD
69119
reduxStore={store}
70120
clientID={'<Application ID for your application>'}
71-
graphScopes={['https://<your-tenant-name>.onmicrosoft.com/hello/demo.read']}
121+
scopes={['https://<your-tenant-name>.onmicrosoft.com/<your-application-name>/demo.read']}
72122
unauthenticatedFunction={this.loginCallback}
73123
authenticatedFunction={this.logoutCallback}
74124
userInfoCallback={this.printUserInfo}
@@ -91,7 +141,7 @@ const sampleReducer = (state = initialState, action) => {
91141
case 'AAD_LOGOUT_SUCCESS':
92142
return { ...state, aadResponse: null};
93143
default:
94-
return state;
144+
return state;
95145
}
96146
};
97-
```
147+
```

0 commit comments

Comments
 (0)