react-native-msal2 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
# react-native-msal2
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
[](https://www.npmjs.com/package/react-native-msal)
|
|
5
|
+
[](https://www.npmjs.com/package/react-native-msal)
|
|
6
|
+

|
|
7
|
+
[](https://github.com/semantic-release/semantic-release)
|
|
8
|
+
|
|
9
|
+
MSAL React Native wrapper for iOS and Android
|
|
4
10
|
|
|
5
11
|
## Installation
|
|
6
12
|
|
|
@@ -10,15 +16,56 @@ npm i react-native-msal2
|
|
|
10
16
|
|
|
11
17
|
## Usage
|
|
12
18
|
|
|
13
|
-
```
|
|
14
|
-
import
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
```typescript
|
|
20
|
+
import PublicClientApplication from 'react-native-msal';
|
|
21
|
+
import type { MSALConfiguration /*, etc */ } from 'react-native-msal';
|
|
22
|
+
|
|
23
|
+
const config: MSALConfiguration = {
|
|
24
|
+
auth: {
|
|
25
|
+
clientId: 'your-client-id',
|
|
26
|
+
// This authority is used as the default in `acquireToken` and `acquireTokenSilent` if not provided to those methods.
|
|
27
|
+
// Defaults to 'https://login.microsoftonline.com/common'
|
|
28
|
+
authority: 'https://<authority url>',
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
const scopes = ['scope1', 'scope2'];
|
|
32
|
+
|
|
33
|
+
// Initialize the public client application:
|
|
34
|
+
const pca = new PublicClientApplication(config);
|
|
35
|
+
try {
|
|
36
|
+
await pca.init();
|
|
37
|
+
} catch (error) {
|
|
38
|
+
console.error('Error initializing the pca, check your config.', error);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Acquiring a token for the first time, you must call pca.acquireToken
|
|
42
|
+
const params: MSALInteractiveParams = { scopes };
|
|
43
|
+
const result: MSALResult | undefined = await pca.acquireToken(params);
|
|
44
|
+
|
|
45
|
+
// On subsequent token acquisitions, you can call `pca.acquireTokenSilent`
|
|
46
|
+
// Force the token to refresh with the `forceRefresh` option
|
|
47
|
+
const params: MSALSilentParams = {
|
|
48
|
+
account: result!.account, // or get this by filtering the result from `pca.getAccounts` (see below)
|
|
49
|
+
scopes,
|
|
50
|
+
forceRefresh: true,
|
|
51
|
+
};
|
|
52
|
+
const result: MSALResult | undefined = await pca.acquireTokenSilent(params);
|
|
53
|
+
|
|
54
|
+
// Get all accounts for which this application has refresh tokens
|
|
55
|
+
const accounts: MSALAccount[] = await pca.getAccounts();
|
|
56
|
+
|
|
57
|
+
// Retrieve the account matching the identifier
|
|
58
|
+
const account: MSALAccount | undefined = await pca.getAccount(result!.account.identifier);
|
|
59
|
+
|
|
60
|
+
// Remove all tokens from the cache for this application for the provided account
|
|
61
|
+
const success: boolean = await pca.removeAccount(result!.account);
|
|
62
|
+
|
|
63
|
+
// 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
|
|
64
|
+
const params: MSALSignoutParams = {
|
|
65
|
+
account: result!.account,
|
|
66
|
+
signoutFromBrowser: true,
|
|
67
|
+
};
|
|
68
|
+
const success: boolean = await pca.signOut(params);
|
|
22
69
|
```
|
|
23
70
|
|
|
24
71
|
## Development
|