@multiplatform.one/keycloak 1.0.2 → 1.0.3
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/package.json +32 -34
- package/routes/index.d.ts +1 -1
- package/routes/index.js +1 -1
- package/src/Authenticated.tsx +12 -13
- package/src/apollo.ts +1 -1
- package/src/authConfig.ts +2 -0
- package/src/hooks/useTokensFromQuery/index.ts +2 -0
- package/src/hooks/useTokensFromState.ts +2 -2
- package/{lib/@types/expoKeycloakAuth.d.d.mts → src/keycloak/config.ts} +17 -6
- package/src/keycloak/context.ts +3 -1
- package/src/keycloak/index.ts +1 -0
- package/src/keycloak/keycloak.native.ts +49 -15
- package/src/keycloak/keycloak.ts +66 -11
- package/src/provider/AfterAuth.tsx +2 -0
- package/src/provider/AuthProvider/AuthProvider.native.tsx +159 -6
- package/src/provider/AuthProvider/AuthProvider.tsx +66 -43
- package/src/provider/KeycloakProvider.tsx +12 -2
- package/src/routes.ts +19 -0
- package/src/session/session.ts +4 -15
- package/src/token.ts +13 -5
- package/lib/@types/expoKeycloakAuth.d.d.ts +0 -25
- package/lib/@types/expoKeycloakAuth.d.js +0 -1
- package/lib/@types/expoKeycloakAuth.d.mjs +0 -0
- package/lib/Authenticated.d.mts +0 -32
- package/lib/Authenticated.d.ts +0 -32
- package/lib/Authenticated.js +0 -20
- package/lib/Authenticated.mjs +0 -20
- package/lib/apollo.d.mts +0 -7
- package/lib/apollo.d.ts +0 -7
- package/lib/apollo.js +0 -15
- package/lib/apollo.mjs +0 -15
- package/lib/authConfig.d.mts +0 -12
- package/lib/authConfig.d.ts +0 -12
- package/lib/authConfig.js +0 -9
- package/lib/authConfig.mjs +0 -9
- package/lib/chunk-2L5TXBDK.mjs +0 -7
- package/lib/chunk-2MYOFYAK.mjs +0 -53
- package/lib/chunk-2VDDEPLF.js +0 -27
- package/lib/chunk-2VGMJ7WP.js +0 -34
- package/lib/chunk-32AVT4GA.js +0 -9
- package/lib/chunk-3ZTSLDX7.js +0 -13
- package/lib/chunk-6APOOEW6.js +0 -28
- package/lib/chunk-6F4PWJZI.js +0 -1
- package/lib/chunk-6FRYV4MK.mjs +0 -27
- package/lib/chunk-6WBHOY7M.js +0 -50
- package/lib/chunk-74FSREBY.js +0 -161
- package/lib/chunk-A2V2S4HP.js +0 -22
- package/lib/chunk-BUZONXAW.js +0 -1
- package/lib/chunk-C6TOWKPW.mjs +0 -245
- package/lib/chunk-DNEUOHZQ.mjs +0 -28
- package/lib/chunk-EGCPD3BX.js +0 -51
- package/lib/chunk-HH32BME2.mjs +0 -0
- package/lib/chunk-HTWZLBA4.mjs +0 -13
- package/lib/chunk-I5FNGKQ6.js +0 -16
- package/lib/chunk-IGSEESI3.mjs +0 -51
- package/lib/chunk-JAFUI2JQ.mjs +0 -9
- package/lib/chunk-JPQI72HR.mjs +0 -0
- package/lib/chunk-KWNIT4G4.mjs +0 -34
- package/lib/chunk-L3HTVJ4B.mjs +0 -13
- package/lib/chunk-MDAAMGTE.js +0 -1
- package/lib/chunk-NQMFZ6RW.mjs +0 -50
- package/lib/chunk-OAUYHIWG.mjs +0 -0
- package/lib/chunk-OBB23GPX.mjs +0 -0
- package/lib/chunk-OYWXU5N7.mjs +0 -161
- package/lib/chunk-P57PW2II.js +0 -11
- package/lib/chunk-TUJRPTZE.js +0 -13
- package/lib/chunk-UESWAK47.mjs +0 -0
- package/lib/chunk-UKSHA3X3.mjs +0 -16
- package/lib/chunk-VS4M7GMO.js +0 -1
- package/lib/chunk-W4LGQZMF.js +0 -245
- package/lib/chunk-WBQAMGXK.mjs +0 -0
- package/lib/chunk-WMH347OL.mjs +0 -22
- package/lib/chunk-WS4IMGVL.js +0 -1
- package/lib/chunk-YACGLW5Q.js +0 -7
- package/lib/chunk-YYYDFAI4.js +0 -53
- package/lib/chunk-ZCBD6HWK.js +0 -1
- package/lib/chunk-ZFXKCRJC.mjs +0 -11
- package/lib/hooks/index.d.mts +0 -5
- package/lib/hooks/index.d.ts +0 -5
- package/lib/hooks/index.js +0 -19
- package/lib/hooks/index.mjs +0 -19
- package/lib/hooks/useAuthConfig.d.mts +0 -6
- package/lib/hooks/useAuthConfig.d.ts +0 -6
- package/lib/hooks/useAuthConfig.js +0 -8
- package/lib/hooks/useAuthConfig.mjs +0 -8
- package/lib/hooks/useTokensFromQuery/index.d.mts +0 -3
- package/lib/hooks/useTokensFromQuery/index.d.ts +0 -3
- package/lib/hooks/useTokensFromQuery/index.js +0 -7
- package/lib/hooks/useTokensFromQuery/index.mjs +0 -7
- package/lib/hooks/useTokensFromQuery/index.native.d.mts +0 -3
- package/lib/hooks/useTokensFromQuery/index.native.d.ts +0 -3
- package/lib/hooks/useTokensFromQuery/index.native.js +0 -7
- package/lib/hooks/useTokensFromQuery/index.native.mjs +0 -7
- package/lib/hooks/useTokensFromState.d.mts +0 -3
- package/lib/hooks/useTokensFromState.d.ts +0 -3
- package/lib/hooks/useTokensFromState.js +0 -9
- package/lib/hooks/useTokensFromState.mjs +0 -9
- package/lib/index.d.mts +0 -18
- package/lib/index.d.ts +0 -18
- package/lib/index.js +0 -70
- package/lib/index.mjs +0 -70
- package/lib/keycloak/context.d.mts +0 -12
- package/lib/keycloak/context.d.ts +0 -12
- package/lib/keycloak/context.js +0 -7
- package/lib/keycloak/context.mjs +0 -7
- package/lib/keycloak/index.d.mts +0 -7
- package/lib/keycloak/index.d.ts +0 -7
- package/lib/keycloak/index.js +0 -14
- package/lib/keycloak/index.mjs +0 -14
- package/lib/keycloak/keycloak.d.mts +0 -37
- package/lib/keycloak/keycloak.d.ts +0 -37
- package/lib/keycloak/keycloak.js +0 -13
- package/lib/keycloak/keycloak.mjs +0 -13
- package/lib/keycloak/keycloak.native.d.mts +0 -33
- package/lib/keycloak/keycloak.native.d.ts +0 -33
- package/lib/keycloak/keycloak.native.js +0 -134
- package/lib/keycloak/keycloak.native.mjs +0 -134
- package/lib/provider/AfterAuth.d.mts +0 -28
- package/lib/provider/AfterAuth.d.ts +0 -28
- package/lib/provider/AfterAuth.js +0 -18
- package/lib/provider/AfterAuth.mjs +0 -18
- package/lib/provider/AuthProvider/AuthProvider.d.mts +0 -37
- package/lib/provider/AuthProvider/AuthProvider.d.ts +0 -37
- package/lib/provider/AuthProvider/AuthProvider.js +0 -19
- package/lib/provider/AuthProvider/AuthProvider.mjs +0 -19
- package/lib/provider/AuthProvider/AuthProvider.native.d.mts +0 -29
- package/lib/provider/AuthProvider/AuthProvider.native.d.ts +0 -29
- package/lib/provider/AuthProvider/AuthProvider.native.js +0 -25
- package/lib/provider/AuthProvider/AuthProvider.native.mjs +0 -25
- package/lib/provider/AuthProvider/index.d.mts +0 -4
- package/lib/provider/AuthProvider/index.d.ts +0 -4
- package/lib/provider/AuthProvider/index.js +0 -20
- package/lib/provider/AuthProvider/index.mjs +0 -20
- package/lib/provider/KeycloakProvider.d.mts +0 -34
- package/lib/provider/KeycloakProvider.d.ts +0 -34
- package/lib/provider/KeycloakProvider.js +0 -21
- package/lib/provider/KeycloakProvider.mjs +0 -21
- package/lib/provider/index.d.mts +0 -8
- package/lib/provider/index.d.ts +0 -8
- package/lib/provider/index.js +0 -28
- package/lib/provider/index.mjs +0 -28
- package/lib/routes.d.mts +0 -34
- package/lib/routes.d.ts +0 -34
- package/lib/routes.js +0 -131
- package/lib/routes.mjs +0 -131
- package/lib/session/index.d.mts +0 -3
- package/lib/session/index.d.ts +0 -3
- package/lib/session/index.js +0 -10
- package/lib/session/index.mjs +0 -10
- package/lib/session/session.d.mts +0 -18
- package/lib/session/session.d.ts +0 -18
- package/lib/session/session.js +0 -9
- package/lib/session/session.mjs +0 -9
- package/lib/session/session.native.d.mts +0 -8
- package/lib/session/session.native.d.ts +0 -8
- package/lib/session/session.native.js +0 -13
- package/lib/session/session.native.mjs +0 -13
- package/lib/state.d.mts +0 -12
- package/lib/state.d.ts +0 -12
- package/lib/state.js +0 -9
- package/lib/state.mjs +0 -9
- package/lib/token.d.mts +0 -17
- package/lib/token.d.ts +0 -17
- package/lib/token.js +0 -9
- package/lib/token.mjs +0 -9
- package/lib/types.d.mts +0 -20
- package/lib/types.d.ts +0 -20
- package/lib/types.js +0 -1
- package/lib/types.mjs +0 -1
package/lib/routes.js
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } async function _asyncOptionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = await fn(value); } else if (op === 'call' || op === 'optionalCall') { value = await fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
-
|
|
3
|
-
var _chunkP57PW2IIjs = require('./chunk-P57PW2II.js');
|
|
4
|
-
|
|
5
|
-
// src/routes.ts
|
|
6
|
-
var _nextauth = require('next-auth');
|
|
7
|
-
var _jwtdecode = require('jwt-decode');
|
|
8
|
-
var KeycloakProvider = _chunkP57PW2IIjs.__require.call(void 0, "next-auth/providers/keycloak").default;
|
|
9
|
-
var _nextAuth;
|
|
10
|
-
var NextAuth = _chunkP57PW2IIjs.__require.call(void 0, "next-auth").default;
|
|
11
|
-
var NextResponse = _chunkP57PW2IIjs.__require.call(void 0, "next/server").NextResponse;
|
|
12
|
-
var logger = console;
|
|
13
|
-
function createAuthHandler(options) {
|
|
14
|
-
return NextAuth(createNextAuthOptions(options));
|
|
15
|
-
}
|
|
16
|
-
var defaults = {
|
|
17
|
-
keycloak: {
|
|
18
|
-
baseUrl: "http://localhost:8080",
|
|
19
|
-
realm: "master"
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
function createLogoutHandler(options) {
|
|
23
|
-
return {
|
|
24
|
-
async GET() {
|
|
25
|
-
const idToken = await _asyncOptionalChain([(await _nextauth.getServerSession.call(void 0, createNextAuthOptions(options))), 'optionalAccess', async _ => _.idToken]);
|
|
26
|
-
if (idToken) {
|
|
27
|
-
try {
|
|
28
|
-
await fetch(
|
|
29
|
-
`${_optionalChain([options, 'access', _2 => _2.keycloak, 'optionalAccess', _3 => _3.baseUrl]) || defaults.keycloak.baseUrl}/realms/${_optionalChain([options, 'access', _4 => _4.keycloak, 'optionalAccess', _5 => _5.realm]) || defaults.keycloak.realm}/protocol/openid-connect/logout?id_token_hint=${idToken}&post_logout_redirect_uri=${encodeURIComponent(
|
|
30
|
-
options.baseUrl
|
|
31
|
-
)}`,
|
|
32
|
-
{ method: "GET" }
|
|
33
|
-
);
|
|
34
|
-
} catch (err) {
|
|
35
|
-
logger.error(err);
|
|
36
|
-
return new NextResponse(null, { status: 500 });
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return new NextResponse();
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
function createNextAuthOptions(options) {
|
|
44
|
-
if (_nextAuth)
|
|
45
|
-
return _nextAuth;
|
|
46
|
-
_nextAuth = {
|
|
47
|
-
...options.nextAuth,
|
|
48
|
-
providers: [
|
|
49
|
-
KeycloakProvider({
|
|
50
|
-
issuer: `${_optionalChain([options, 'access', _6 => _6.keycloak, 'optionalAccess', _7 => _7.baseUrl]) || defaults.keycloak.baseUrl}/realms/${_optionalChain([options, 'access', _8 => _8.keycloak, 'optionalAccess', _9 => _9.realm]) || defaults.keycloak.realm}`,
|
|
51
|
-
...options.keycloak
|
|
52
|
-
}),
|
|
53
|
-
..._optionalChain([options, 'access', _10 => _10.nextAuth, 'optionalAccess', _11 => _11.providers]) || []
|
|
54
|
-
],
|
|
55
|
-
callbacks: {
|
|
56
|
-
..._optionalChain([options, 'access', _12 => _12.nextAuth, 'optionalAccess', _13 => _13.callbacks]),
|
|
57
|
-
async jwt(params) {
|
|
58
|
-
if (typeof _optionalChain([options, 'access', _14 => _14.nextAuth, 'optionalAccess', _15 => _15.callbacks, 'optionalAccess', _16 => _16.jwt]) === "function") {
|
|
59
|
-
return _optionalChain([options, 'access', _17 => _17.nextAuth, 'optionalAccess', _18 => _18.callbacks, 'access', _19 => _19.jwt, 'call', _20 => _20(params)]);
|
|
60
|
-
}
|
|
61
|
-
const { token, account } = params;
|
|
62
|
-
if (account) {
|
|
63
|
-
const decoded = _jwtdecode.jwtDecode.call(void 0, account.access_token || "");
|
|
64
|
-
token.decoded = decoded;
|
|
65
|
-
token.accessToken = account.access_token;
|
|
66
|
-
token.idToken = account.id_token;
|
|
67
|
-
token.expiresAt = account.expires_at;
|
|
68
|
-
token.refreshToken = account.refresh_token;
|
|
69
|
-
token.roles = _optionalChain([decoded, 'access', _21 => _21.realm_access, 'optionalAccess', _22 => _22.roles]);
|
|
70
|
-
return token;
|
|
71
|
-
} else if (Math.floor(Date.now() / 1e3) < Number(token.expiresAt)) {
|
|
72
|
-
return token;
|
|
73
|
-
} else {
|
|
74
|
-
try {
|
|
75
|
-
return refreshAccessToken(options, token);
|
|
76
|
-
} catch (err) {
|
|
77
|
-
return { ...token, err };
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
async session(params) {
|
|
82
|
-
if (typeof _optionalChain([options, 'access', _23 => _23.nextAuth, 'optionalAccess', _24 => _24.callbacks, 'optionalAccess', _25 => _25.session]) === "function") {
|
|
83
|
-
return options.nextAuth.callbacks.session(params);
|
|
84
|
-
}
|
|
85
|
-
const { session: nextSession, token: nextToken } = params;
|
|
86
|
-
const session = nextSession;
|
|
87
|
-
const token = nextToken;
|
|
88
|
-
if (token.accessToken)
|
|
89
|
-
session.accessToken = token.accessToken;
|
|
90
|
-
if (token.idToken)
|
|
91
|
-
session.idToken = token.idToken;
|
|
92
|
-
session.err = token.err;
|
|
93
|
-
return session;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
return _nextAuth;
|
|
98
|
-
}
|
|
99
|
-
async function refreshAccessToken(options, nextToken) {
|
|
100
|
-
const res = await fetch(
|
|
101
|
-
`${_optionalChain([options, 'access', _26 => _26.keycloak, 'optionalAccess', _27 => _27.baseUrl]) || defaults.keycloak.baseUrl}/realms/${_optionalChain([options, 'access', _28 => _28.keycloak, 'optionalAccess', _29 => _29.realm]) || defaults.keycloak.realm}/protocol/openid-connect/token`,
|
|
102
|
-
{
|
|
103
|
-
method: "POST",
|
|
104
|
-
headers: {
|
|
105
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
106
|
-
},
|
|
107
|
-
body: new URLSearchParams({
|
|
108
|
-
client_id: options.keycloak.clientId,
|
|
109
|
-
client_secret: options.keycloak.clientSecret,
|
|
110
|
-
grant_type: "refresh_token",
|
|
111
|
-
refresh_token: nextToken.refreshToken
|
|
112
|
-
})
|
|
113
|
-
}
|
|
114
|
-
);
|
|
115
|
-
const refreshToken = await res.json();
|
|
116
|
-
if (!res.ok)
|
|
117
|
-
throw refreshToken;
|
|
118
|
-
return {
|
|
119
|
-
...nextToken,
|
|
120
|
-
accessToken: refreshToken.access_token,
|
|
121
|
-
decoded: _jwtdecode.jwtDecode.call(void 0, refreshToken.access_token),
|
|
122
|
-
expiresAt: Math.floor(Date.now() / 1e3) + Number(refreshToken.expires_in),
|
|
123
|
-
idToken: refreshToken.id_token,
|
|
124
|
-
refreshToken: refreshToken.refresh_token
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
exports.createAuthHandler = createAuthHandler; exports.createLogoutHandler = createLogoutHandler; exports.createNextAuthOptions = createNextAuthOptions;
|
package/lib/routes.mjs
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__require
|
|
3
|
-
} from "./chunk-ZFXKCRJC.mjs";
|
|
4
|
-
|
|
5
|
-
// src/routes.ts
|
|
6
|
-
import { getServerSession } from "next-auth";
|
|
7
|
-
import { jwtDecode } from "jwt-decode";
|
|
8
|
-
var KeycloakProvider = __require("next-auth/providers/keycloak").default;
|
|
9
|
-
var _nextAuth;
|
|
10
|
-
var NextAuth = __require("next-auth").default;
|
|
11
|
-
var NextResponse = __require("next/server").NextResponse;
|
|
12
|
-
var logger = console;
|
|
13
|
-
function createAuthHandler(options) {
|
|
14
|
-
return NextAuth(createNextAuthOptions(options));
|
|
15
|
-
}
|
|
16
|
-
var defaults = {
|
|
17
|
-
keycloak: {
|
|
18
|
-
baseUrl: "http://localhost:8080",
|
|
19
|
-
realm: "master"
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
function createLogoutHandler(options) {
|
|
23
|
-
return {
|
|
24
|
-
async GET() {
|
|
25
|
-
const idToken = (await getServerSession(createNextAuthOptions(options)))?.idToken;
|
|
26
|
-
if (idToken) {
|
|
27
|
-
try {
|
|
28
|
-
await fetch(
|
|
29
|
-
`${options.keycloak?.baseUrl || defaults.keycloak.baseUrl}/realms/${options.keycloak?.realm || defaults.keycloak.realm}/protocol/openid-connect/logout?id_token_hint=${idToken}&post_logout_redirect_uri=${encodeURIComponent(
|
|
30
|
-
options.baseUrl
|
|
31
|
-
)}`,
|
|
32
|
-
{ method: "GET" }
|
|
33
|
-
);
|
|
34
|
-
} catch (err) {
|
|
35
|
-
logger.error(err);
|
|
36
|
-
return new NextResponse(null, { status: 500 });
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return new NextResponse();
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
function createNextAuthOptions(options) {
|
|
44
|
-
if (_nextAuth)
|
|
45
|
-
return _nextAuth;
|
|
46
|
-
_nextAuth = {
|
|
47
|
-
...options.nextAuth,
|
|
48
|
-
providers: [
|
|
49
|
-
KeycloakProvider({
|
|
50
|
-
issuer: `${options.keycloak?.baseUrl || defaults.keycloak.baseUrl}/realms/${options.keycloak?.realm || defaults.keycloak.realm}`,
|
|
51
|
-
...options.keycloak
|
|
52
|
-
}),
|
|
53
|
-
...options.nextAuth?.providers || []
|
|
54
|
-
],
|
|
55
|
-
callbacks: {
|
|
56
|
-
...options.nextAuth?.callbacks,
|
|
57
|
-
async jwt(params) {
|
|
58
|
-
if (typeof options.nextAuth?.callbacks?.jwt === "function") {
|
|
59
|
-
return options.nextAuth?.callbacks.jwt(params);
|
|
60
|
-
}
|
|
61
|
-
const { token, account } = params;
|
|
62
|
-
if (account) {
|
|
63
|
-
const decoded = jwtDecode(account.access_token || "");
|
|
64
|
-
token.decoded = decoded;
|
|
65
|
-
token.accessToken = account.access_token;
|
|
66
|
-
token.idToken = account.id_token;
|
|
67
|
-
token.expiresAt = account.expires_at;
|
|
68
|
-
token.refreshToken = account.refresh_token;
|
|
69
|
-
token.roles = decoded.realm_access?.roles;
|
|
70
|
-
return token;
|
|
71
|
-
} else if (Math.floor(Date.now() / 1e3) < Number(token.expiresAt)) {
|
|
72
|
-
return token;
|
|
73
|
-
} else {
|
|
74
|
-
try {
|
|
75
|
-
return refreshAccessToken(options, token);
|
|
76
|
-
} catch (err) {
|
|
77
|
-
return { ...token, err };
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
async session(params) {
|
|
82
|
-
if (typeof options.nextAuth?.callbacks?.session === "function") {
|
|
83
|
-
return options.nextAuth.callbacks.session(params);
|
|
84
|
-
}
|
|
85
|
-
const { session: nextSession, token: nextToken } = params;
|
|
86
|
-
const session = nextSession;
|
|
87
|
-
const token = nextToken;
|
|
88
|
-
if (token.accessToken)
|
|
89
|
-
session.accessToken = token.accessToken;
|
|
90
|
-
if (token.idToken)
|
|
91
|
-
session.idToken = token.idToken;
|
|
92
|
-
session.err = token.err;
|
|
93
|
-
return session;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
return _nextAuth;
|
|
98
|
-
}
|
|
99
|
-
async function refreshAccessToken(options, nextToken) {
|
|
100
|
-
const res = await fetch(
|
|
101
|
-
`${options.keycloak?.baseUrl || defaults.keycloak.baseUrl}/realms/${options.keycloak?.realm || defaults.keycloak.realm}/protocol/openid-connect/token`,
|
|
102
|
-
{
|
|
103
|
-
method: "POST",
|
|
104
|
-
headers: {
|
|
105
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
106
|
-
},
|
|
107
|
-
body: new URLSearchParams({
|
|
108
|
-
client_id: options.keycloak.clientId,
|
|
109
|
-
client_secret: options.keycloak.clientSecret,
|
|
110
|
-
grant_type: "refresh_token",
|
|
111
|
-
refresh_token: nextToken.refreshToken
|
|
112
|
-
})
|
|
113
|
-
}
|
|
114
|
-
);
|
|
115
|
-
const refreshToken = await res.json();
|
|
116
|
-
if (!res.ok)
|
|
117
|
-
throw refreshToken;
|
|
118
|
-
return {
|
|
119
|
-
...nextToken,
|
|
120
|
-
accessToken: refreshToken.access_token,
|
|
121
|
-
decoded: jwtDecode(refreshToken.access_token),
|
|
122
|
-
expiresAt: Math.floor(Date.now() / 1e3) + Number(refreshToken.expires_in),
|
|
123
|
-
idToken: refreshToken.id_token,
|
|
124
|
-
refreshToken: refreshToken.refresh_token
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
export {
|
|
128
|
-
createAuthHandler,
|
|
129
|
-
createLogoutHandler,
|
|
130
|
-
createNextAuthOptions
|
|
131
|
-
};
|
package/lib/session/index.d.mts
DELETED
package/lib/session/index.d.ts
DELETED
package/lib/session/index.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../chunk-WS4IMGVL.js');
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var _chunk2VGMJ7WPjs = require('../chunk-2VGMJ7WP.js');
|
|
6
|
-
require('../chunk-P57PW2II.js');
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
exports.getSession = _chunk2VGMJ7WPjs.getSession; exports.useSession = _chunk2VGMJ7WPjs.useSession;
|
package/lib/session/index.mjs
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { AuthOptions, Session as Session$1 } from 'next-auth';
|
|
2
|
-
import { GetSessionParams, SessionContextValue as SessionContextValue$1, UseSessionOptions } from 'next-auth/react';
|
|
3
|
-
|
|
4
|
-
declare function getSession(options?: AuthOptions | GetSessionParams, req?: any, res?: any): Promise<Session | null>;
|
|
5
|
-
type SessionContextValue<R extends boolean> = Partial<Omit<SessionContextValue$1<R> & {
|
|
6
|
-
session: Session;
|
|
7
|
-
}, 'data'>>;
|
|
8
|
-
declare let useSession: <R extends boolean>(options?: UseSessionOptions<R> | undefined) => Partial<Omit<SessionContextValue$1<R> & {
|
|
9
|
-
session: Session;
|
|
10
|
-
}, "data">>;
|
|
11
|
-
interface Session extends Session$1 {
|
|
12
|
-
accessToken?: string;
|
|
13
|
-
err?: Error;
|
|
14
|
-
idToken?: string;
|
|
15
|
-
refreshToken?: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export { type Session, type SessionContextValue, getSession, useSession };
|
package/lib/session/session.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { AuthOptions, Session as Session$1 } from 'next-auth';
|
|
2
|
-
import { GetSessionParams, SessionContextValue as SessionContextValue$1, UseSessionOptions } from 'next-auth/react';
|
|
3
|
-
|
|
4
|
-
declare function getSession(options?: AuthOptions | GetSessionParams, req?: any, res?: any): Promise<Session | null>;
|
|
5
|
-
type SessionContextValue<R extends boolean> = Partial<Omit<SessionContextValue$1<R> & {
|
|
6
|
-
session: Session;
|
|
7
|
-
}, 'data'>>;
|
|
8
|
-
declare let useSession: <R extends boolean>(options?: UseSessionOptions<R> | undefined) => Partial<Omit<SessionContextValue$1<R> & {
|
|
9
|
-
session: Session;
|
|
10
|
-
}, "data">>;
|
|
11
|
-
interface Session extends Session$1 {
|
|
12
|
-
accessToken?: string;
|
|
13
|
-
err?: Error;
|
|
14
|
-
idToken?: string;
|
|
15
|
-
refreshToken?: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export { type Session, type SessionContextValue, getSession, useSession };
|
package/lib/session/session.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var _chunk2VGMJ7WPjs = require('../chunk-2VGMJ7WP.js');
|
|
5
|
-
require('../chunk-P57PW2II.js');
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
exports.getSession = _chunk2VGMJ7WPjs.getSession; exports.useSession = _chunk2VGMJ7WPjs.useSession;
|
package/lib/session/session.mjs
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { SessionContextValue } from './session.mjs';
|
|
2
|
-
import { UseSessionOptions } from 'next-auth/react';
|
|
3
|
-
import 'next-auth';
|
|
4
|
-
|
|
5
|
-
declare function getSession(): Promise<null>;
|
|
6
|
-
declare function useSession<R extends boolean>(_options?: UseSessionOptions<R>): SessionContextValue<R>;
|
|
7
|
-
|
|
8
|
-
export { getSession, useSession };
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { SessionContextValue } from './session.js';
|
|
2
|
-
import { UseSessionOptions } from 'next-auth/react';
|
|
3
|
-
import 'next-auth';
|
|
4
|
-
|
|
5
|
-
declare function getSession(): Promise<null>;
|
|
6
|
-
declare function useSession<R extends boolean>(_options?: UseSessionOptions<R>): SessionContextValue<R>;
|
|
7
|
-
|
|
8
|
-
export { getSession, useSession };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../chunk-P57PW2II.js');
|
|
2
|
-
|
|
3
|
-
// src/session/session.native.ts
|
|
4
|
-
async function getSession() {
|
|
5
|
-
return null;
|
|
6
|
-
}
|
|
7
|
-
function useSession(_options) {
|
|
8
|
-
return {};
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
exports.getSession = getSession; exports.useSession = useSession;
|
package/lib/state.d.mts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
declare const persist: boolean;
|
|
2
|
-
declare function useAuthState(): {
|
|
3
|
-
idToken: string;
|
|
4
|
-
refreshToken: string;
|
|
5
|
-
token: string;
|
|
6
|
-
} & {
|
|
7
|
-
setIdToken: (value: string) => void;
|
|
8
|
-
setRefreshToken: (value: string) => void;
|
|
9
|
-
setToken: (value: string) => void;
|
|
10
|
-
} & Record<string, Function>;
|
|
11
|
-
|
|
12
|
-
export { persist, useAuthState };
|
package/lib/state.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
declare const persist: boolean;
|
|
2
|
-
declare function useAuthState(): {
|
|
3
|
-
idToken: string;
|
|
4
|
-
refreshToken: string;
|
|
5
|
-
token: string;
|
|
6
|
-
} & {
|
|
7
|
-
setIdToken: (value: string) => void;
|
|
8
|
-
setRefreshToken: (value: string) => void;
|
|
9
|
-
setToken: (value: string) => void;
|
|
10
|
-
} & Record<string, Function>;
|
|
11
|
-
|
|
12
|
-
export { persist, useAuthState };
|
package/lib/state.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var _chunkA2V2S4HPjs = require('./chunk-A2V2S4HP.js');
|
|
5
|
-
require('./chunk-P57PW2II.js');
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
exports.persist = _chunkA2V2S4HPjs.persist; exports.useAuthState = _chunkA2V2S4HPjs.useAuthState;
|
package/lib/state.mjs
DELETED
package/lib/token.d.mts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { KeycloakTokenParsed } from 'keycloak-js';
|
|
2
|
-
|
|
3
|
-
declare function validToken(token?: string | boolean, refreshToken?: string | boolean): string | boolean | undefined;
|
|
4
|
-
declare function isTokenValid(token: string): boolean;
|
|
5
|
-
interface TokenParsed extends KeycloakTokenParsed {
|
|
6
|
-
jti?: string;
|
|
7
|
-
sid?: string;
|
|
8
|
-
typ?: 'Bearer' | string;
|
|
9
|
-
}
|
|
10
|
-
interface AccessTokenParsed extends TokenParsed {
|
|
11
|
-
email?: string;
|
|
12
|
-
email_verified?: boolean;
|
|
13
|
-
preferred_username?: string;
|
|
14
|
-
scope?: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export { type AccessTokenParsed, type TokenParsed, isTokenValid, validToken };
|
package/lib/token.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { KeycloakTokenParsed } from 'keycloak-js';
|
|
2
|
-
|
|
3
|
-
declare function validToken(token?: string | boolean, refreshToken?: string | boolean): string | boolean | undefined;
|
|
4
|
-
declare function isTokenValid(token: string): boolean;
|
|
5
|
-
interface TokenParsed extends KeycloakTokenParsed {
|
|
6
|
-
jti?: string;
|
|
7
|
-
sid?: string;
|
|
8
|
-
typ?: 'Bearer' | string;
|
|
9
|
-
}
|
|
10
|
-
interface AccessTokenParsed extends TokenParsed {
|
|
11
|
-
email?: string;
|
|
12
|
-
email_verified?: boolean;
|
|
13
|
-
preferred_username?: string;
|
|
14
|
-
scope?: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export { type AccessTokenParsed, type TokenParsed, isTokenValid, validToken };
|
package/lib/token.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var _chunk2VDDEPLFjs = require('./chunk-2VDDEPLF.js');
|
|
5
|
-
require('./chunk-P57PW2II.js');
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
exports.isTokenValid = _chunk2VDDEPLFjs.isTokenValid; exports.validToken = _chunk2VDDEPLFjs.validToken;
|
package/lib/token.mjs
DELETED
package/lib/types.d.mts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
declare global {
|
|
2
|
-
interface Window {
|
|
3
|
-
ReactNativeWebView: {
|
|
4
|
-
postMessage: (body: string) => unknown;
|
|
5
|
-
};
|
|
6
|
-
webkit: {
|
|
7
|
-
messageHandlers: {
|
|
8
|
-
[key: string]: {
|
|
9
|
-
postMessage: (body: string) => unknown;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
interface KeycloakMock {
|
|
16
|
-
email?: string;
|
|
17
|
-
username: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export type { KeycloakMock };
|
package/lib/types.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
declare global {
|
|
2
|
-
interface Window {
|
|
3
|
-
ReactNativeWebView: {
|
|
4
|
-
postMessage: (body: string) => unknown;
|
|
5
|
-
};
|
|
6
|
-
webkit: {
|
|
7
|
-
messageHandlers: {
|
|
8
|
-
[key: string]: {
|
|
9
|
-
postMessage: (body: string) => unknown;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
interface KeycloakMock {
|
|
16
|
-
email?: string;
|
|
17
|
-
username: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export type { KeycloakMock };
|
package/lib/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";require('./chunk-6F4PWJZI.js');
|
package/lib/types.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "./chunk-WBQAMGXK.mjs";
|