@multiplatform.one/keycloak 1.0.13 → 1.0.15
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/dist/cjs/Authenticated.js +3 -5
- package/dist/cjs/Authenticated.js.map +1 -1
- package/dist/cjs/Authenticated.native.js +7 -9
- package/dist/cjs/Authenticated.native.js.map +2 -2
- package/dist/cjs/authConfig.native.js.map +1 -1
- package/dist/cjs/hooks/index.native.js.map +1 -1
- package/dist/cjs/hooks/useAuthConfig.native.js.map +1 -1
- package/dist/cjs/hooks/useTokensFromQuery/index.js +1 -2
- package/dist/cjs/hooks/useTokensFromQuery/index.js.map +1 -1
- package/dist/cjs/hooks/useTokensFromQuery/index.native.js.map +1 -1
- package/dist/cjs/hooks/useTokensFromState.native.js.map +1 -1
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/keycloak/config.native.js.map +1 -1
- package/dist/cjs/keycloak/context.native.js.map +1 -1
- package/dist/cjs/keycloak/index.native.js.map +1 -1
- package/dist/cjs/keycloak/keycloak.js +4 -19
- package/dist/cjs/keycloak/keycloak.js.map +1 -1
- package/dist/cjs/keycloak/keycloak.native.js +59 -61
- package/dist/cjs/keycloak/keycloak.native.js.map +2 -2
- package/dist/cjs/provider/AfterAuth.native.js.map +1 -1
- package/dist/cjs/provider/AuthProvider/AuthProvider.js +10 -10
- package/dist/cjs/provider/AuthProvider/AuthProvider.js.map +1 -1
- package/dist/cjs/provider/AuthProvider/AuthProvider.native.js +61 -74
- package/dist/cjs/provider/AuthProvider/AuthProvider.native.js.map +2 -2
- package/dist/cjs/provider/AuthProvider/index.native.js.map +1 -1
- package/dist/cjs/provider/KeycloakProvider.native.js.map +1 -1
- package/dist/cjs/provider/index.native.js.map +1 -1
- package/dist/cjs/routes.js +4 -6
- package/dist/cjs/routes.js.map +1 -1
- package/dist/cjs/routes.native.js +71 -81
- package/dist/cjs/routes.native.js.map +3 -3
- package/dist/cjs/session/index.native.js.map +1 -1
- package/dist/cjs/session/session.js +3 -22
- package/dist/cjs/session/session.js.map +2 -2
- package/dist/cjs/session/session.native.js +53 -58
- package/dist/cjs/session/session.native.js.map +2 -2
- package/dist/cjs/state.native.js.map +1 -1
- package/dist/cjs/token.native.js.map +1 -1
- package/dist/cjs/types.native.js.map +1 -1
- package/dist/esm/Authenticated.js +3 -5
- package/dist/esm/Authenticated.js.map +1 -1
- package/dist/esm/Authenticated.mjs +1 -1
- package/dist/esm/Authenticated.native.js +7 -9
- package/dist/esm/Authenticated.native.js.map +3 -3
- package/dist/esm/authConfig.native.js.map +1 -1
- package/dist/esm/hooks/index.native.js.map +1 -1
- package/dist/esm/hooks/useAuthConfig.native.js.map +1 -1
- package/dist/esm/hooks/useTokensFromQuery/index.js +1 -2
- package/dist/esm/hooks/useTokensFromQuery/index.js.map +1 -1
- package/dist/esm/hooks/useTokensFromQuery/index.native.js.map +1 -1
- package/dist/esm/hooks/useTokensFromState.native.js.map +1 -1
- package/dist/esm/index.native.js.map +1 -1
- package/dist/esm/keycloak/config.native.js.map +1 -1
- package/dist/esm/keycloak/context.native.js.map +1 -1
- package/dist/esm/keycloak/index.native.js.map +1 -1
- package/dist/esm/keycloak/keycloak.js +5 -20
- package/dist/esm/keycloak/keycloak.js.map +1 -1
- package/dist/esm/keycloak/keycloak.mjs +2 -13
- package/dist/esm/keycloak/keycloak.native.js +59 -61
- package/dist/esm/keycloak/keycloak.native.js.map +2 -2
- package/dist/esm/provider/AfterAuth.native.js.map +1 -1
- package/dist/esm/provider/AuthProvider/AuthProvider.js +10 -10
- package/dist/esm/provider/AuthProvider/AuthProvider.js.map +1 -1
- package/dist/esm/provider/AuthProvider/AuthProvider.mjs +9 -5
- package/dist/esm/provider/AuthProvider/AuthProvider.native.js +61 -74
- package/dist/esm/provider/AuthProvider/AuthProvider.native.js.map +2 -2
- package/dist/esm/provider/AuthProvider/index.native.js.map +1 -1
- package/dist/esm/provider/KeycloakProvider.native.js.map +1 -1
- package/dist/esm/provider/index.native.js.map +1 -1
- package/dist/esm/routes.js +4 -6
- package/dist/esm/routes.js.map +1 -1
- package/dist/esm/routes.mjs +2 -2
- package/dist/esm/routes.native.js +71 -81
- package/dist/esm/routes.native.js.map +3 -3
- package/dist/esm/session/index.native.js.map +1 -1
- package/dist/esm/session/session.js +2 -13
- package/dist/esm/session/session.js.map +2 -2
- package/dist/esm/session/session.mjs +3 -12
- package/dist/esm/session/session.native.js +53 -58
- package/dist/esm/session/session.native.js.map +2 -2
- package/dist/esm/state.native.js.map +1 -1
- package/dist/esm/token.native.js.map +1 -1
- package/dist/jsx/Authenticated.js +3 -5
- package/dist/jsx/Authenticated.js.map +1 -1
- package/dist/jsx/Authenticated.mjs +1 -1
- package/dist/jsx/Authenticated.native.js +7 -9
- package/dist/jsx/Authenticated.native.js.map +3 -3
- package/dist/jsx/authConfig.native.js.map +1 -1
- package/dist/jsx/hooks/index.native.js.map +1 -1
- package/dist/jsx/hooks/useAuthConfig.native.js.map +1 -1
- package/dist/jsx/hooks/useTokensFromQuery/index.js +1 -2
- package/dist/jsx/hooks/useTokensFromQuery/index.js.map +1 -1
- package/dist/jsx/hooks/useTokensFromQuery/index.native.js.map +1 -1
- package/dist/jsx/hooks/useTokensFromState.native.js.map +1 -1
- package/dist/jsx/index.native.js.map +1 -1
- package/dist/jsx/keycloak/config.native.js.map +1 -1
- package/dist/jsx/keycloak/context.native.js.map +1 -1
- package/dist/jsx/keycloak/index.native.js.map +1 -1
- package/dist/jsx/keycloak/keycloak.js +5 -20
- package/dist/jsx/keycloak/keycloak.js.map +1 -1
- package/dist/jsx/keycloak/keycloak.mjs +2 -13
- package/dist/jsx/keycloak/keycloak.native.js +59 -61
- package/dist/jsx/keycloak/keycloak.native.js.map +2 -2
- package/dist/jsx/provider/AfterAuth.native.js.map +1 -1
- package/dist/jsx/provider/AuthProvider/AuthProvider.js +10 -10
- package/dist/jsx/provider/AuthProvider/AuthProvider.js.map +1 -1
- package/dist/jsx/provider/AuthProvider/AuthProvider.mjs +9 -5
- package/dist/jsx/provider/AuthProvider/AuthProvider.native.js +61 -74
- package/dist/jsx/provider/AuthProvider/AuthProvider.native.js.map +2 -2
- package/dist/jsx/provider/AuthProvider/index.native.js.map +1 -1
- package/dist/jsx/provider/KeycloakProvider.native.js.map +1 -1
- package/dist/jsx/provider/index.native.js.map +1 -1
- package/dist/jsx/routes.js +4 -6
- package/dist/jsx/routes.js.map +1 -1
- package/dist/jsx/routes.mjs +2 -2
- package/dist/jsx/routes.native.js +71 -81
- package/dist/jsx/routes.native.js.map +3 -3
- package/dist/jsx/session/index.native.js.map +1 -1
- package/dist/jsx/session/session.js +2 -13
- package/dist/jsx/session/session.js.map +2 -2
- package/dist/jsx/session/session.mjs +3 -12
- package/dist/jsx/session/session.native.js +53 -58
- package/dist/jsx/session/session.native.js.map +2 -2
- package/dist/jsx/state.native.js.map +1 -1
- package/dist/jsx/token.native.js.map +1 -1
- package/package.json +11 -13
- package/routes/index.d.ts +15 -15
- package/routes/index.js +15 -15
- package/src/@types/expoKeycloakAuth.d.ts +16 -16
- package/src/Authenticated.tsx +1 -2
- package/src/authConfig.ts +15 -15
- package/src/hooks/index.ts +15 -15
- package/src/hooks/useAuthConfig.ts +15 -15
- package/src/hooks/useTokensFromQuery/index.native.ts +15 -15
- package/src/hooks/useTokensFromQuery/index.ts +15 -15
- package/src/hooks/useTokensFromState.ts +15 -15
- package/src/index.ts +15 -15
- package/src/keycloak/config.ts +15 -15
- package/src/keycloak/context.ts +15 -15
- package/src/keycloak/index.ts +15 -15
- package/src/keycloak/keycloak.native.ts +15 -15
- package/src/keycloak/keycloak.ts +16 -36
- package/src/provider/AuthProvider/AuthProvider.tsx +7 -4
- package/src/provider/AuthProvider/index.ts +15 -15
- package/src/provider/index.ts +15 -15
- package/src/routes.ts +18 -21
- package/src/session/index.ts +15 -15
- package/src/session/session.native.ts +15 -15
- package/src/session/session.ts +18 -32
- package/src/state.ts +15 -15
- package/src/token.ts +15 -15
- package/src/types.ts +15 -15
- package/types/Authenticated.d.ts.map +1 -1
- package/types/keycloak/keycloak.d.ts +0 -2
- package/types/keycloak/keycloak.d.ts.map +1 -1
- package/types/provider/AuthProvider/AuthProvider.d.ts.map +1 -1
- package/types/routes.d.ts.map +1 -1
- package/types/session/session.d.ts +1 -2
- package/types/session/session.d.ts.map +1 -1
- package/dist/esm/hooks/useTokensFromQuery/index.native.mjs +0 -2
- package/dist/esm/keycloak/keycloak.native.mjs +0 -84
- package/dist/esm/provider/AuthProvider/AuthProvider.native.mjs +0 -111
- package/dist/esm/session/session.native.mjs +0 -7
- package/dist/jsx/hooks/useTokensFromQuery/index.native.mjs +0 -2
- package/dist/jsx/keycloak/keycloak.native.mjs +0 -84
- package/dist/jsx/provider/AuthProvider/AuthProvider.native.mjs +0 -111
- package/dist/jsx/session/session.native.mjs +0 -7
package/src/types.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
/*
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
2
|
+
* File: /src/types.ts
|
|
3
|
+
* Project: @multiplatform.one/keycloak
|
|
4
|
+
* File Created: 04-04-2024 15:50:39
|
|
5
|
+
* Author: Clay Risser
|
|
6
|
+
* -----
|
|
7
|
+
* BitSpur (c) Copyright 2021 - 2024
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
+
* you may not use this file except in compliance with the License.
|
|
11
|
+
* You may obtain a copy of the License at
|
|
12
12
|
*
|
|
13
|
-
*
|
|
13
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
15
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
16
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
+
* See the License for the specific language governing permissions and
|
|
19
|
+
* limitations under the License.
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
declare global {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Authenticated.d.ts","sourceRoot":"","sources":["../src/Authenticated.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Authenticated.d.ts","sourceRoot":"","sources":["../src/Authenticated.tsx"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,iBAAiB,EAAa,MAAM,OAAO,CAAC;AAQ3E,MAAM,WAAW,kBAAmB,SAAQ,iBAAiB;IAC3D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,gBAAgB,CAAC,EAAE,aAAa,CAAC;IACjC,kBAAkB,CAAC,EAAE,aAAa,CAAC;CACpC;AAED,wBAAgB,aAAa,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,EAAE,kBAAkB,qBAuB7G;AAED,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC,WAC9D,CAAC,uBAKjB"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type KeycloakClient from 'keycloak-js';
|
|
2
2
|
import type { AccessTokenParsed, TokenParsed } from '../token';
|
|
3
|
-
import type { AuthOptions } from 'next-auth';
|
|
4
3
|
import type { AuthRequestPromptOptions } from 'expo-auth-session';
|
|
5
4
|
import type { KeycloakMock } from '../types';
|
|
6
5
|
import type { Session } from '../session/session';
|
|
@@ -40,5 +39,4 @@ export declare class Keycloak {
|
|
|
40
39
|
get authenticated(): boolean;
|
|
41
40
|
}
|
|
42
41
|
export declare function useKeycloak(): Keycloak | null | undefined;
|
|
43
|
-
export declare function getKeycloak(options?: AuthOptions, req?: any, res?: any): Promise<Keycloak>;
|
|
44
42
|
//# sourceMappingURL=keycloak.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keycloak.d.ts","sourceRoot":"","sources":["../../src/keycloak/keycloak.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,cAAc,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC/D,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"keycloak.d.ts","sourceRoot":"","sources":["../../src/keycloak/keycloak.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,cAAc,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC/D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAyB,KAAK,cAAc,EAAE,MAAM,UAAU,CAAC;AAQtE,OAAO,KAAK,EACV,oBAAoB,IAAI,sBAAsB,EAC9C,qBAAqB,IAAI,uBAAuB,EACjD,MAAM,aAAa,CAAC;AAErB,MAAM,MAAM,oBAAoB,GAAG,sBAAsB,GAAG,wBAAwB,GAAG;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAC9G,MAAM,MAAM,qBAAqB,GAAG,uBAAuB,CAAC;AAE5D,qBAAa,QAAQ;aAcD,MAAM,EAAE,cAAc;IAbxC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,OAAO,CAAC,cAAc,CAAC,CAAc;IACrC,OAAO,CAAC,MAAM,CAAC,CAAyD;IACxE,OAAO,CAAC,OAAO,CAAC,CAA0D;IAC1E,OAAO,CAAC,mBAAmB,CAAC,CAAc;IAC1C,OAAO,CAAC,YAAY,CAAC,CAAoB;IACzC,OAAO,CAAC,cAAc,CAAC,CAAiB;IACxC,OAAO,CAAC,IAAI,CAA2B;gBAGrB,MAAM,EAAE,cAAc,EACtC,KAAK,CAAC,EAAE,MAAM,GAAG,cAAc,GAAG,YAAY,GAAG,OAAO,EACxD,OAAO,CAAC,EAAE,MAAM,EAChB,YAAY,CAAC,EAAE,MAAM,EACrB,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,oBAAoB,KAAK,OAAO,CAAC,SAAS,CAAC,EAC9D,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,qBAAqB,KAAK,OAAO,CAAC,SAAS,CAAC;IA2BlE,IAAI,WAAW,kCAGd;IAED,IAAI,aAAa,4BAGhB;IAED,IAAI,kBAAkB,4BAGrB;IAED,IAAI,QAAQ,uBAGX;IAED,IAAI,KAAK,QAIR;IAED,IAAI,KAAK,uBAGR;IAED,IAAI,WAAW,oDAGd;IAED,IAAI,cAAc,6DAGjB;IAED,IAAI,SAAS,uBAGZ;IAED,IAAI,OAAO,uBAGV;IAED,IAAI,QAAQ,uBAGX;IAEK,WAAW;IAYX,KAAK,CAAC,OAAO,GAAE,oBAAyB;IAgBxC,MAAM,CAAC,OAAO,GAAE,qBAA0B;IAgBhD,IAAI,aAAa,YAKhB;CACF;AAED,wBAAgB,WAAW,gCAiB1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthProvider.d.ts","sourceRoot":"","sources":["../../../src/provider/AuthProvider/AuthProvider.tsx"],"names":[],"mappings":"AAwBA,OAAO,KAAuC,MAAM,OAAO,CAAC;AAC5D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAW5D,MAAM,WAAW,iBAAkB,SAAQ,iBAAiB;IAC1D,cAAc,EAAE,cAAc,CAAC;IAC/B,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IAC1C,eAAe,CAAC,EAAE,IAAI,CAAC,oBAAoB,EAAE,UAAU,CAAC,CAAC;CAC1D;AAID,MAAM,WAAW,MAAM,CAAC,CAAC,GAAG,OAAO;IACjC,OAAO,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC;CACpB;AAED,wBAAgB,YAAY,CAAC,EAAE,QAAQ,EAAE,eAAe,EAAE,mBAAmB,EAAE,cAAc,EAAE,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"AuthProvider.d.ts","sourceRoot":"","sources":["../../../src/provider/AuthProvider/AuthProvider.tsx"],"names":[],"mappings":"AAwBA,OAAO,KAAuC,MAAM,OAAO,CAAC;AAC5D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAW5D,MAAM,WAAW,iBAAkB,SAAQ,iBAAiB;IAC1D,cAAc,EAAE,cAAc,CAAC;IAC/B,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IAC1C,eAAe,CAAC,EAAE,IAAI,CAAC,oBAAoB,EAAE,UAAU,CAAC,CAAC;CAC1D;AAID,MAAM,WAAW,MAAM,CAAC,CAAC,GAAG,OAAO;IACjC,OAAO,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC;CACpB;AAED,wBAAgB,YAAY,CAAC,EAAE,QAAQ,EAAE,eAAe,EAAE,mBAAmB,EAAE,cAAc,EAAE,EAAE,iBAAiB,qBAiOjH;AAUD,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB"}
|
package/types/routes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAoB,MAAM,WAAW,CAAC;AAC/D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAoB,MAAM,WAAW,CAAC;AAC/D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAY3D,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,OAE5D;AASD,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,kBAAkB;;EAsB9D;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,kBAAkB,eAsEhE;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,eAAe,CAAC;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IAChC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,eAAgB,SAAQ,eAAe,CAAC,GAAG,CAAC;IAC3D,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,SAAU,SAAQ,GAAG;IACpC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,iBAAiB,CAAC;IAC3B,GAAG,CAAC,EAAE,KAAK,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Session as NextSession } from 'next-auth';
|
|
2
2
|
import type { SessionContextValue as NextSessionContextValue, UseSessionOptions } from 'next-auth/react';
|
|
3
|
-
export declare function getSession(options?: AuthOptions, req?: any, res?: any): Promise<Session | null>;
|
|
4
3
|
export type SessionContextValue<R extends boolean> = Partial<Omit<NextSessionContextValue<R> & {
|
|
5
4
|
session: Session;
|
|
6
5
|
}, 'data'>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/session/session.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/session/session.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,WAAW,CAAC;AACxD,OAAO,KAAK,EAAE,mBAAmB,IAAI,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAIzG,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,OAAO,IAAI,OAAO,CAC1D,IAAI,CAAC,uBAAuB,CAAC,CAAC,CAAC,GAAG;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,EAAE,MAAM,CAAC,CAChE,CAAC;AAEF,QAAA,IAAI,UAAU;aAHiC,OAAO;WAKrD,CAAC;AAaF,MAAM,WAAW,OAAQ,SAAQ,WAAW;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,GAAG,CAAC,EAAE,KAAK,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { KeycloakConfigContext } from "../keycloak/config.mjs";
|
|
2
|
-
import { KeycloakContext } from "./context.mjs";
|
|
3
|
-
import { MultiPlatform } from "multiplatform.one";
|
|
4
|
-
import { jwtDecode } from "jwt-decode";
|
|
5
|
-
import { useContext } from "react";
|
|
6
|
-
class Keycloak {
|
|
7
|
-
constructor(config, input, idToken, refreshToken, login, logout) {
|
|
8
|
-
this.config = config;
|
|
9
|
-
typeof input == "string" ? (this.token = input, this.idToken = idToken, this.refreshToken = refreshToken) : typeof input == "object" && (typeof input.init == "function" ? this.keycloakClient = input : this.mock = input), this.token && !this._tokenParsed && (this._tokenParsed = jwtDecode(this.token)), this.idToken && !this._idTokenParsed && (this._idTokenParsed = jwtDecode(this.idToken)), this.refreshToken && !this._refreshTokenParsed && (this._refreshTokenParsed = jwtDecode(this.refreshToken)), this._login = login, this._logout = logout;
|
|
10
|
-
}
|
|
11
|
-
token;
|
|
12
|
-
idToken;
|
|
13
|
-
refreshToken;
|
|
14
|
-
_idTokenParsed;
|
|
15
|
-
_login;
|
|
16
|
-
_logout;
|
|
17
|
-
_refreshTokenParsed;
|
|
18
|
-
_tokenParsed;
|
|
19
|
-
keycloakClient;
|
|
20
|
-
mock;
|
|
21
|
-
get tokenParsed() {
|
|
22
|
-
return this.keycloakClient ? this.keycloakClient.tokenParsed : this._tokenParsed;
|
|
23
|
-
}
|
|
24
|
-
get idTokenParsed() {
|
|
25
|
-
return this.keycloakClient ? this.keycloakClient.idTokenParsed : this._idTokenParsed;
|
|
26
|
-
}
|
|
27
|
-
get refreshTokenParsed() {
|
|
28
|
-
return this.keycloakClient ? this.keycloakClient.refreshTokenParsed : this._refreshTokenParsed;
|
|
29
|
-
}
|
|
30
|
-
get clientId() {
|
|
31
|
-
return this.keycloakClient ? this.keycloakClient.clientId : this.tokenParsed?.azp || this.config.clientId;
|
|
32
|
-
}
|
|
33
|
-
get email() {
|
|
34
|
-
return this.keycloakClient ? this.keycloakClient.tokenParsed?.email : this.mock ? this.mock.email : this.tokenParsed?.email;
|
|
35
|
-
}
|
|
36
|
-
get realm() {
|
|
37
|
-
return this.keycloakClient ? this.keycloakClient.realm : this.tokenParsed?.iss?.split("/").pop() || this.config.realm;
|
|
38
|
-
}
|
|
39
|
-
get realmAccess() {
|
|
40
|
-
return this.keycloakClient ? this.keycloakClient.realmAccess : this.tokenParsed?.realm_access;
|
|
41
|
-
}
|
|
42
|
-
get resourceAccess() {
|
|
43
|
-
return this.keycloakClient ? this.keycloakClient.resourceAccess : this.tokenParsed?.resource_access;
|
|
44
|
-
}
|
|
45
|
-
get sessionId() {
|
|
46
|
-
return this.keycloakClient ? this.keycloakClient.sessionId : this.tokenParsed?.session_state;
|
|
47
|
-
}
|
|
48
|
-
get subject() {
|
|
49
|
-
return this.keycloakClient ? this.keycloakClient.subject : this.tokenParsed?.sub;
|
|
50
|
-
}
|
|
51
|
-
get username() {
|
|
52
|
-
return this.mock ? this.mock.username : this.tokenParsed?.preferred_username;
|
|
53
|
-
}
|
|
54
|
-
async getUserInfo() {
|
|
55
|
-
if (!this.authenticated) return;
|
|
56
|
-
const response = await fetch(`${this.config.url}/realms/${this.config.realm}/protocol/openid-connect/userinfo`, {
|
|
57
|
-
method: "GET",
|
|
58
|
-
headers: {
|
|
59
|
-
Authorization: "Bearer " + this.token,
|
|
60
|
-
Accept: "application/json"
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
if (response.ok) return response.json();
|
|
64
|
-
}
|
|
65
|
-
async login(options = {}) {
|
|
66
|
-
this.idToken = void 0, this.refreshToken = void 0, this.token = void 0, this.keycloakClient ? await this.keycloakClient.login(options) : await this._login?.(options);
|
|
67
|
-
}
|
|
68
|
-
async logout(options = {}) {
|
|
69
|
-
this.idToken = void 0, this.refreshToken = void 0, this.token = void 0, this.keycloakClient ? await this.keycloakClient.logout(options) : await this._logout?.(options);
|
|
70
|
-
}
|
|
71
|
-
get authenticated() {
|
|
72
|
-
return this.mock ? !0 : this.keycloakClient ? !!this.keycloakClient.authenticated : !this.tokenParsed?.exp || !this.idToken ? !1 : this.tokenParsed.exp > Date.now() / 1e3;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
function useKeycloak() {
|
|
76
|
-
const keycloak = useContext(KeycloakContext),
|
|
77
|
-
keycloakConfig = useContext(KeycloakConfigContext);
|
|
78
|
-
if (keycloak) return keycloak;
|
|
79
|
-
if (MultiPlatform.isStorybook) return new Keycloak(keycloakConfig, {
|
|
80
|
-
email: "storybook@example.com",
|
|
81
|
-
username: "storybook"
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
export { Keycloak, useKeycloak };
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect, useMemo, useCallback } from "react";
|
|
2
|
-
import { AfterAuth } from "../AfterAuth.mjs";
|
|
3
|
-
import { Keycloak, KeycloakConfigContext } from "../../keycloak/index.mjs";
|
|
4
|
-
import { KeycloakContext } from "../../keycloak/context.mjs";
|
|
5
|
-
import { makeRedirectUri, useAuthRequest, useAutoDiscovery, refreshAsync, exchangeCodeAsync } from "expo-auth-session";
|
|
6
|
-
import { persist, useAuthState } from "../../state.mjs";
|
|
7
|
-
import { validOrRefreshableToken, isTokenExpired } from "../../token.mjs";
|
|
8
|
-
import { jsx } from "react/jsx-runtime";
|
|
9
|
-
const REFRESH_THRESHOLD = 5;
|
|
10
|
-
function AuthProvider({
|
|
11
|
-
children,
|
|
12
|
-
keycloakConfig
|
|
13
|
-
}) {
|
|
14
|
-
const [keycloak, setKeycloak] = useState(),
|
|
15
|
-
authState = useAuthState(),
|
|
16
|
-
initialRefreshToken = useMemo(() => validOrRefreshableToken(persist && authState.refreshToken || !1), []),
|
|
17
|
-
keycloakUrl = `${keycloakConfig?.url}/realms/${keycloakConfig?.realm}`,
|
|
18
|
-
clientId = keycloakConfig.publicClientId || keycloakConfig?.clientId || "",
|
|
19
|
-
discovery = useAutoDiscovery(keycloakUrl),
|
|
20
|
-
redirectUri = makeRedirectUri(),
|
|
21
|
-
[tokens, setTokens] = useState({
|
|
22
|
-
refreshToken: initialRefreshToken,
|
|
23
|
-
token: validOrRefreshableToken(persist && authState.token || !1, initialRefreshToken),
|
|
24
|
-
idToken: validOrRefreshableToken(persist && authState.idToken || !1, initialRefreshToken)
|
|
25
|
-
}),
|
|
26
|
-
scopes = useMemo(() => [... /* @__PURE__ */new Set(["email", "openid", "profile", ...(keycloakConfig.scopes || [])])], [keycloakConfig.scopes]),
|
|
27
|
-
[request, response, promptAsync] = useAuthRequest({
|
|
28
|
-
clientId,
|
|
29
|
-
redirectUri,
|
|
30
|
-
scopes
|
|
31
|
-
}, discovery);
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
!discovery || !response?.type || !request?.codeVerifier || !clientId || (async () => {
|
|
34
|
-
if (response?.type === "success" && request.codeVerifier && response.params.code) {
|
|
35
|
-
const tokenResponse = await exchangeCodeAsync({
|
|
36
|
-
clientId,
|
|
37
|
-
code: response.params.code,
|
|
38
|
-
redirectUri,
|
|
39
|
-
scopes,
|
|
40
|
-
extraParams: {
|
|
41
|
-
code_verifier: request.codeVerifier
|
|
42
|
-
}
|
|
43
|
-
}, discovery);
|
|
44
|
-
tokenResponse && setTokens({
|
|
45
|
-
idToken: tokenResponse.idToken,
|
|
46
|
-
refreshToken: tokenResponse.refreshToken,
|
|
47
|
-
token: tokenResponse.accessToken
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
})();
|
|
51
|
-
}, [!discovery, request?.codeVerifier, response?.type === "success" ? response?.params?.code : void 0, clientId, scopes, redirectUri]);
|
|
52
|
-
const resetTokens = useCallback(() => {
|
|
53
|
-
authState.setIdToken(""), authState.setRefreshToken(""), authState.setToken(""), setTokens({
|
|
54
|
-
refreshToken: void 0,
|
|
55
|
-
token: void 0,
|
|
56
|
-
idToken: void 0
|
|
57
|
-
});
|
|
58
|
-
}, []),
|
|
59
|
-
refreshTokens = useCallback(async () => {
|
|
60
|
-
if (discovery) if (typeof tokens.refreshToken == "string") {
|
|
61
|
-
if (isTokenExpired(tokens.refreshToken)) resetTokens();else {
|
|
62
|
-
const tokenResponse = await refreshAsync({
|
|
63
|
-
clientId,
|
|
64
|
-
refreshToken: tokens.refreshToken,
|
|
65
|
-
scopes
|
|
66
|
-
}, discovery);
|
|
67
|
-
tokenResponse ? setTokens({
|
|
68
|
-
idToken: tokenResponse.idToken,
|
|
69
|
-
refreshToken: tokenResponse.refreshToken,
|
|
70
|
-
token: tokenResponse.accessToken
|
|
71
|
-
}) : resetTokens();
|
|
72
|
-
}
|
|
73
|
-
} else authState.refreshToken && typeof authState.refreshToken == "string" && isTokenExpired(authState.refreshToken) && resetTokens();
|
|
74
|
-
}, [!discovery, tokens.refreshToken, clientId, scopes]);
|
|
75
|
-
return useEffect(() => {
|
|
76
|
-
discovery && refreshTokens();
|
|
77
|
-
}, [!discovery]), useEffect(() => {
|
|
78
|
-
if (!request) return;
|
|
79
|
-
let refreshHandle;
|
|
80
|
-
return (async () => {
|
|
81
|
-
if (tokens.token && isTokenExpired(tokens.token)) await refreshTokens();else {
|
|
82
|
-
const _keycloak = new Keycloak(keycloakConfig, tokens.token || void 0, tokens.idToken || void 0, tokens.refreshToken || void 0, async options => {
|
|
83
|
-
await promptAsync(options);
|
|
84
|
-
}, async _options => {
|
|
85
|
-
resetTokens();
|
|
86
|
-
});
|
|
87
|
-
if (_keycloak.tokenParsed?.exp) {
|
|
88
|
-
const timeout = Math.max(Math.min(_keycloak.tokenParsed.exp, _keycloak.refreshTokenParsed?.exp || 0) - Math.floor(Date.now() / 1e3) - REFRESH_THRESHOLD, REFRESH_THRESHOLD) * 1e3;
|
|
89
|
-
if (timeout > 0) refreshHandle = setTimeout(() => {
|
|
90
|
-
refreshTokens();
|
|
91
|
-
}, timeout);else {
|
|
92
|
-
setTimeout(() => _keycloak.logout(), Math.max(0, timeout + REFRESH_THRESHOLD) * 1e3);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
setKeycloak(_keycloak);
|
|
97
|
-
}
|
|
98
|
-
})(), () => {
|
|
99
|
-
refreshHandle && clearTimeout(refreshHandle);
|
|
100
|
-
};
|
|
101
|
-
}, [!request, tokens.token, tokens.idToken, tokens.refreshToken, refreshTokens]), /* @__PURE__ */jsx(KeycloakConfigContext.Provider, {
|
|
102
|
-
value: keycloakConfig,
|
|
103
|
-
children: /* @__PURE__ */jsx(KeycloakContext.Provider, {
|
|
104
|
-
value: keycloak,
|
|
105
|
-
children: /* @__PURE__ */jsx(AfterAuth, {
|
|
106
|
-
children
|
|
107
|
-
})
|
|
108
|
-
})
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
export { AuthProvider };
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { KeycloakConfigContext } from "../keycloak/config.mjs";
|
|
2
|
-
import { KeycloakContext } from "./context.mjs";
|
|
3
|
-
import { MultiPlatform } from "multiplatform.one";
|
|
4
|
-
import { jwtDecode } from "jwt-decode";
|
|
5
|
-
import { useContext } from "react";
|
|
6
|
-
class Keycloak {
|
|
7
|
-
constructor(config, input, idToken, refreshToken, login, logout) {
|
|
8
|
-
this.config = config;
|
|
9
|
-
typeof input == "string" ? (this.token = input, this.idToken = idToken, this.refreshToken = refreshToken) : typeof input == "object" && (typeof input.init == "function" ? this.keycloakClient = input : this.mock = input), this.token && !this._tokenParsed && (this._tokenParsed = jwtDecode(this.token)), this.idToken && !this._idTokenParsed && (this._idTokenParsed = jwtDecode(this.idToken)), this.refreshToken && !this._refreshTokenParsed && (this._refreshTokenParsed = jwtDecode(this.refreshToken)), this._login = login, this._logout = logout;
|
|
10
|
-
}
|
|
11
|
-
token;
|
|
12
|
-
idToken;
|
|
13
|
-
refreshToken;
|
|
14
|
-
_idTokenParsed;
|
|
15
|
-
_login;
|
|
16
|
-
_logout;
|
|
17
|
-
_refreshTokenParsed;
|
|
18
|
-
_tokenParsed;
|
|
19
|
-
keycloakClient;
|
|
20
|
-
mock;
|
|
21
|
-
get tokenParsed() {
|
|
22
|
-
return this.keycloakClient ? this.keycloakClient.tokenParsed : this._tokenParsed;
|
|
23
|
-
}
|
|
24
|
-
get idTokenParsed() {
|
|
25
|
-
return this.keycloakClient ? this.keycloakClient.idTokenParsed : this._idTokenParsed;
|
|
26
|
-
}
|
|
27
|
-
get refreshTokenParsed() {
|
|
28
|
-
return this.keycloakClient ? this.keycloakClient.refreshTokenParsed : this._refreshTokenParsed;
|
|
29
|
-
}
|
|
30
|
-
get clientId() {
|
|
31
|
-
return this.keycloakClient ? this.keycloakClient.clientId : this.tokenParsed?.azp || this.config.clientId;
|
|
32
|
-
}
|
|
33
|
-
get email() {
|
|
34
|
-
return this.keycloakClient ? this.keycloakClient.tokenParsed?.email : this.mock ? this.mock.email : this.tokenParsed?.email;
|
|
35
|
-
}
|
|
36
|
-
get realm() {
|
|
37
|
-
return this.keycloakClient ? this.keycloakClient.realm : this.tokenParsed?.iss?.split("/").pop() || this.config.realm;
|
|
38
|
-
}
|
|
39
|
-
get realmAccess() {
|
|
40
|
-
return this.keycloakClient ? this.keycloakClient.realmAccess : this.tokenParsed?.realm_access;
|
|
41
|
-
}
|
|
42
|
-
get resourceAccess() {
|
|
43
|
-
return this.keycloakClient ? this.keycloakClient.resourceAccess : this.tokenParsed?.resource_access;
|
|
44
|
-
}
|
|
45
|
-
get sessionId() {
|
|
46
|
-
return this.keycloakClient ? this.keycloakClient.sessionId : this.tokenParsed?.session_state;
|
|
47
|
-
}
|
|
48
|
-
get subject() {
|
|
49
|
-
return this.keycloakClient ? this.keycloakClient.subject : this.tokenParsed?.sub;
|
|
50
|
-
}
|
|
51
|
-
get username() {
|
|
52
|
-
return this.mock ? this.mock.username : this.tokenParsed?.preferred_username;
|
|
53
|
-
}
|
|
54
|
-
async getUserInfo() {
|
|
55
|
-
if (!this.authenticated) return;
|
|
56
|
-
const response = await fetch(`${this.config.url}/realms/${this.config.realm}/protocol/openid-connect/userinfo`, {
|
|
57
|
-
method: "GET",
|
|
58
|
-
headers: {
|
|
59
|
-
Authorization: "Bearer " + this.token,
|
|
60
|
-
Accept: "application/json"
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
if (response.ok) return response.json();
|
|
64
|
-
}
|
|
65
|
-
async login(options = {}) {
|
|
66
|
-
this.idToken = void 0, this.refreshToken = void 0, this.token = void 0, this.keycloakClient ? await this.keycloakClient.login(options) : await this._login?.(options);
|
|
67
|
-
}
|
|
68
|
-
async logout(options = {}) {
|
|
69
|
-
this.idToken = void 0, this.refreshToken = void 0, this.token = void 0, this.keycloakClient ? await this.keycloakClient.logout(options) : await this._logout?.(options);
|
|
70
|
-
}
|
|
71
|
-
get authenticated() {
|
|
72
|
-
return this.mock ? !0 : this.keycloakClient ? !!this.keycloakClient.authenticated : !this.tokenParsed?.exp || !this.idToken ? !1 : this.tokenParsed.exp > Date.now() / 1e3;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
function useKeycloak() {
|
|
76
|
-
const keycloak = useContext(KeycloakContext),
|
|
77
|
-
keycloakConfig = useContext(KeycloakConfigContext);
|
|
78
|
-
if (keycloak) return keycloak;
|
|
79
|
-
if (MultiPlatform.isStorybook) return new Keycloak(keycloakConfig, {
|
|
80
|
-
email: "storybook@example.com",
|
|
81
|
-
username: "storybook"
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
export { Keycloak, useKeycloak };
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect, useMemo, useCallback } from "react";
|
|
2
|
-
import { AfterAuth } from "../AfterAuth.mjs";
|
|
3
|
-
import { Keycloak, KeycloakConfigContext } from "../../keycloak/index.mjs";
|
|
4
|
-
import { KeycloakContext } from "../../keycloak/context.mjs";
|
|
5
|
-
import { makeRedirectUri, useAuthRequest, useAutoDiscovery, refreshAsync, exchangeCodeAsync } from "expo-auth-session";
|
|
6
|
-
import { persist, useAuthState } from "../../state.mjs";
|
|
7
|
-
import { validOrRefreshableToken, isTokenExpired } from "../../token.mjs";
|
|
8
|
-
import { jsx } from "react/jsx-runtime";
|
|
9
|
-
const REFRESH_THRESHOLD = 5;
|
|
10
|
-
function AuthProvider({
|
|
11
|
-
children,
|
|
12
|
-
keycloakConfig
|
|
13
|
-
}) {
|
|
14
|
-
const [keycloak, setKeycloak] = useState(),
|
|
15
|
-
authState = useAuthState(),
|
|
16
|
-
initialRefreshToken = useMemo(() => validOrRefreshableToken(persist && authState.refreshToken || !1), []),
|
|
17
|
-
keycloakUrl = `${keycloakConfig?.url}/realms/${keycloakConfig?.realm}`,
|
|
18
|
-
clientId = keycloakConfig.publicClientId || keycloakConfig?.clientId || "",
|
|
19
|
-
discovery = useAutoDiscovery(keycloakUrl),
|
|
20
|
-
redirectUri = makeRedirectUri(),
|
|
21
|
-
[tokens, setTokens] = useState({
|
|
22
|
-
refreshToken: initialRefreshToken,
|
|
23
|
-
token: validOrRefreshableToken(persist && authState.token || !1, initialRefreshToken),
|
|
24
|
-
idToken: validOrRefreshableToken(persist && authState.idToken || !1, initialRefreshToken)
|
|
25
|
-
}),
|
|
26
|
-
scopes = useMemo(() => [... /* @__PURE__ */new Set(["email", "openid", "profile", ...(keycloakConfig.scopes || [])])], [keycloakConfig.scopes]),
|
|
27
|
-
[request, response, promptAsync] = useAuthRequest({
|
|
28
|
-
clientId,
|
|
29
|
-
redirectUri,
|
|
30
|
-
scopes
|
|
31
|
-
}, discovery);
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
!discovery || !response?.type || !request?.codeVerifier || !clientId || (async () => {
|
|
34
|
-
if (response?.type === "success" && request.codeVerifier && response.params.code) {
|
|
35
|
-
const tokenResponse = await exchangeCodeAsync({
|
|
36
|
-
clientId,
|
|
37
|
-
code: response.params.code,
|
|
38
|
-
redirectUri,
|
|
39
|
-
scopes,
|
|
40
|
-
extraParams: {
|
|
41
|
-
code_verifier: request.codeVerifier
|
|
42
|
-
}
|
|
43
|
-
}, discovery);
|
|
44
|
-
tokenResponse && setTokens({
|
|
45
|
-
idToken: tokenResponse.idToken,
|
|
46
|
-
refreshToken: tokenResponse.refreshToken,
|
|
47
|
-
token: tokenResponse.accessToken
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
})();
|
|
51
|
-
}, [!discovery, request?.codeVerifier, response?.type === "success" ? response?.params?.code : void 0, clientId, scopes, redirectUri]);
|
|
52
|
-
const resetTokens = useCallback(() => {
|
|
53
|
-
authState.setIdToken(""), authState.setRefreshToken(""), authState.setToken(""), setTokens({
|
|
54
|
-
refreshToken: void 0,
|
|
55
|
-
token: void 0,
|
|
56
|
-
idToken: void 0
|
|
57
|
-
});
|
|
58
|
-
}, []),
|
|
59
|
-
refreshTokens = useCallback(async () => {
|
|
60
|
-
if (discovery) if (typeof tokens.refreshToken == "string") {
|
|
61
|
-
if (isTokenExpired(tokens.refreshToken)) resetTokens();else {
|
|
62
|
-
const tokenResponse = await refreshAsync({
|
|
63
|
-
clientId,
|
|
64
|
-
refreshToken: tokens.refreshToken,
|
|
65
|
-
scopes
|
|
66
|
-
}, discovery);
|
|
67
|
-
tokenResponse ? setTokens({
|
|
68
|
-
idToken: tokenResponse.idToken,
|
|
69
|
-
refreshToken: tokenResponse.refreshToken,
|
|
70
|
-
token: tokenResponse.accessToken
|
|
71
|
-
}) : resetTokens();
|
|
72
|
-
}
|
|
73
|
-
} else authState.refreshToken && typeof authState.refreshToken == "string" && isTokenExpired(authState.refreshToken) && resetTokens();
|
|
74
|
-
}, [!discovery, tokens.refreshToken, clientId, scopes]);
|
|
75
|
-
return useEffect(() => {
|
|
76
|
-
discovery && refreshTokens();
|
|
77
|
-
}, [!discovery]), useEffect(() => {
|
|
78
|
-
if (!request) return;
|
|
79
|
-
let refreshHandle;
|
|
80
|
-
return (async () => {
|
|
81
|
-
if (tokens.token && isTokenExpired(tokens.token)) await refreshTokens();else {
|
|
82
|
-
const _keycloak = new Keycloak(keycloakConfig, tokens.token || void 0, tokens.idToken || void 0, tokens.refreshToken || void 0, async options => {
|
|
83
|
-
await promptAsync(options);
|
|
84
|
-
}, async _options => {
|
|
85
|
-
resetTokens();
|
|
86
|
-
});
|
|
87
|
-
if (_keycloak.tokenParsed?.exp) {
|
|
88
|
-
const timeout = Math.max(Math.min(_keycloak.tokenParsed.exp, _keycloak.refreshTokenParsed?.exp || 0) - Math.floor(Date.now() / 1e3) - REFRESH_THRESHOLD, REFRESH_THRESHOLD) * 1e3;
|
|
89
|
-
if (timeout > 0) refreshHandle = setTimeout(() => {
|
|
90
|
-
refreshTokens();
|
|
91
|
-
}, timeout);else {
|
|
92
|
-
setTimeout(() => _keycloak.logout(), Math.max(0, timeout + REFRESH_THRESHOLD) * 1e3);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
setKeycloak(_keycloak);
|
|
97
|
-
}
|
|
98
|
-
})(), () => {
|
|
99
|
-
refreshHandle && clearTimeout(refreshHandle);
|
|
100
|
-
};
|
|
101
|
-
}, [!request, tokens.token, tokens.idToken, tokens.refreshToken, refreshTokens]), /* @__PURE__ */jsx(KeycloakConfigContext.Provider, {
|
|
102
|
-
value: keycloakConfig,
|
|
103
|
-
children: /* @__PURE__ */jsx(KeycloakContext.Provider, {
|
|
104
|
-
value: keycloak,
|
|
105
|
-
children: /* @__PURE__ */jsx(AfterAuth, {
|
|
106
|
-
children
|
|
107
|
-
})
|
|
108
|
-
})
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
export { AuthProvider };
|