├── .editorconfig ├── .github ├── ISSUE_TEMPLATE.md ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .vscode └── settings.json ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── lerna.json ├── package-lock.json ├── package.json ├── packages └── react-aad-msal │ ├── .auto-changelog │ ├── .eslintrc.js │ ├── .gitignore │ ├── .huskyrc.json │ ├── .lintstagedrc.json │ ├── .prettierignore │ ├── .prettierrc │ ├── CHANGELOG.md │ ├── LICENSE │ ├── babel.config.js │ ├── jest.config.js │ ├── package.json │ ├── src │ ├── AccessTokenResponse.ts │ ├── AuthenticationActionCreators.ts │ ├── IdTokenResponse.ts │ ├── Logger.ts │ ├── MsalAuthProvider.ts │ ├── components │ │ ├── AzureAD.tsx │ │ └── withAuthentication.tsx │ ├── enums │ │ ├── AuthenticationActions.ts │ │ ├── AuthenticationState.ts │ │ ├── LoginType.ts │ │ ├── TokenType.ts │ │ └── index.ts │ ├── index.test.tsx │ ├── index.ts │ └── interfaces │ │ ├── IAccountInfo.ts │ │ ├── IAuthProvider.ts │ │ ├── IMsalAuthProviderConfig.ts │ │ └── index.ts │ ├── tsconfig.json │ └── webpack.config.js ├── samples ├── react-javascript │ ├── .gitignore │ ├── README.md │ ├── package.json │ ├── public │ │ ├── auth.html │ │ ├── favicon.ico │ │ ├── index.html │ │ └── manifest.json │ ├── src │ │ ├── App.css │ │ ├── App.js │ │ ├── App.test.js │ │ ├── GetAccessTokenButton.js │ │ ├── GetIdTokenButton.js │ │ ├── SampleAppButtonLaunch.js │ │ ├── SampleAppRedirectOnLaunch.js │ │ ├── authProvider.js │ │ ├── index.css │ │ ├── index.js │ │ ├── reduxStore.js │ │ └── registerServiceWorker.js │ └── yarn.lock └── react-typescript │ ├── package.json │ ├── public │ ├── auth.html │ ├── favicon.ico │ ├── index.html │ └── manifest.json │ ├── src │ ├── App.css │ ├── App.test.tsx │ ├── App.tsx │ ├── GetAccessTokenButton.tsx │ ├── GetIdTokenButton.tsx │ ├── SampleAppButtonLaunch.tsx │ ├── SampleAppRedirectOnLaunch.tsx │ ├── SampleBox.tsx │ ├── authProvider.ts │ ├── index.css │ ├── index.tsx │ ├── react-app-env.d.ts │ ├── reduxStore.ts │ ├── serviceWorker.ts │ └── setupTests.ts │ └── tsconfig.json └── yarn.lock /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | charset = utf-8 7 | indent_style = space 8 | indent_size = 2 9 | end_of_line = lf 10 | insert_final_newline = true 11 | trim_trailing_whitespace = true 12 | 13 | [*.md] 14 | insert_final_newline = false 15 | trim_trailing_whitespace = false 16 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 4 | > Please provide us with the following information: 5 | > --------------------------------------------------------------- 6 | 7 | ### This issue is for a: (mark with an `x`) 8 | ``` 9 | - [ ] bug report -> please search issues before submitting 10 | - [ ] feature request 11 | - [ ] documentation issue or request 12 | - [ ] regression (a behavior that used to work and stopped in a new release) 13 | ``` 14 | 15 | ### Minimal steps to reproduce 16 | > 17 | 18 | ### Any log messages given by the failure 19 | > 20 | 21 | ### Expected/desired behavior 22 | > 23 | 24 | ### OS and Version? 25 | > Windows 7, 8 or 10. Linux (which distribution). macOS (Yosemite? El Capitan? Sierra?) 26 | 27 | ### Library versions 28 | - `react-aad-msal`: [e.g. version number] 29 | - `msal`: [e.g. version number] 30 | 31 | ### Mention any other details that might be useful 32 | 33 | > --------------------------------------------------------------- 34 | > Thanks! We'll be in touch soon. 35 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Library versions** 11 | - `react-aad-msal`: [e.g. version number] 12 | - `msal`: [e.g. version number] 13 | 14 | **Describe the bug** 15 | A clear and concise description of what the bug is. 16 | 17 | **Expected behavior** 18 | A clear and concise description of what you expected to happen. 19 | 20 | 21 | **To Reproduce** 22 | Steps to reproduce the behavior: 23 | 1. Go to '...' 24 | 2. Click on '....' 25 | 3. Scroll down to '....' 26 | 4. See error 27 | 28 | **Desktop (please complete the following information):** 29 | - OS: [e.g. iOS] 30 | - Browser [e.g. chrome, safari] 31 | - Version [e.g. 22] 32 | 33 | **Smartphone (please complete the following information):** 34 | - Device: [e.g. iPhone6] 35 | - OS: [e.g. iOS8.1] 36 | - Browser [e.g. stock browser, safari] 37 | - Version [e.g. 22] 38 | 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Purpose 2 | 3 | * ... 4 | 5 | ## Does this introduce a breaking change? 6 | 7 | ``` 8 | [ ] Yes 9 | [ ] No 10 | ``` 11 | 12 | ## Pull Request Type 13 | What kind of change does this Pull Request introduce? 14 | 15 | 16 | ``` 17 | [ ] Bugfix 18 | [ ] Feature 19 | [ ] Code style update (formatting, local variables) 20 | [ ] Refactoring (no functional changes, no api changes) 21 | [ ] Documentation content changes 22 | [ ] Other... Please describe: 23 | ``` 24 | 25 | ## How to Test 26 | * Get the code 27 | 28 | ``` 29 | git clone [repo-address] 30 | cd [repo-name] 31 | git checkout [branch-name] 32 | npm install 33 | ``` 34 | 35 | * Test the code 36 | 37 | ``` 38 | ``` 39 | 40 | ## What to Check 41 | Verify that the following are valid 42 | * ... 43 | 44 | ## Other Information 45 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | *.VC.VC.opendb 85 | 86 | # Visual Studio profiler 87 | *.psess 88 | *.vsp 89 | *.vspx 90 | *.sap 91 | 92 | # TFS 2012 Local Workspace 93 | $tf/ 94 | 95 | # Guidance Automation Toolkit 96 | *.gpState 97 | 98 | # ReSharper is a .NET coding add-in 99 | _ReSharper*/ 100 | *.[Rr]e[Ss]harper 101 | *.DotSettings.user 102 | 103 | # JustCode is a .NET coding add-in 104 | .JustCode 105 | 106 | # TeamCity is a build add-in 107 | _TeamCity* 108 | 109 | # DotCover is a Code Coverage Tool 110 | *.dotCover 111 | 112 | # NCrunch 113 | _NCrunch_* 114 | .*crunch*.local.xml 115 | nCrunchTemp_* 116 | 117 | # MightyMoose 118 | *.mm.* 119 | AutoTest.Net/ 120 | 121 | # Web workbench (sass) 122 | .sass-cache/ 123 | 124 | # Installshield output folder 125 | [Ee]xpress/ 126 | 127 | # DocProject is a documentation generator add-in 128 | DocProject/buildhelp/ 129 | DocProject/Help/*.HxT 130 | DocProject/Help/*.HxC 131 | DocProject/Help/*.hhc 132 | DocProject/Help/*.hhk 133 | DocProject/Help/*.hhp 134 | DocProject/Help/Html2 135 | DocProject/Help/html 136 | 137 | # Click-Once directory 138 | publish/ 139 | 140 | # Publish Web Output 141 | *.[Pp]ublish.xml 142 | *.azurePubxml 143 | # TODO: Comment the next line if you want to checkin your web deploy settings 144 | # but database connection strings (with potential passwords) will be unencrypted 145 | *.pubxml 146 | *.publishproj 147 | 148 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 149 | # checkin your Azure Web App publish settings, but sensitive information contained 150 | # in these scripts will be unencrypted 151 | PublishScripts/ 152 | 153 | # NuGet Packages 154 | *.nupkg 155 | # The packages folder can be ignored because of Package Restore 156 | 157 | # Uncomment if necessary however generally it will be regenerated when needed 158 | #!**/packages/repositories.config 159 | # NuGet v3's project.json files produces more ignoreable files 160 | *.nuget.props 161 | *.nuget.targets 162 | 163 | # Microsoft Azure Build Output 164 | csx/ 165 | *.build.csdef 166 | 167 | # Microsoft Azure Emulator 168 | ecf/ 169 | rcf/ 170 | 171 | # Windows Store app package directories and files 172 | AppPackages/ 173 | BundleArtifacts/ 174 | Package.StoreAssociation.xml 175 | _pkginfo.txt 176 | 177 | # Visual Studio cache files 178 | # files ending in .cache can be ignored 179 | *.[Cc]ache 180 | # but keep track of directories ending in .cache 181 | !*.[Cc]ache/ 182 | 183 | # Others 184 | ClientBin/ 185 | ~$* 186 | *~ 187 | *.dbmdl 188 | *.dbproj.schemaview 189 | *.pfx 190 | *.publishsettings 191 | node_modules/ 192 | orleans.codegen.cs 193 | 194 | # Since there are multiple workflows, uncomment next line to ignore bower_components 195 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 196 | #bower_components/ 197 | 198 | # RIA/Silverlight projects 199 | Generated_Code/ 200 | 201 | # Backup & report files from converting an old project file 202 | # to a newer Visual Studio version. Backup files are not needed, 203 | # because we have git ;-) 204 | _UpgradeReport_Files/ 205 | Backup*/ 206 | UpgradeLog*.XML 207 | UpgradeLog*.htm 208 | 209 | # SQL Server files 210 | *.mdf 211 | *.ldf 212 | 213 | # Business Intelligence projects 214 | *.rdl.data 215 | *.bim.layout 216 | *.bim_*.settings 217 | 218 | # Microsoft Fakes 219 | FakesAssemblies/ 220 | 221 | # GhostDoc plugin setting file 222 | *.GhostDoc.xml 223 | 224 | # Node.js Tools for Visual Studio 225 | .ntvs_analysis.dat 226 | 227 | # Visual Studio 6 build log 228 | *.plg 229 | 230 | # Visual Studio 6 workspace options file 231 | *.opt 232 | 233 | # Visual Studio LightSwitch build output 234 | **/*.HTMLClient/GeneratedArtifacts 235 | **/*.DesktopClient/GeneratedArtifacts 236 | **/*.DesktopClient/ModelManifest.xml 237 | **/*.Server/GeneratedArtifacts 238 | **/*.Server/ModelManifest.xml 239 | _Pvt_Extensions 240 | 241 | # Paket dependency manager 242 | .paket/paket.exe 243 | paket-files/ 244 | 245 | # FAKE - F# Make 246 | .fake/ 247 | 248 | # JetBrains Rider 249 | .idea/ 250 | *.sln.iml 251 | 252 | # Library specific ignore files 253 | node_modules/ 254 | *.tgz 255 | *.zip 256 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.exclude": { 3 | "**/node_modules": true, 4 | "debug.log": true 5 | }, 6 | "typescript.tsdk": "node_modules\\typescript\\lib", 7 | "[javascript]": { 8 | "editor.defaultFormatter": "esbenp.prettier-vscode", 9 | "editor.formatOnSave": true 10 | }, 11 | "[javascriptreact]": { 12 | "editor.defaultFormatter": "esbenp.prettier-vscode", 13 | "editor.formatOnSave": true 14 | }, 15 | "[typescript]": { 16 | "editor.defaultFormatter": "esbenp.prettier-vscode", 17 | "editor.formatOnSave": true 18 | }, 19 | "[typescriptreact]": { 20 | "editor.defaultFormatter": "esbenp.prettier-vscode", 21 | "editor.formatOnSave": true 22 | }, 23 | "editor.codeActionsOnSave": { 24 | "source.fixAll.eslint": true 25 | }, 26 | "eslint.validate": [ 27 | "html", 28 | "javascript", 29 | "typescript", 30 | "javascriptreact", 31 | "typescriptreact" 32 | ], 33 | "eslint.workingDirectories": [ 34 | {"pattern": "./packages/*/"}, 35 | {"pattern": "./samples/*/"} 36 | ], 37 | } 38 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to React AAD MSAL 2 | 3 | This project welcomes contributions and suggestions. Most contributions require you to agree to a 4 | Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us 5 | the rights to use your contribution. For details, visit https://cla.microsoft.com. 6 | 7 | When you submit a pull request, a CLA-bot will automatically determine whether you need to provide 8 | a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions 9 | provided by the bot. You will only need to do this once across all repos using our CLA. 10 | 11 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 12 | For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or 13 | contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. 14 | 15 | - [Code of Conduct](#coc) 16 | - [Issues and Bugs](#issue) 17 | - [Feature Requests](#feature) 18 | - [Submission Guidelines](#submit) 19 | 20 | ## Code of Conduct 21 | Help us keep this project open and inclusive. Please read and follow our [Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 22 | 23 | ## Found an Issue? 24 | If you find a bug in the source code or a mistake in the documentation, you can help us by 25 | [submitting an issue](#submit-issue) to the GitHub Repository. Even better, you can 26 | [submit a Pull Request](#submit-pr) with a fix. 27 | 28 | ## Want a Feature? 29 | You can *request* a new feature by [submitting an issue](#submit-issue) to the GitHub 30 | Repository. If you would like to *implement* a new feature, please submit an issue with 31 | a proposal for your work first, to be sure that we can use it. 32 | 33 | * **Small Features** can be crafted and directly [submitted as a Pull Request](#submit-pr). 34 | 35 | ## Submission Guidelines 36 | 37 | ### Submitting an Issue 38 | Before you submit an issue, search the archive, maybe your question was already answered. 39 | 40 | If your issue appears to be a bug, and hasn't been reported, open a new issue. 41 | Help us to maximize the effort we can spend fixing issues and adding new 42 | features, by not reporting duplicate issues. Providing the following information will increase the 43 | chances of your issue being dealt with quickly: 44 | 45 | * **Overview of the Issue** - if an error is being thrown a non-minified stack trace helps 46 | * **Version** - what version is affected (e.g. 0.1.2) 47 | * **Motivation for or Use Case** - explain what are you trying to do and why the current behavior is a bug for you 48 | * **Browsers and Operating System** - is this a problem with all browsers? 49 | * **Reproduce the Error** - provide a live example or a unambiguous set of steps 50 | * **Related Issues** - has a similar issue been reported before? 51 | * **Suggest a Fix** - if you can't fix the bug yourself, perhaps you can point to what might be 52 | causing the problem (line of code or commit) 53 | 54 | You can file new issues by providing the above information at the corresponding repository's issues link: https://github.com/[organization-name]/[repository-name]/issues/new]. 55 | 56 | ### Developing the Module 57 | If you want to test a change you added to the module, start the sample app with `npm run start-dev`. This will build the module and start the sample app without running the linter. 58 | 59 | ### Submitting a Pull Request (PR) 60 | Before you submit your Pull Request (PR) consider the following guidelines: 61 | 62 | * Search the repository (https://github.com/[organization-name]/[repository-name]/pulls) for an open or closed PR 63 | that relates to your submission. You don't want to duplicate effort. 64 | 65 | * Make your changes in a new git fork: 66 | 67 | * Commit your changes using a descriptive commit message 68 | * Push your fork to GitHub: 69 | * In GitHub, create a pull request 70 | * If we suggest changes then: 71 | * Make the required updates. 72 | * Rebase your fork and force push to your GitHub repository (this will update your Pull Request): 73 | 74 | ```shell 75 | git rebase master -i 76 | git push -f 77 | ``` 78 | 79 | That's it! Thank you for your contribution! 80 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 React AAD MSAL 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **DEPRECATION NOTICE: Microsoft has released the official [`@azure/msal-react`](https://www.npmjs.com/package/@azure/msal-react) library which replaces `react-aad-msal`. It is recommended that applications migrate to the officially supported library in order to utilize the better Auth Code Flow process. `react-aad-msal` uses older MSAL dependencies which have known drawbacks for some clients. New applications should not consider using this library, as it will not be maintained. Please review the `@azure/msal-react` official [documentation](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib/msal-react), [samples](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib/msal-react#samples), and [migration guide](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-react/docs/migration-guide.md) for more information.** 2 | 3 |
4 |
5 |
The easiest way to integrate the Microsoft Authentication Library (MSAL) with React applications. Secure your apps with Azure Active Directory (AAD)
7 | 10 | 11 |:monkey_face: Our code monkeys live on a solid diet of :star:'s. If you like what they're doing, please feed them!
12 | 13 | # React AAD MSAL 14 | 15 | A library of components to easily integrate the Microsoft Authentication Library with Azure Active Directory in your React app quickly and reliably. The library focuses on flexibility, providing functionality to login, logout, and fetch the user details while maintaining access to the underlying MSAL library for advanced use. 16 | 17 | **:exclamation: This library is not affiliated with the Identity team at Microsoft. It was developed as a tool for the Open Source community to use and contribute to as they see fit.** 18 | 19 | ## :memo: Table of contents 20 | 21 | - [React AAD MSAL](#react-aad-msal) 22 | - [:memo: Table of contents](#memo-table-of-contents) 23 | - [:tada: Features](#tada-features) 24 | - [:checkered_flag: Getting Started](#checkeredflag-getting-started) 25 | - [Prerequisites](#prerequisites) 26 | - [Installation](#installation) 27 | - [Creating the Provider](#creating-the-provider) 28 | - [Msal Configuration](#msal-configuration) 29 | - [Authentication Parameters](#authentication-parameters) 30 | - [Options](#options) 31 | - [:package: Authentication Components](#package-authentication-components) 32 | - [AzureAD Component](#azuread-component) 33 | - [Higher Order Component](#higher-order-component) 34 | - [:mortar_board: Advanced Topics](#mortarboard-advanced-topics) 35 | - [Getting Tokens for API Requests](#getting-tokens-for-api-requests) 36 | - [Refreshing Access Tokens](#refreshing-access-tokens) 37 | - [Renewing IdTokens](#renewing-idtokens) 38 | - [Integrating with a Redux Store](#integrating-with-a-redux-store) 39 | - [Accessing the MSAL API](#accessing-the-msal-api) 40 | - [:cd: Sample applications](#cd-sample-applications) 41 | - [:calendar: Roadmap](#calendar-roadmap) 42 | - [:books: Resources](#books-resources) 43 | - [:trophy: Contributors](#trophy-contributors) 44 | 45 | ## :tada: Features 46 | 47 | :white_check_mark: Login/logout with `AzureAD` component 48 | :white_check_mark: Callback functions for login success, logout success, and user info changed 49 | :white_check_mark: `withAuthentication` higher order component for protecting components, routes, or the whole app 50 | :white_check_mark: Function as Child Component pattern ([FaCC](https://medium.com/merrickchristensen/function-as-child-components-5f3920a9ace9)) to pass authentication data and login/logout functions to children components 51 | :white_check_mark: Redux integration for storing authentication status, user info, tokens, etc 52 | :white_check_mark: Automatic renewal of IdTokens, and optional function to get a fresh token at any point 53 | :white_check_mark: Easily fetch a fresh Access Token from cache (or refresh it) before calling API endpoints 54 | :white_check_mark: Various build types including ES6, CommonJS, and UMD 55 | 56 | ## :checkered_flag: Getting Started 57 | 58 | ### Prerequisites 59 | 60 | - [node.js](https://nodejs.org/en/) 61 | - [Register an app](https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app) in AzureAD to get a `clientId`. You will need to [follow additional steps](https://docs.microsoft.com/en-us/azure/active-directory/develop/scenario-spa-app-registration) to enable the app for your SPA site. 62 | 63 | ### Installation 64 | 65 | Via NPM: 66 | 67 | ``` 68 | npm install react-aad-msal msal --save 69 | ``` 70 | 71 | ### Creating the Provider 72 | 73 | Before beginning it is required to configure an instance of the `MsalAuthProvider` and give it three parameters: 74 | 75 | | Parameters | Description | 76 | | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | 77 | | `config` | Instance of a `Msal.Configuration` object to configure the underlying provider. The documentation for all the options can be found in the [configuration options](https://docs.microsoft.com/en-us/azure/active-directory/develop/msal-js-initializing-client-applications#configuration-options) doc | 78 | | `parameters` | Instance of the `Msal.AuthenticationParameters` configuration to identify how the authentication process should function. This object includes the `scopes` values. You can see possible [values for scopes here](https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-v2-scopes) | 79 | | `options` | **[Optional]** The `options` are defined by the [IMsalAuthProviderConfig](/packages/react-aad-msal/src/interfaces/IMsalAuthProviderConfig.ts) interface. This contains settings that describe how the authentication provider should handle certain authentication processes. | 80 | 81 | The `MsalAuthProvider` is meant to be a singleton. There are known implications when multiple instances of MSAL are running at the same time. The recommended approach is to instantiate the `MsalAuthProvider` in a separate file and `import` it when needed. 82 | 83 | ```TypeScript 84 | // authProvider.js 85 | import { MsalAuthProvider, LoginType } from 'react-aad-msal'; 86 | 87 | // Msal Configurations 88 | const config = { 89 | auth: { 90 | authority: 'https://login.microsoftonline.com/common', 91 | clientId: '263 | Welcome, {accountInfo.account.name}! 264 | 265 |
266 | ); 267 | case AuthenticationState.Unauthenticated: 268 | return ( 269 |An error occurred during authentication, please try again!
} 271 |272 | Hey stranger, you look new! 273 | 274 |
275 |Authenticating...
); 279 | } 280 | } 281 | } 282 |( 6 | WrappedComponent: React.ComponentType
, 7 | parameters: IAzureADProps, 8 | ): React.FunctionComponent
=> {
9 | // tslint:disable-next-line: no-shadowed-variable
10 | const withAuthentication: React.FunctionComponent = (props: any) => {
11 | const propParams: IAzureADProps = { forceLogin: true, ...parameters };
12 |
13 | withAuthentication.displayName = `withAuthentication(${WrappedComponent.displayName || WrappedComponent.name}`;
14 | return (
15 | This example will launch a popup dialog to allow for authentication with Azure Active Directory
51 | This example shows how you can use the AzureAD component to redirect the login screen automatically on
52 | page load. Click the checkbox below to enable the redirect and refresh your browser window.
53 | When logged in, this box will show your tokens and user info
91 | ID Token: {accountInfo.jwtIdToken}
92 |
94 | Username: {accountInfo.account.userName}
95 |
97 | Access Token: {accountInfo.jwtAccessToken}
98 |
100 | Name: {accountInfo.account.name}
101 | If authentication fails, this box will have the errors that occurred
111 | errorCode: {error.errorCode}
112 |
114 | errorMessage: {error.errorMessage}
115 |
14 | You can use the auth provider to get a fresh token. If a valid token is in cache it will be returned, otherwise
15 | a fresh token will be requested. If the request fails, the user will be forced to login again.
16 |
13 | It's also possible to renew the IdToken. If a valid token is in the cache, it will be returned. Otherwise a
14 | renewed token will be requested. If the request fails, the user will be forced to login again.
15 | You're logged in! You're logged in! Redirecting in {this.state.counter} seconds...
59 | When logged in, this box will show your tokens and user info
60 |
64 | ID Token:{" "}
65 | {accountInfo.jwtIdToken}
66 |
68 | Username:{" "}
69 | {accountInfo.account.userName}
70 |
72 |
73 | Access Token:
74 | {" "}
75 | {accountInfo.jwtAccessToken}
76 |
78 | Name:{" "}
79 | {accountInfo.account.name}
80 |
87 | If authentication fails, this box will have the errors that
88 | occurred
89 |
93 | errorCode:{" "}
94 | {error.errorCode}
95 |
97 |
98 | errorMessage:
99 | {" "}
100 | {error.errorMessage}
101 |
16 | You can use the auth provider to get a fresh token. If a valid token is
17 | in cache it will be returned, otherwise a fresh token will be requested.
18 | If the request fails, the user will be forced to login again.
19 |
16 | It's also possible to renew the IdToken. If a valid token is in the
17 | cache, it will be returned. Otherwise a renewed token will be requested.
18 | If the request fails, the user will be forced to login again.
19 | You're logged in! You're logged in! Redirecting in {counter} seconds...
12 | example will launch a popup dialog to allow for authentication with
13 | Azure Active Directory
14 |
21 | example shows how you can use the AzureAD component to redirect the reen
22 | automatically on page load.Click the checkbox below to enable the
23 | redirect and refresh your browser window.
24 | unauthenticatedFunction
62 | authenticatedFunction
70 |
10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
11 |
12 | The page will reload if you make edits.
13 | You will also see any lint errors in the console.
14 |
15 | ### `yarn test`
16 |
17 | Launches the test runner in the interactive watch mode.
18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
19 |
20 | ### `yarn build`
21 |
22 | Builds the app for production to the `build` folder.
23 | It correctly bundles React in production mode and optimizes the build for the best performance.
24 |
25 | The build is minified and the filenames include the hashes.
26 | Your app is ready to be deployed!
27 |
28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
29 |
30 | ### `yarn eject`
31 |
32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!**
33 |
34 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
35 |
36 | Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
37 |
38 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
39 |
40 | ## Learn More
41 |
42 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
43 |
44 | To learn React, check out the [React documentation](https://reactjs.org/).
45 |
46 | ### Code Splitting
47 |
48 | This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
49 |
50 | ### Analyzing the Bundle Size
51 |
52 | This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
53 |
54 | ### Making a Progressive Web App
55 |
56 | This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
57 |
58 | ### Advanced Configuration
59 |
60 | This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
61 |
62 | ### Deployment
63 |
64 | This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
65 |
66 | ### `yarn build` fails to minify
67 |
68 | This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
69 |
--------------------------------------------------------------------------------
/samples/react-javascript/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-javascript-sample",
3 | "version": "1.0.0",
4 | "description": "A sample React application that demonstrates the Azure AD react component.",
5 | "private": true,
6 | "license": "MIT",
7 | "repository": {
8 | "type": "git",
9 | "url": "https://github.com/syncweek-react-aad/react-aad.git"
10 | },
11 | "author": "Laura Bochenek",
12 | "contributors": [
13 | "Laura Bochenek Button Login
41 | Automatic Redirect
50 | Welcome to the react-aad-msal sample
66 | Authenticated Values
87 | Errors
107 | Welcome to the react-aad-msal sample
27 | Authenticated Values
58 | Errors
86 | Button Login
11 | Automatic Redirect
20 |