Skip to content

Commit 4d3acb6

Browse files
committed
Added sample app
1 parent a015140 commit 4d3acb6

17 files changed

+11887
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
## 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.
77

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).
10+
811
## Setup
912
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.
1013

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"clean": "npm cache clean --force && npm run rimraf -- node_modules dist",
8080
"clean:build": "npm run rimraf -- dist",
8181
"lint": "npm run tslint -- -c tslint.json './src/**/*.ts' './src/**/*.tsx'",
82-
"start": "node scripts/start.js",
82+
"start": "npm install && npm run build && npm link && npm --prefix ./sample install && npm --prefix ./sample run start",
8383
"build": "npm run lint && tsc",
8484
"test": "node scripts/test.js --env=jsdom",
8585
"prepublishOnly": "npm run clean && npm install && npm run build"

sample/README.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# react-aad-msal Sample App
2+
3+
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+
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+
### Prerequisites
19+
20+
*Setting up an Azure Active Directory App*
21+
22+
In order to use this sample, you must have an Azure Active Directory application setup.
23+
24+
Documentation for AAD Application:
25+
26+
https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal
27+
28+
Documentation for AAD B2C Application:
29+
30+
https://docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-app-registration
31+
32+
## Getting Started
33+
34+
*NOTE: in order to successfully build and run this sample, be sure to complete the prerequisite steps above.
35+
An Azure Active Directory application must first be setup and configured.*
36+
37+
- Build the `react-aad-msal` component: `npm install && npm run build`
38+
- create a `.env.local` file, with the following variables:
39+
```
40+
REACT_APP_AAD_APP_CLIENT_ID=<client id guid>
41+
REACT_APP_AUTHORITY=<authority url (optional)>
42+
```
43+
- Run the sample application: `npm install && npm run start`
44+
45+
The sample site should launch in a Web browser.
46+
47+
### Quickstart
48+
49+
1. `git clone [repository clone url]`
50+
2. `cd react-aad-msal`
51+
3. `npm install`
52+
4. Setup a `.env` file with the following items:
53+
- `REACT_APP_AAD_APP_CLIENT_ID`
54+
- `REACT_APP_AUTHORITY`
55+
5. `npm start`
56+
57+
## Demo
58+
59+
This sample demonstrates how to use the `Popup` auth method. As well as how to use the (optional) redux store.
60+
61+
To run this sample, you just need to provide your `REACT_APP_AAD_APP_CLIENT_ID` and (optionally) `REACT_APP_AUTHORITY`.
62+
63+
``` javascript
64+
<AzureAD
65+
clientID={process.env.REACT_APP_AAD_APP_CLIENT_ID}
66+
authority={process.env.REACT_APP_AUTHORITY}
67+
...
68+
>
69+
```
70+
71+
Type is set to `LoginType.Popup`.
72+
73+
``` javascript
74+
<AzureAD
75+
...
76+
type={LoginType.Popup}
77+
...
78+
>
79+
```
80+
81+
And we also provide a reduxStore (setup in our `reduxStore.js` file).
82+
83+
``` javascript
84+
import { basicReduxStore } from './reduxStore';
85+
86+
<AzureAD
87+
...
88+
reduxStore={basicReduxStore}
89+
...
90+
>
91+
```
92+
93+
For our `userInfoCallback` property, we setup a function that just saves the userInfo we get back from AAD to state.
94+
95+
``` javascript
96+
userJustLoggedIn = receivedUserInfo => {
97+
this.setState({ userInfo: receivedUserInfo })
98+
}
99+
```
100+
101+
For our `unauthenticatedFunction` property, we setup a function that returns a button that uses the login function provided by our AzureAD component.
102+
103+
``` javascript
104+
unauthenticatedFunction = loginFunction => {
105+
return (
106+
<button style={buttonStyle} onClick={loginFunction}>Login</button>
107+
);
108+
}
109+
```
110+
111+
//TODO: Logout documentation
112+
113+
## Resources
114+
115+
- Link to react-aad-msal library github
116+
- Link to react-aad-msal npm page

0 commit comments

Comments
 (0)