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.
Files changed (2) hide show
  1. package/README.md +57 -10
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,6 +1,12 @@
1
1
  # react-native-msal2
2
2
 
3
- A plugin for React Native.
3
+
4
+ [![npm latest version](https://img.shields.io/npm/v/react-native-msal/latest.svg)](https://www.npmjs.com/package/react-native-msal)
5
+ [![npm beta version](https://img.shields.io/npm/v/react-native-msal/beta.svg)](https://www.npmjs.com/package/react-native-msal)
6
+ ![ci status](https://github.com/stashenergy/react-native-msal/workflows/CI/badge.svg)
7
+ [![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)
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
- ```jsx
14
- import React from 'react'
15
- import { Text } from 'react-native'
16
- import { Msal2 } from 'react-native-msal2'
17
-
18
- export () =>
19
- <Msal2>
20
- <Text>Hello Plugin</Text>
21
- </Msal2>
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-msal2",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "license": "MIT",
5
5
  "description": "MSAL React Native wrapper for iOS and Android",
6
6
  "homepage": "https://github.com/bittu/react-native-msal2#readme",