next-auth-heksso 1.1.7 → 1.1.8
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 +7 -7
- package/react/KeycloakSessionContext.d.ts +16 -2
- package/react/KeycloakSessionContext.js +16 -12
- package/src/react/KeycloakSessionContext.tsx +24 -11
- package/.env.example +0 -5
- package/.idea/checkstyle-idea.xml +0 -15
- package/.idea/codeStyles/Project.xml +0 -55
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/jpa-buddy.xml +0 -6
- package/.idea/misc.xml +0 -9
- package/.idea/modules.xml +0 -8
- package/.idea/next-auth-heksso.iml +0 -9
- package/.idea/prettier.xml +0 -7
- package/.idea/vcs.xml +0 -6
package/package.json
CHANGED
|
@@ -5,12 +5,7 @@
|
|
|
5
5
|
"email": "contact@voakie.com"
|
|
6
6
|
},
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"version": "1.1.
|
|
9
|
-
"scripts": {
|
|
10
|
-
"prepublish": "rm api/ -r && rm react/ -r && tsc",
|
|
11
|
-
"build": "tsc",
|
|
12
|
-
"clean": "rm api/ -r && rm react/ -r -r"
|
|
13
|
-
},
|
|
8
|
+
"version": "1.1.8",
|
|
14
9
|
"main": "api/index.js",
|
|
15
10
|
"types": "api/index.d.ts",
|
|
16
11
|
"dependencies": {
|
|
@@ -24,5 +19,10 @@
|
|
|
24
19
|
"react": "^18.2.0",
|
|
25
20
|
"react-dom": "^18.2.0",
|
|
26
21
|
"typescript": "^4.9.4"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"prepublish": "rm api/ -r && rm react/ -r && tsc",
|
|
25
|
+
"build": "tsc",
|
|
26
|
+
"clean": "rm api/ -r && rm react/ -r -r"
|
|
27
27
|
}
|
|
28
|
-
}
|
|
28
|
+
}
|
|
@@ -1,10 +1,24 @@
|
|
|
1
|
+
import type { signOut as nextAuthSignOut, useSession } from "next-auth/react";
|
|
2
|
+
import { NextRouter } from "next/router";
|
|
1
3
|
import React, { PropsWithChildren } from "react";
|
|
4
|
+
type NextAuthSession = ReturnType<typeof useSession>;
|
|
2
5
|
export interface KeycloakSession {
|
|
3
6
|
accessTokenError: boolean;
|
|
4
7
|
getAccessToken: () => Promise<string>;
|
|
5
8
|
}
|
|
6
9
|
export declare const KeycloakSessionContext: React.Context<KeycloakSession>;
|
|
7
10
|
export declare function useKeycloakSession(): KeycloakSession;
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Provider for the useKeycloakSession react hook. Has to directly hook into next-auth and next/router
|
|
13
|
+
* @param router Next.js router (retrieve with `useRouter()`)
|
|
14
|
+
* @param session Next Auth Session (retrieve with `useSession()`)
|
|
15
|
+
* @param signOut Next Auth Sign Out function (exported by "next-auth/react")
|
|
16
|
+
* @param children
|
|
17
|
+
* @constructor
|
|
18
|
+
*/
|
|
19
|
+
export declare function KeycloakSessionProvider({ router, session, signOut, children }: PropsWithChildren<{
|
|
20
|
+
session: NextAuthSession;
|
|
21
|
+
router: NextRouter;
|
|
22
|
+
signOut: typeof nextAuthSignOut;
|
|
10
23
|
}>): JSX.Element;
|
|
24
|
+
export {};
|
|
@@ -33,17 +33,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
33
33
|
};
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
35
|
exports.KeycloakSessionProvider = exports.useKeycloakSession = exports.KeycloakSessionContext = void 0;
|
|
36
|
-
const react_1 = require("
|
|
37
|
-
|
|
38
|
-
const react_2 = __importStar(require("react"));
|
|
39
|
-
exports.KeycloakSessionContext = (0, react_2.createContext)({
|
|
36
|
+
const react_1 = __importStar(require("react"));
|
|
37
|
+
exports.KeycloakSessionContext = (0, react_1.createContext)({
|
|
40
38
|
accessTokenError: false,
|
|
41
39
|
getAccessToken: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
40
|
return "";
|
|
43
41
|
})
|
|
44
42
|
});
|
|
45
43
|
function useKeycloakSession() {
|
|
46
|
-
return (0,
|
|
44
|
+
return (0, react_1.useContext)(exports.KeycloakSessionContext);
|
|
47
45
|
}
|
|
48
46
|
exports.useKeycloakSession = useKeycloakSession;
|
|
49
47
|
function refreshAccessToken() {
|
|
@@ -68,14 +66,20 @@ function refreshAccessToken() {
|
|
|
68
66
|
}
|
|
69
67
|
});
|
|
70
68
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Provider for the useKeycloakSession react hook. Has to directly hook into next-auth and next/router
|
|
71
|
+
* @param router Next.js router (retrieve with `useRouter()`)
|
|
72
|
+
* @param session Next Auth Session (retrieve with `useSession()`)
|
|
73
|
+
* @param signOut Next Auth Sign Out function (exported by "next-auth/react")
|
|
74
|
+
* @param children
|
|
75
|
+
* @constructor
|
|
76
|
+
*/
|
|
77
|
+
function KeycloakSessionProvider({ router, session, signOut, children }) {
|
|
78
|
+
return (react_1.default.createElement(_KeycloakSessionProvider, { session: session, router: router, signOut: signOut }, children));
|
|
75
79
|
}
|
|
76
80
|
exports.KeycloakSessionProvider = KeycloakSessionProvider;
|
|
77
81
|
// Proxy class component to prevent unnecessary re-renders
|
|
78
|
-
class _KeycloakSessionProvider extends
|
|
82
|
+
class _KeycloakSessionProvider extends react_1.Component {
|
|
79
83
|
constructor(props) {
|
|
80
84
|
super(props);
|
|
81
85
|
this.state = {
|
|
@@ -136,7 +140,7 @@ class _KeycloakSessionProvider extends react_2.Component {
|
|
|
136
140
|
const { error, accessToken, accessTokenExpires } = this.props.session.data;
|
|
137
141
|
if (error === "RefreshAccessTokenError") {
|
|
138
142
|
// Force sign in to get a new refresh token
|
|
139
|
-
|
|
143
|
+
this.props.signOut({ redirect: true, callbackUrl: "/" }).then();
|
|
140
144
|
}
|
|
141
145
|
else if (accessToken && accessToken != this.state.accessToken) {
|
|
142
146
|
this.setState({
|
|
@@ -153,7 +157,7 @@ class _KeycloakSessionProvider extends react_2.Component {
|
|
|
153
157
|
}
|
|
154
158
|
}
|
|
155
159
|
render() {
|
|
156
|
-
return (
|
|
160
|
+
return (react_1.default.createElement(exports.KeycloakSessionContext.Provider, { value: this.getContextValue() }, this.props.children));
|
|
157
161
|
}
|
|
158
162
|
}
|
|
159
163
|
function sessionDataGuard(sessionData) {
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { signOut, useSession } from "next-auth/react"
|
|
2
|
-
import { NextRouter
|
|
1
|
+
import type { signOut as nextAuthSignOut, useSession } from "next-auth/react"
|
|
2
|
+
import { NextRouter } from "next/router"
|
|
3
3
|
import React, { Component, createContext, PropsWithChildren, useContext } from "react"
|
|
4
4
|
|
|
5
|
+
type NextAuthSession = ReturnType<typeof useSession>
|
|
6
|
+
|
|
5
7
|
export interface KeycloakSession {
|
|
6
8
|
accessTokenError: boolean
|
|
7
9
|
getAccessToken: () => Promise<string>
|
|
@@ -14,7 +16,7 @@ export const KeycloakSessionContext = createContext<KeycloakSession>({
|
|
|
14
16
|
}
|
|
15
17
|
})
|
|
16
18
|
|
|
17
|
-
export function useKeycloakSession() {
|
|
19
|
+
export function useKeycloakSession(): KeycloakSession {
|
|
18
20
|
return useContext(KeycloakSessionContext)
|
|
19
21
|
}
|
|
20
22
|
|
|
@@ -44,7 +46,7 @@ async function refreshAccessToken() {
|
|
|
44
46
|
interface KeycloakSessionProviderProps {
|
|
45
47
|
session: ReturnType<typeof useSession>
|
|
46
48
|
router: NextRouter
|
|
47
|
-
|
|
49
|
+
signOut: typeof nextAuthSignOut
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
interface KeycloakSessionProviderState {
|
|
@@ -53,15 +55,26 @@ interface KeycloakSessionProviderState {
|
|
|
53
55
|
accessTokenExpires?: number
|
|
54
56
|
}
|
|
55
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Provider for the useKeycloakSession react hook. Has to directly hook into next-auth and next/router
|
|
60
|
+
* @param router Next.js router (retrieve with `useRouter()`)
|
|
61
|
+
* @param session Next Auth Session (retrieve with `useSession()`)
|
|
62
|
+
* @param signOut Next Auth Sign Out function (exported by "next-auth/react")
|
|
63
|
+
* @param children
|
|
64
|
+
* @constructor
|
|
65
|
+
*/
|
|
56
66
|
export function KeycloakSessionProvider({
|
|
57
|
-
|
|
67
|
+
router,
|
|
68
|
+
session,
|
|
69
|
+
signOut,
|
|
58
70
|
children
|
|
59
|
-
}: PropsWithChildren<{
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
71
|
+
}: PropsWithChildren<{
|
|
72
|
+
session: NextAuthSession
|
|
73
|
+
router: NextRouter
|
|
74
|
+
signOut: typeof nextAuthSignOut
|
|
75
|
+
}>) {
|
|
63
76
|
return (
|
|
64
|
-
<_KeycloakSessionProvider session={session} router={router}
|
|
77
|
+
<_KeycloakSessionProvider session={session} router={router} signOut={signOut}>
|
|
65
78
|
{children}
|
|
66
79
|
</_KeycloakSessionProvider>
|
|
67
80
|
)
|
|
@@ -143,7 +156,7 @@ class _KeycloakSessionProvider extends Component<
|
|
|
143
156
|
|
|
144
157
|
if (error === "RefreshAccessTokenError") {
|
|
145
158
|
// Force sign in to get a new refresh token
|
|
146
|
-
signOut({ redirect: true, callbackUrl: "/" }).then()
|
|
159
|
+
this.props.signOut({ redirect: true, callbackUrl: "/" }).then()
|
|
147
160
|
} else if (accessToken && accessToken != this.state.accessToken) {
|
|
148
161
|
this.setState({
|
|
149
162
|
accessToken,
|
package/.env.example
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
NEXTAUTH_URL=http://localhost:3000 # URL for this site
|
|
2
|
-
NEXTAUTH_SECRET=<Secret for Token generation. Enter a random string>
|
|
3
|
-
KEYCLOAK_CLIENT_ID=hekmoney
|
|
4
|
-
KEYCLOAK_CLIENT_SECRET=<Go to Keycloak -> Clients -> Credentials>
|
|
5
|
-
KEYCLOAK_ISSUER=http://localhost:8080/realms/master
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="CheckStyle-IDEA" serialisationVersion="2">
|
|
4
|
-
<checkstyleVersion>10.6.0</checkstyleVersion>
|
|
5
|
-
<scanScope>JavaOnly</scanScope>
|
|
6
|
-
<option name="thirdPartyClasspath" />
|
|
7
|
-
<option name="activeLocationIds" />
|
|
8
|
-
<option name="locations">
|
|
9
|
-
<list>
|
|
10
|
-
<ConfigurationLocation id="bundled-sun-checks" type="BUNDLED" scope="All" description="Sun Checks">(bundled)</ConfigurationLocation>
|
|
11
|
-
<ConfigurationLocation id="bundled-google-checks" type="BUNDLED" scope="All" description="Google Checks">(bundled)</ConfigurationLocation>
|
|
12
|
-
</list>
|
|
13
|
-
</option>
|
|
14
|
-
</component>
|
|
15
|
-
</project>
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
<component name="ProjectCodeStyleConfiguration">
|
|
2
|
-
<code_scheme name="Project" version="173">
|
|
3
|
-
<HTMLCodeStyleSettings>
|
|
4
|
-
<option name="HTML_SPACE_INSIDE_EMPTY_TAG" value="true" />
|
|
5
|
-
<option name="HTML_ENFORCE_QUOTES" value="true" />
|
|
6
|
-
</HTMLCodeStyleSettings>
|
|
7
|
-
<JSCodeStyleSettings version="0">
|
|
8
|
-
<option name="USE_SEMICOLON_AFTER_STATEMENT" value="false" />
|
|
9
|
-
<option name="FORCE_SEMICOLON_STYLE" value="true" />
|
|
10
|
-
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
|
|
11
|
-
<option name="FORCE_QUOTE_STYlE" value="true" />
|
|
12
|
-
<option name="ENFORCE_TRAILING_COMMA" value="Remove" />
|
|
13
|
-
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
|
|
14
|
-
<option name="SPACES_WITHIN_IMPORTS" value="true" />
|
|
15
|
-
</JSCodeStyleSettings>
|
|
16
|
-
<JetCodeStyleSettings>
|
|
17
|
-
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
|
18
|
-
</JetCodeStyleSettings>
|
|
19
|
-
<TypeScriptCodeStyleSettings version="0">
|
|
20
|
-
<option name="USE_SEMICOLON_AFTER_STATEMENT" value="false" />
|
|
21
|
-
<option name="FORCE_SEMICOLON_STYLE" value="true" />
|
|
22
|
-
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
|
|
23
|
-
<option name="FORCE_QUOTE_STYlE" value="true" />
|
|
24
|
-
<option name="ENFORCE_TRAILING_COMMA" value="Remove" />
|
|
25
|
-
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
|
|
26
|
-
<option name="SPACES_WITHIN_IMPORTS" value="true" />
|
|
27
|
-
</TypeScriptCodeStyleSettings>
|
|
28
|
-
<VueCodeStyleSettings>
|
|
29
|
-
<option name="INTERPOLATION_NEW_LINE_AFTER_START_DELIMITER" value="false" />
|
|
30
|
-
<option name="INTERPOLATION_NEW_LINE_BEFORE_END_DELIMITER" value="false" />
|
|
31
|
-
</VueCodeStyleSettings>
|
|
32
|
-
<codeStyleSettings language="HTML">
|
|
33
|
-
<option name="SOFT_MARGINS" value="100" />
|
|
34
|
-
<indentOptions>
|
|
35
|
-
<option name="CONTINUATION_INDENT_SIZE" value="4" />
|
|
36
|
-
</indentOptions>
|
|
37
|
-
</codeStyleSettings>
|
|
38
|
-
<codeStyleSettings language="JavaScript">
|
|
39
|
-
<option name="SOFT_MARGINS" value="100" />
|
|
40
|
-
</codeStyleSettings>
|
|
41
|
-
<codeStyleSettings language="TypeScript">
|
|
42
|
-
<option name="SOFT_MARGINS" value="100" />
|
|
43
|
-
</codeStyleSettings>
|
|
44
|
-
<codeStyleSettings language="Vue">
|
|
45
|
-
<option name="SOFT_MARGINS" value="100" />
|
|
46
|
-
<indentOptions>
|
|
47
|
-
<option name="INDENT_SIZE" value="4" />
|
|
48
|
-
<option name="TAB_SIZE" value="4" />
|
|
49
|
-
</indentOptions>
|
|
50
|
-
</codeStyleSettings>
|
|
51
|
-
<codeStyleSettings language="kotlin">
|
|
52
|
-
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
|
53
|
-
</codeStyleSettings>
|
|
54
|
-
</code_scheme>
|
|
55
|
-
</component>
|
package/.idea/jpa-buddy.xml
DELETED
package/.idea/misc.xml
DELETED
package/.idea/modules.xml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="ProjectModuleManager">
|
|
4
|
-
<modules>
|
|
5
|
-
<module fileurl="file://$PROJECT_DIR$/.idea/next-auth-heksso.iml" filepath="$PROJECT_DIR$/.idea/next-auth-heksso.iml" />
|
|
6
|
-
</modules>
|
|
7
|
-
</component>
|
|
8
|
-
</project>
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<module type="JAVA_MODULE" version="4">
|
|
3
|
-
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
4
|
-
<exclude-output />
|
|
5
|
-
<content url="file://$MODULE_DIR$" />
|
|
6
|
-
<orderEntry type="inheritedJdk" />
|
|
7
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
|
8
|
-
</component>
|
|
9
|
-
</module>
|
package/.idea/prettier.xml
DELETED