@asgardeo/auth-react 0.2.2 → 0.2.6

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.
@@ -15,14 +15,16 @@
15
15
  * specific language governing permissions and limitations
16
16
  * under the License.
17
17
  */
18
- import { AuthClientConfig } from "@asgardeo/auth-spa";
19
18
  import { FunctionComponent, PropsWithChildren, ReactNode } from "react";
19
+ import { AuthParams } from ".";
20
20
  import AuthAPI from "./api";
21
21
  import { AuthContextInterface, AuthReactConfig } from "./models";
22
22
  declare const AuthClient: AuthAPI;
23
23
  interface AuthProviderPropsInterface {
24
- config: AuthClientConfig<AuthReactConfig>;
24
+ config: AuthReactConfig;
25
25
  fallback?: ReactNode;
26
+ getAuthParams?: () => Promise<AuthParams>;
27
+ onSignOut?: () => void;
26
28
  }
27
29
  declare const AuthProvider: FunctionComponent<PropsWithChildren<AuthProviderPropsInterface>>;
28
30
  declare const useAuthContext: () => AuthContextInterface;
@@ -1 +1 @@
1
- {"version":3,"file":"authenticate.d.ts","sourceRoot":"","sources":["../../src/authenticate.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EACH,gBAAgB,EAQnB,MAAM,oBAAoB,CAAC;AAC5B,OAAc,EACV,iBAAiB,EACjB,iBAAiB,EAKjB,SAAS,EACZ,MAAM,OAAO,CAAC;AACf,OAAO,OAAO,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAsB,MAAM,UAAU,CAAC;AAErF,QAAA,MAAM,UAAU,SAAgB,CAAC;AAOjC,UAAU,0BAA0B;IAChC,MAAM,EAAE,gBAAgB,CAAC,eAAe,CAAC,CAAC;IAC1C,QAAQ,CAAC,EAAE,SAAS,CAAC;CACxB;AAED,QAAA,MAAM,YAAY,EAAE,iBAAiB,CAAC,iBAAiB,CAAC,0BAA0B,CAAC,CAqIlF,CAAC;AAEF,QAAA,MAAM,cAAc,QAAO,oBAE1B,CAAC;AAEF,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,cAAc,EAAE,CAAC"}
1
+ {"version":3,"file":"authenticate.d.ts","sourceRoot":"","sources":["../../src/authenticate.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAYH,OAAc,EACV,iBAAiB,EACjB,iBAAiB,EAMjB,SAAS,EACZ,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,CAAC;AAC/B,OAAO,OAAO,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAsB,MAAM,UAAU,CAAC;AASrF,QAAA,MAAM,UAAU,SAAgB,CAAC;AAOjC,UAAU,0BAA0B;IAChC,MAAM,EAAE,eAAe,CAAC;IACxB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;IAC1C,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;CAC1B;AAED,QAAA,MAAM,YAAY,EAAE,iBAAiB,CAAC,iBAAiB,CAAC,0BAA0B,CAAC,CAiKlF,CAAC;AAEF,QAAA,MAAM,cAAc,QAAO,oBAE1B,CAAC;AAEF,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,cAAc,EAAE,CAAC"}
@@ -16,14 +16,20 @@
16
16
  * under the License.
17
17
  */
18
18
  import { AuthClientConfig, BasicUserInfo, Config, CustomGrantConfig, DecodedIDTokenPayload, Hooks, HttpClientInstance, HttpRequestConfig, HttpResponse, OIDCEndpoints, SignInConfig, SPAConfig } from "@asgardeo/auth-spa";
19
- export interface AuthReactConfig extends SPAConfig {
19
+ export interface ReactConfig extends SPAConfig {
20
20
  /**
21
21
  * The SDK's `AuthProvider` by default is listening to the URL changes to see
22
22
  * if `code` & `session_state` search params are available so that it could perform
23
23
  * token exchange. This option could be used to override that behaviour.
24
24
  */
25
25
  skipRedirectCallback?: boolean;
26
+ /**
27
+ * The `AuthProvider`, by default, looks for an active session in the server and updates the session information
28
+ * with the latest session information from the server. This option could be used to disable that behaviour.
29
+ */
30
+ disableTrySignInSilently?: boolean;
26
31
  }
32
+ export declare type AuthReactConfig = AuthClientConfig<ReactConfig>;
27
33
  export interface AuthStateInterface {
28
34
  allowedScopes: string;
29
35
  displayName?: string;
@@ -63,4 +69,11 @@ export interface SecureRouteInterface {
63
69
  callback: () => void;
64
70
  component: any;
65
71
  }
72
+ /**
73
+ * The model of the object returned by the `getAuthParams` prop method of the `AuthProvider`.
74
+ */
75
+ export interface AuthParams {
76
+ authorizationCode?: string;
77
+ sessionState?: string;
78
+ }
66
79
  //# sourceMappingURL=models.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../src/models.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EACH,gBAAgB,EAChB,aAAa,EACb,MAAM,EACN,iBAAiB,EACjB,qBAAqB,EACrB,KAAK,EACL,kBAAkB,EAClB,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,SAAS,EACZ,MAAM,oBAAoB,CAAC;AAE5B,MAAM,WAAW,eAAgB,SAAQ,SAAS;IAC9C;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAClC;AAED,MAAM,WAAW,kBAAkB;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,OAAO,CAAC;IACzB;;OAEG;IACH,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,oBAAoB;IACjC,MAAM,EAAE,CACJ,MAAM,CAAC,EAAE,YAAY,EACrB,iBAAiB,CAAC,EAAE,MAAM,EAC1B,YAAY,CAAC,EAAE,MAAM,EACrB,QAAQ,CAAC,EA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G,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB"}
@@ -272,8 +272,8 @@
272
272
  "affectsGlobalScope": false
273
273
  },
274
274
  "../../node_modules/@asgardeo/auth-js/dist/src/authentication-client.d.ts": {
275
- "version": "227377e02e082a35ac126a233c838e50c7cc4e19e49370fd4bab58bf0ca82724",
276
- "signature": "227377e02e082a35ac126a233c838e50c7cc4e19e49370fd4bab58bf0ca82724",
275
+ "version": "0a33fe4f991e14cc2395c4a25192e6b1102ea330691a70ede2bc484a8275674a",
276
+ "signature": "0a33fe4f991e14cc2395c4a25192e6b1102ea330691a70ede2bc484a8275674a",
277
277
  "affectsGlobalScope": false
278
278
  },
279
279
  "../../node_modules/@asgardeo/auth-js/dist/src/public-api.d.ts": {
@@ -287,8 +287,8 @@
287
287
  "affectsGlobalScope": false
288
288
  },
289
289
  "../../node_modules/@asgardeo/auth-spa/dist/src/constants/messages-types.d.ts": {
290
- "version": "e5c33b8b7c301afa3154a57c29be6be9522d0c7ea8bdbb646dee8205ad77d1bd",
291
- "signature": "e5c33b8b7c301afa3154a57c29be6be9522d0c7ea8bdbb646dee8205ad77d1bd",
290
+ "version": "3843d8d46256ecb2b2142ad5a5527eda0140e89cf4c2b444d0b36d6fb0422280",
291
+ "signature": "3843d8d46256ecb2b2142ad5a5527eda0140e89cf4c2b444d0b36d6fb0422280",
292
292
  "affectsGlobalScope": false
293
293
  },
294
294
  "../../node_modules/@asgardeo/auth-spa/dist/src/constants/storage.d.ts": {
@@ -327,8 +327,8 @@
327
327
  "affectsGlobalScope": false
328
328
  },
329
329
  "../../node_modules/@asgardeo/auth-spa/dist/src/models/message.d.ts": {
330
- "version": "bc0e12b37c6c85a2426e1c9d6d05cda60fd4b0dca3b1c05c88d366380138a323",
331
- "signature": "bc0e12b37c6c85a2426e1c9d6d05cda60fd4b0dca3b1c05c88d366380138a323",
330
+ "version": "d79d31fdde47282b9db37abef02969057c5067b31cd39de18aed1bb84f60cc6d",
331
+ "signature": "d79d31fdde47282b9db37abef02969057c5067b31cd39de18aed1bb84f60cc6d",
332
332
  "affectsGlobalScope": false
333
333
  },
334
334
  "../../node_modules/@asgardeo/auth-spa/dist/src/models/http-client.d.ts": {
@@ -342,8 +342,8 @@
342
342
  "affectsGlobalScope": false
343
343
  },
344
344
  "../../node_modules/@asgardeo/auth-spa/dist/src/models/session-management-helper.d.ts": {
345
- "version": "72cce015ba668326f73049d22faa7fb8c28cc80e7c6f87ea1220d31f0dc1d5aa",
346
- "signature": "72cce015ba668326f73049d22faa7fb8c28cc80e7c6f87ea1220d31f0dc1d5aa",
345
+ "version": "f61a044988a189c1105be1ee9707a24980f55840c3c1c667196564b58df59894",
346
+ "signature": "f61a044988a189c1105be1ee9707a24980f55840c3c1c667196564b58df59894",
347
347
  "affectsGlobalScope": false
348
348
  },
349
349
  "../../node_modules/@asgardeo/auth-spa/dist/src/models/client-config.d.ts": {
@@ -407,8 +407,8 @@
407
407
  "affectsGlobalScope": false
408
408
  },
409
409
  "../src/models.ts": {
410
- "version": "d0d5bb13085a7ac5beaea6e726c1e351f7ef86d9c6fd16d0d2afd880a4e6c176",
411
- "signature": "523aeb42112ec318f70d078f2388ee6cc3f253decbf2df75fb1701b0f6cd300d",
410
+ "version": "1c9e0d3b0412540f0a91d6b1c18b01fbea6853767d94e73dba874810f0c4c0c4",
411
+ "signature": "31a1ae07a495fd07e1476be5e03a05cde390334f809a15db0565544ce9c9a349",
412
412
  "affectsGlobalScope": false
413
413
  },
414
414
  "../src/api.ts": {
@@ -441,16 +441,6 @@
441
441
  "signature": "ef92cfb8590d2d68d539312d111098fffa651ca129e2fbf917d62ffa35b88f34",
442
442
  "affectsGlobalScope": true
443
443
  },
444
- "../src/authenticate.tsx": {
445
- "version": "f205a1ccc04834f72d597d5e7b6712e8e8ebadf25d13ecef5de94b305194a4ca",
446
- "signature": "ce04cc38344b9d1d8b78eec2e642a7125b02204459ecc7372b6aa72d883eddcf",
447
- "affectsGlobalScope": false
448
- },
449
- "../src/authenticated-component.tsx": {
450
- "version": "ad17d183847f830cd30dea3894719ce0dd906f4cced82f30f9fe1673183582e5",
451
- "signature": "dbb05d7576d05619ccb20b22f5324ad6439a4b6f68e7418e7aba72fb282ef9a1",
452
- "affectsGlobalScope": false
453
- },
454
444
  "../../node_modules/@types/react-router/node_modules/@types/react/global.d.ts": {
455
445
  "version": "ecf78e637f710f340ec08d5d92b3f31b134a46a4fcf2e758690d8c46ce62cba6",
456
446
  "signature": "ecf78e637f710f340ec08d5d92b3f31b134a46a4fcf2e758690d8c46ce62cba6",
@@ -516,6 +506,11 @@
516
506
  "signature": "a7444f6cda6b9d661a122ba8530dc1941173ae0ab22e75d7adca56b6b99bd40c",
517
507
  "affectsGlobalScope": false
518
508
  },
509
+ "../src/authenticated-component.tsx": {
510
+ "version": "ad17d183847f830cd30dea3894719ce0dd906f4cced82f30f9fe1673183582e5",
511
+ "signature": "dbb05d7576d05619ccb20b22f5324ad6439a4b6f68e7418e7aba72fb282ef9a1",
512
+ "affectsGlobalScope": false
513
+ },
519
514
  "../src/secure-app.tsx": {
520
515
  "version": "4173bf21c8d1ff2f10153d792a855d9c1461f776303979363174dc282e05c303",
521
516
  "signature": "4e2751af90e9060f90c7b42823979b2a864e27e288ded76312d3b20e10afabaa",
@@ -531,6 +526,11 @@
531
526
  "signature": "6d7600bbc5b99e10ef306eb23ee39102865d99e91863458d0a49bc6edeb6cf54",
532
527
  "affectsGlobalScope": false
533
528
  },
529
+ "../src/authenticate.tsx": {
530
+ "version": "2bc22e229d648167ed022fb73477762608a1d502c97e90308066dd3b7e0632aa",
531
+ "signature": "336cb282ec49398aece02113130600346cc39c172377aad24e5cb639ce3d226b",
532
+ "affectsGlobalScope": false
533
+ },
534
534
  "../src/reducer.ts": {
535
535
  "version": "9a02a9f8c10f680e76d26d7f857dd4a54c6ee89fe461bad1367bbd95627c0666",
536
536
  "signature": "8ad53cc4bf5cc967c8947af4f113a3ed943d9b26002a36fbaa062341233d8e17",
@@ -1100,6 +1100,7 @@
1100
1100
  "../../node_modules/@asgardeo/auth-spa/dist/src/index.d.ts",
1101
1101
  "../../node_modules/@types/react/index.d.ts",
1102
1102
  "../src/api.ts",
1103
+ "../src/index.ts",
1103
1104
  "../src/models.ts"
1104
1105
  ],
1105
1106
  "../src/authenticated-component.tsx": [
@@ -1578,9 +1579,9 @@
1578
1579
  "../src/models.ts"
1579
1580
  ],
1580
1581
  "../src/authenticate.tsx": [
1581
- "../../node_modules/@asgardeo/auth-spa/dist/src/index.d.ts",
1582
1582
  "../../node_modules/@types/react/index.d.ts",
1583
1583
  "../src/api.ts",
1584
+ "../src/index.ts",
1584
1585
  "../src/models.ts"
1585
1586
  ],
1586
1587
  "../src/authenticated-component.tsx": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asgardeo/auth-react",
3
- "version": "0.2.2",
3
+ "version": "0.2.6",
4
4
  "description": "Asgardeo Auth React SDK for React Applications.",
5
5
  "keywords": [
6
6
  "WSO2",
@@ -35,7 +35,7 @@
35
35
  "author": "WSO2",
36
36
  "license": "Apache-2.0",
37
37
  "dependencies": {
38
- "@asgardeo/auth-spa": "^0.2.3"
38
+ "@asgardeo/auth-spa": "^0.2.8"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@babel/cli": "^7.10.5",
@@ -68,8 +68,8 @@
68
68
  },
69
69
  "peerDependencies": {
70
70
  "@babel/runtime-corejs3": "^7.11.2",
71
- "react": "^16.14.0",
72
- "react-dom": "16.14.0",
71
+ "react": ">=16.8",
72
+ "react-dom": ">=16.8",
73
73
  "react-router-dom": "^5.2.0"
74
74
  }
75
75
  }
@@ -32,12 +32,21 @@ import React, {
32
32
  createContext,
33
33
  useContext,
34
34
  useEffect,
35
+ useMemo,
35
36
  useState,
36
37
  ReactNode
37
38
  } from "react";
39
+ import { AuthParams } from ".";
38
40
  import AuthAPI from "./api";
39
41
  import { AuthContextInterface, AuthReactConfig, AuthStateInterface } from "./models";
40
42
 
43
+ /**
44
+ * Default `AuthClientConfig<AuthReactConfig>` config.
45
+ */
46
+ const defaultConfig: Partial<AuthClientConfig<AuthReactConfig>> = {
47
+ disableTrySignInSilently: false
48
+ };
49
+
41
50
  const AuthClient = new AuthAPI();
42
51
 
43
52
  /**
@@ -46,8 +55,10 @@ const AuthClient = new AuthAPI();
46
55
  const AuthContext = createContext<AuthContextInterface>(null);
47
56
 
48
57
  interface AuthProviderPropsInterface {
49
- config: AuthClientConfig<AuthReactConfig>;
58
+ config: AuthReactConfig;
50
59
  fallback?: ReactNode;
60
+ getAuthParams?: () => Promise<AuthParams>;
61
+ onSignOut?: () => void;
51
62
  }
52
63
 
53
64
  const AuthProvider: FunctionComponent<PropsWithChildren<AuthProviderPropsInterface>> = (
@@ -56,7 +67,11 @@ const AuthProvider: FunctionComponent<PropsWithChildren<AuthProviderPropsInterfa
56
67
  const [ state, dispatch ] = useState<AuthStateInterface>(AuthClient.getState());
57
68
  const [ initialized, setInitialized ] = useState(false);
58
69
 
59
- const { children, config, fallback } = props;
70
+ const { children, config: passedConfig, fallback, getAuthParams, onSignOut } = props;
71
+
72
+ const config = useMemo(
73
+ (): AuthReactConfig => ({ ...defaultConfig, ...passedConfig }), [ passedConfig ]
74
+ );
60
75
 
61
76
  const signIn = async(
62
77
  config?: SignInConfig,
@@ -110,32 +125,56 @@ const AuthProvider: FunctionComponent<PropsWithChildren<AuthProviderPropsInterfa
110
125
  * Try signing in when the component is mounted.
111
126
  */
112
127
  useEffect(() => {
128
+ (async () => {
129
+ let isSignedOut: boolean = false;
130
+ await on(Hooks.SignOut, () => {
131
+ isSignedOut = true;
113
132
 
114
- // User is already authenticated. Skip...
115
- if (state.isAuthenticated) {
116
- return;
117
- }
133
+ if (onSignOut) {
134
+ onSignOut();
135
+ }
136
+ });
137
+
138
+ // User is already authenticated. Skip...
139
+ if (state.isAuthenticated) {
140
+ return;
141
+ }
118
142
 
119
- (async () => {
120
143
  // If `skipRedirectCallback` is not true, check if the URL has `code` and `session_state` params.
121
144
  // If so, initiate the sign in.
122
145
  if (!config.skipRedirectCallback) {
123
- await signIn({ callOnlyOnRedirect: true })
124
- .then(() => {
125
- // TODO: Add logs when a logger is available.
126
- // Tracked here https://github.com/asgardeo/asgardeo-auth-js-sdk/issues/151.
127
- })
128
- .catch((error) => {
129
- // TODO: Add logs when a logger is available.
130
- // Tracked here https://github.com/asgardeo/asgardeo-auth-js-sdk/issues/151.
131
- throw error;
132
- });
146
+ let authParams: AuthParams = null;
147
+ if (getAuthParams && typeof getAuthParams === "function") {
148
+ authParams = await getAuthParams();
149
+ }
150
+
151
+ if (SPAUtils.hasAuthSearchParamsInURL()
152
+ || authParams?.authorizationCode
153
+ || new URL(location.href).searchParams.get("error") )
154
+ {
155
+ await signIn({ callOnlyOnRedirect: true }, authParams?.authorizationCode, authParams?.sessionState)
156
+ .then(() => {
157
+ // TODO: Add logs when a logger is available.
158
+ // Tracked here https://github.com/asgardeo/asgardeo-auth-js-sdk/issues/151.
159
+ })
160
+ .catch((error) => {
161
+ // TODO: Add logs when a logger is available.
162
+ // Tracked here https://github.com/asgardeo/asgardeo-auth-js-sdk/issues/151.
163
+ throw error;
164
+ });
165
+ }
133
166
  }
134
167
 
135
168
  if (AuthClient.getState().isAuthenticated) {
136
169
  return;
137
170
  }
138
171
 
172
+ if (config.disableTrySignInSilently || isSignedOut) {
173
+ dispatch({ ...state, isLoading: false });
174
+
175
+ return;
176
+ }
177
+
139
178
  // This uses the RP iframe to get the session. Hence, will not work if 3rd party cookies are disabled.
140
179
  // If the browser has these cookies disabled, we'll not be able to retrieve the session on refreshes.
141
180
  await trySignInSilently()
@@ -150,7 +189,7 @@ const AuthProvider: FunctionComponent<PropsWithChildren<AuthProviderPropsInterfa
150
189
  });
151
190
  })();
152
191
 
153
- }, []);
192
+ }, [ config ]);
154
193
 
155
194
  /**
156
195
  * Render state and special case actions
package/src/models.ts CHANGED
@@ -31,15 +31,21 @@ import {
31
31
  SPAConfig
32
32
  } from "@asgardeo/auth-spa";
33
33
 
34
- export interface AuthReactConfig extends SPAConfig {
34
+ export interface ReactConfig extends SPAConfig {
35
35
  /**
36
36
  * The SDK's `AuthProvider` by default is listening to the URL changes to see
37
37
  * if `code` & `session_state` search params are available so that it could perform
38
38
  * token exchange. This option could be used to override that behaviour.
39
39
  */
40
40
  skipRedirectCallback?: boolean;
41
+ /**
42
+ * The `AuthProvider`, by default, looks for an active session in the server and updates the session information
43
+ * with the latest session information from the server. This option could be used to disable that behaviour.
44
+ */
45
+ disableTrySignInSilently?: boolean;
41
46
  }
42
47
 
48
+ export type AuthReactConfig = AuthClientConfig<ReactConfig>;
43
49
  export interface AuthStateInterface {
44
50
  allowedScopes: string;
45
51
  displayName?: string;
@@ -100,3 +106,11 @@ export interface SecureRouteInterface {
100
106
  callback: () => void;
101
107
  component: any;
102
108
  }
109
+
110
+ /**
111
+ * The model of the object returned by the `getAuthParams` prop method of the `AuthProvider`.
112
+ */
113
+ export interface AuthParams {
114
+ authorizationCode?: string;
115
+ sessionState?: string;
116
+ }