Skip to content
This repository was archived by the owner on May 20, 2022. It is now read-only.

Commit 48158fd

Browse files
authored
v4.0.0 (#125)
1 parent 87fef78 commit 48158fd

File tree

90 files changed

+5741
-1175
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+5741
-1175
lines changed

.editorconfig

Lines changed: 0 additions & 15 deletions
This file was deleted.

.eslintrc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// @generated by expo-module-scripts
2+
module.exports = require('expo-module-scripts/eslintrc.base.js');

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
.expo/
77

88
# VSCode
9-
.vscode/
10-
jsconfig.json
9+
.history/
1110

1211
# Xcode
1312
#
14-
build/
1513
*.pbxuser
1614
!default.pbxuser
1715
*.mode1v3
@@ -31,6 +29,9 @@ project.xcworkspace
3129

3230
# Android/IJ
3331
#
32+
/example/android/**/build/
33+
/android/**/build/
34+
/build
3435
.idea
3536
.gradle
3637
local.properties

.husky/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
22
. "$(dirname "$0")/_/husky.sh"
33

4-
yarn lint && yarn typescript
4+
yarn lint && yarn expo-module tsc --noEmit

.npmignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Exclude all top-level hidden directories by convention
2+
/.*/
3+
4+
__mocks__
5+
__tests__
6+
7+
/babel.config.js
8+
/android/src/androidTest/
9+
/android/src/test/
10+
11+
/example/
12+
/docs/
13+
/_assets/

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"cSpell.words": [
3+
"RNMSAL"
4+
]
5+
}

.yarnrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Override Yarn command so we can automatically setup the repo on running `yarn`
2+
3+
yarn-path "scripts/bootstrap.js"

CHANGELOG.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,37 @@
11
# CHANGELOG
22

3+
## 4.0.0-beta.6
4+
5+
### Breaking changes
6+
7+
- `acquireToken`, `acquireTokenSilent`, and `getAccount` may return `Promise<undefined>`. This matches what the underlying native libraries return.
8+
- The Android `msal_config.json` file that was previously required is no longer needed and is ignored. You can safely delete this file. All options are now configurable in the config object which is passed to the `PublicClientApplication` constructor
9+
- The `PublicClientApplication` constructor no longer takes a second `init` boolean argument, and initialization must be done manually by calling the `init` method:
10+
```diff
11+
-const pca = new PublicClientApplication(config, false)
12+
+const pca = new PublicClientApplication(config) // No longer initializes client. You must do this manually 👇
13+
try {
14+
await pca.init();
15+
} catch (error) {
16+
console.log("problem in configuration/setup:", error)
17+
}
18+
```
19+
- A new maven repository is required to be added to your project `build.gradle` (if you are using Expo this is done automatically for you):
20+
```gradle
21+
allProjects {
22+
repositories {
23+
// ...
24+
maven {
25+
url "https://pkgs.dev.azure.com/MicrosoftDeviceSDK/DuoSDK-Public/_packaging/Duo-SDK-Feed/maven/v1"
26+
}
27+
}
28+
}
29+
```
30+
31+
### Features
32+
33+
- Now supports Expo apps through a config plugin! To configure, please follow the [Expo setup guide](/docs/expo_setup.md)
34+
335
## [3.0.0](https://github.com/stashenergy/react-native-msal/compare/v2.0.3...v3.0.0)
436

537
### Breaking changes

README.md

Lines changed: 39 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
77

88
<p align="center">
9-
<img src="_assets/ReactNativeMSALLogo.png" width="300">
9+
<img src="_assets/ReactNativeMSALLogo.webp" width="300">
1010
</p>
1111

1212
## Live Demo (Web)
@@ -27,104 +27,78 @@
2727

2828
**Requires React Native >=0.61**
2929

30-
Stable version:
30+
Stable version:
3131
`$ yarn add react-native-msal`
3232

33-
Beta version:
33+
Beta version:
3434
`$ yarn add react-native-msal@beta`
3535

3636
Don't forget to run `npx pod-install` after!
3737

3838
## Setup
3939

40-
1. Register your application in the Azure Portal
41-
2. Follow the [Android Setup](/docs/android_setup.md) steps
42-
3. Follow the [iOS Setup](/docs/ios_setup.md) steps
40+
### Expo
4341

44-
## Use
42+
Follow the [Expo setup guide](/docs/expo_setup.md)
4543

46-
### `PublicClientApplication` class
44+
### Non-expo
4745

48-
This class is designed to be a thin wrapper around the native functionality of the Android and iOS MSAL libraries.
46+
Follow the [Android setup guide](/docs/android_setup.md) and the [iOS setup guide](/docs/ios_setup.md)
4947

50-
#### Creating an instance
48+
## Use
5149

