next-auth-heksso 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/lib/{next-api → api}/federatedLogout.d.ts +0 -0
- package/lib/{next-api → api}/federatedLogout.js +0 -0
- package/lib/{next-api → api}/index.d.ts +0 -0
- package/lib/{next-api → api}/index.js +0 -0
- package/lib/{next-api → api}/nextAuthConfig.d.ts +0 -0
- package/lib/{next-api → api}/nextAuthConfig.js +0 -0
- package/lib/{next-api → api}/refreshAccessToken.d.ts +0 -0
- package/lib/{next-api → api}/refreshAccessToken.js +0 -0
- package/lib/{next → react}/KeycloakSessionContext.d.ts +0 -0
- package/lib/{next → react}/KeycloakSessionContext.js +0 -0
- package/lib/{next → react}/index.d.ts +0 -0
- package/lib/{next → react}/index.js +0 -0
- package/package.json +4 -2
- package/src/{next-api → api}/federatedLogout.ts +0 -0
- package/src/{next-api → api}/index.ts +0 -0
- package/src/{next-api → api}/nextAuthConfig.ts +0 -0
- package/src/{next-api → api}/refreshAccessToken.ts +0 -0
- package/src/{next → react}/KeycloakSessionContext.tsx +0 -0
- package/src/{next → react}/index.ts +0 -0
- package/lib/index.d.ts +0 -2
- package/lib/index.js +0 -18
- package/lib/next/KeycloakSessionContext.jsx +0 -125
- package/src/index.ts +0 -2
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
"email": "contact@voakie.com"
|
|
6
6
|
},
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"version": "1.0.
|
|
8
|
+
"version": "1.0.1",
|
|
9
9
|
"scripts": {
|
|
10
|
-
"
|
|
10
|
+
"prepublish": "rm lib/ -r && tsc",
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"clean": "rm lib/ -r"
|
|
11
13
|
},
|
|
12
14
|
"main": "lib/index.js",
|
|
13
15
|
"types": "lib/index.d.ts",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/lib/index.d.ts
DELETED
package/lib/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./next"), exports);
|
|
18
|
-
__exportStar(require("./next-api"), exports);
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.KeycloakSessionProvider = exports.KeycloakSessionContext = void 0;
|
|
36
|
-
const react_1 = require("next-auth/react");
|
|
37
|
-
const router_1 = require("next/router");
|
|
38
|
-
const react_2 = __importStar(require("react"));
|
|
39
|
-
exports.KeycloakSessionContext = (0, react_2.createContext)({
|
|
40
|
-
getAccessToken: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
-
return "";
|
|
42
|
-
})
|
|
43
|
-
});
|
|
44
|
-
function refreshAccessToken() {
|
|
45
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
try {
|
|
47
|
-
const response = yield fetch("/api/auth/session", {
|
|
48
|
-
method: "GET",
|
|
49
|
-
headers: {
|
|
50
|
-
"Content-Type": "application/json"
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
const data = yield response.json();
|
|
54
|
-
if (data.error) {
|
|
55
|
-
throw data.error;
|
|
56
|
-
}
|
|
57
|
-
return { accessToken: data.accessToken, accessTokenExpires: data.accessTokenExpires };
|
|
58
|
-
}
|
|
59
|
-
catch (e) {
|
|
60
|
-
console.error(e);
|
|
61
|
-
return undefined;
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
function KeycloakSessionProvider(props) {
|
|
66
|
-
const session = (0, react_1.useSession)();
|
|
67
|
-
const router = (0, router_1.useRouter)();
|
|
68
|
-
const [accessToken, setAccessToken] = (0, react_2.useState)(undefined);
|
|
69
|
-
const [accessTokenError, setAccessTokenError] = (0, react_2.useState)(false);
|
|
70
|
-
const [accessTokenExpires, setAccessTokenExpires] = (0, react_2.useState)(undefined);
|
|
71
|
-
const getAccessToken = (0, react_2.useCallback)(() => __awaiter(this, void 0, void 0, function* () {
|
|
72
|
-
if (!accessToken)
|
|
73
|
-
return undefined;
|
|
74
|
-
if (accessTokenExpires && Date.now() >= accessTokenExpires) {
|
|
75
|
-
try {
|
|
76
|
-
const refreshed = yield refreshAccessToken();
|
|
77
|
-
if (refreshed) {
|
|
78
|
-
setAccessTokenError(false);
|
|
79
|
-
setAccessToken(refreshed.accessToken);
|
|
80
|
-
setAccessTokenExpires(refreshed.accessTokenExpires);
|
|
81
|
-
return refreshed.accessToken;
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
// Refresh failed due to network error
|
|
85
|
-
return undefined;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
catch (e) {
|
|
89
|
-
// Refresh failed because keycloak denied the request
|
|
90
|
-
console.error(e);
|
|
91
|
-
setAccessTokenError(true);
|
|
92
|
-
setAccessToken(undefined);
|
|
93
|
-
setAccessTokenExpires(undefined);
|
|
94
|
-
return undefined;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
else
|
|
98
|
-
return accessToken;
|
|
99
|
-
}), [accessToken, accessTokenExpires]);
|
|
100
|
-
// Because this component is present on every page that requires a session,
|
|
101
|
-
// we check for a valid refresh token here
|
|
102
|
-
(0, react_2.useEffect)(() => {
|
|
103
|
-
var _a, _b, _c, _d;
|
|
104
|
-
if (!router.asPath.startsWith(props.signInPage || "/auth/signin") &&
|
|
105
|
-
(session.status === "unauthenticated" || accessTokenError)) {
|
|
106
|
-
router.push(props.signInPage || "/auth/signin");
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
if (((_a = session.data) === null || _a === void 0 ? void 0 : _a.error) === "RefreshAccessTokenError") {
|
|
110
|
-
(0, react_1.signOut)(); // Force sign in to get a new refresh token
|
|
111
|
-
}
|
|
112
|
-
else if ((_b = session.data) === null || _b === void 0 ? void 0 : _b.accessToken) {
|
|
113
|
-
setAccessToken((_c = session.data) === null || _c === void 0 ? void 0 : _c.accessToken),
|
|
114
|
-
setAccessTokenExpires((_d = session.data) === null || _d === void 0 ? void 0 : _d.accessTokenExpires);
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
setAccessToken(undefined);
|
|
118
|
-
setAccessTokenExpires(undefined);
|
|
119
|
-
}
|
|
120
|
-
}, [session, router.pathname, accessToken, router, props.signInPage, accessTokenError]);
|
|
121
|
-
return (<exports.KeycloakSessionContext.Provider value={{ getAccessToken }}>
|
|
122
|
-
{props.children}
|
|
123
|
-
</exports.KeycloakSessionContext.Provider>);
|
|
124
|
-
}
|
|
125
|
-
exports.KeycloakSessionProvider = KeycloakSessionProvider;
|
package/src/index.ts
DELETED