5250
```typescript
53-
import PublicClientApplication, { MSALConfiguration } from 'react-native-msal';
51+
import PublicClientApplication from 'react-native-msal';
52+
import type { MSALConfiguration /*, etc */ } from 'react-native-msal';
5453

5554
const config: MSALConfiguration = {
5655
auth: {
5756
clientId: 'your-client-id',
58-
// authority: 'default-authority',
57+
// This authority is used as the default in `acquireToken` and `acquireTokenSilent` if not provided to those methods.
58+
// Defaults to 'https://login.microsoftonline.com/common'
59+
authority: 'https://<authority url>',
5960
},
6061
};
62+
const scopes = ['scope1', 'scope2'];
6163

62-
// Option 1: Constructor calls an asynchronous init method for you, but you won't know when it's done and can't catch errors
64+
// Initialize the public client application:
6365
const pca = new PublicClientApplication(config);
64-
65-
// Option 2 (RECOMMENDED): Skips init, so you can call it yourself and handle errors
66-
const pca = new PublicClientApplication(config, false);
6766
try {
6867
await pca.init();
6968
} catch (error) {
70-
console.error('Problem in configuration/setup:', error);
69+
console.error('Error initializing the pca, check your config.', error);
7170
}
72-
```
73-
74-
If you don't provide an authority, the common one will be used. This authority will be used as the default for calls to `acquireToken` and `acquireTokenSilent`.
75-
76-
#### Signing in interactively
7771

78-
```typescript
79-
const params: MSALInteractiveParams = {
80-
scopes: ['scope1', 'scope2'],
81-
};
82-
const result: MSALResult = await pca.acquireToken(params);
83-
```
72+
// Acquiring a token for the first time, you must call pca.acquireToken
73+
const params: MSALInteractiveParams = { scopes };
74+
const result: MSALResult | undefined = await pca.acquireToken(params);
8475

85-
You must use this method before any calls to `acquireTokenSilent`.
86-
Use the `accessToken` from the MSALResult to call your API.
87-
Store the `account` from the result for acquiring tokens silently or for removing the account.
88-
89-
#### Acquiring tokens silently
90-
91-
```typescript
76+
// On subsequent token acquisitions, you can call `pca.acquireTokenSilent`
77+
// Force the token to refresh with the `forceRefresh` option
9278
const params: MSALSilentParams = {
93-
scopes: ['scope1', 'scope2'],
94-
account: result.account,
95-
// forceRefresh: true,
79+
account: result!.account, // or get this by filtering the result from `pca.getAccounts` (see below)
80+
scopes,
81+
forceRefresh: true,
9682
};
97-
const result = await pca.acquireTokenSilent(params);
98-
```
99-
100-
You can force the token to refresh with the `forceRefresh` option
101-
102-
#### Listing all accounts for which the application has refresh tokens
83+
const result: MSALResult | undefined = await pca.acquireTokenSilent(params);
10384

104-
```typescript
85+
// Get all accounts for which this application has refresh tokens
10586
const accounts: MSALAccount[] = await pca.getAccounts();
106-
```
10787

108-
Instead of storing the `account` from a MSALResult for an `acquireTokenSilent` method call, you can filter the MSALAccount[] result for a particular account and use it.
88+
// Retrieve the account matching the identifier
89+
const account: MSALAccount | undefined = await pca.getAccount(result!.account.identifier);
10990

110-
#### Signing out
91+
// Remove all tokens from the cache for this application for the provided account
92+
const success: boolean = await pca.removeAccount(result!.account);
11193

112-
```typescript
113-
const res: boolean = await pca.removeAccount(result.account);
114-
```
115-
116-
Alternatively, you can call the `signOut` method:
117-
118-
```typescript
94+
// Same as `pca.removeAccount` with the exception that, if called on iOS with the `signoutFromBrowser` option set to true, it will additionally remove the account from the system browser
11995
const params: MSALSignoutParams = {
120-
account: result.account,
121-
// signoutFromBrowser: true
96+
account: result!.account,
97+
signoutFromBrowser: true,
12298
};
123-
const res: boolean = await pca.signOut(params);
99+
const success: boolean = await pca.signOut(params);
124100
```
125101

126-
On Android, this is the same as `removeAccount`, but on iOS, if you call it with `signoutFromBrowser: true`, it will sign you out of the browser as well.
127-
128102
### B2C Applications
129103

130104
The `PublicClientApplication` class is a bit too bare bones for dealing with a B2C application, and you will need to write a bit of code to get the desired behavior.
@@ -137,10 +111,10 @@ If you would like to see this class included in the library itself, please let u
137111

138112
As mentioned above, the example app demonstrates a B2C implementation
139113

140-
To run the example locally, first clone the repo and run `$ yarn bootstrap` to install the depedencies. Then run the following for the desired platform:
114+
To run the example locally, first clone the repo and run `$ yarn` to bootstrap the project. Then run the following for the desired platform:
141115

142-
iOS: `$ yarn example ios`
143-
Android: `$ yarn example android`
116+
iOS: `$ yarn example ios`
117+
Android: `$ yarn example android`
144118
Web: `$ yarn example web` (the example app is also running live [here](https://stashenergy.github.io/react-native-msal/))
145119

146120
If you want to run the example using your own Azure application information:
@@ -150,8 +124,7 @@ If you want to run the example using your own Azure application information:
150124
- iOS: `msauth.com.example://auth`
151125
- Web (SPA): `http://localhost:19006`
152126
1. Update the `b2cConfig` and `b2cScopes` variables in `msalConfig.ts` with your details.
153-
1. Update the `msal_config.json` Android asset file with your details.
154127

155-
## Migrating from v2 to v3
128+
## Migrating between major versions
156129

157-
See breaking changes in [CHANGELOG.md](CHANGELOG.md#300).
130+
See breaking changes in [CHANGELOG.md](CHANGELOG.md).

_assets/ReactNativeMSALLogo.png

-116 KB
Binary file not shown.

0 commit comments

Comments
 (0)