Skip to content

Commit

Permalink
fix authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
RenauxLeaInsee committed Apr 19, 2024
1 parent 05c5701 commit d4fd326
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ USER nginx

# Start Nginx server
ENTRYPOINT sh -c "./vite-envs.sh && nginx -g 'daemon off;'"
RUN chmod -R 777 vite-envs.sh
RUN chmod +x vite-envs.sh
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sonor",
"private": true,
"version": "2.0.32",
"version": "2.0.33",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down Expand Up @@ -57,6 +57,7 @@
"typescript": "^5.2.2",
"vite": "^5.1.4",
"vite-tsconfig-paths": "^4.3.2",
"vitest": "^1.5.0"
"vitest": "^1.5.0",
"zod": "^3.22.5"
}
}
9 changes: 9 additions & 0 deletions public/silent-sso.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html>

<body>
<script>
parent.postMessage(location.href, location.origin);
</script>
</body>

</html>
34 changes: 26 additions & 8 deletions src/functions/oidc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createReactOidc } from "oidc-spa/react";
import { Fragment } from "react";

import { z } from "zod";
import { createReactOidc } from "oidc-spa/react";
import { createMockReactOidc } from "oidc-spa/mock/react";
type TokenInfo = {
inseegroupedefaut: string[];
preferred_username: string;
Expand All @@ -15,14 +16,31 @@ const guestUser: TokenInfo = {

const isOidc = import.meta.env.VITE_AUTH_TYPE === "oidc";

const decodedIdTokenSchema = z.object({
inseegroupedefaut: z.array(z.string()),
preferred_username: z.string(),
name: z.string(),
});

export const createAppOidc = () => {
if (isOidc) {
return createReactOidc<TokenInfo>({
issuerUri: import.meta.env.VITE_OIDC_ISSUER,
clientId: import.meta.env.VITE_OIDC_CLIENT_ID,
publicUrl: "/",
extraQueryParams: { kc_idp_hint: import.meta.env.VITE_IDENTITY_PROVIDER },
});
return !import.meta.env.VITE_OIDC_ISSUER
? createMockReactOidc<TokenInfo>({
isUserInitiallyLoggedIn: false,
mockedTokens: {
decodedIdToken: {
inseegroupedefaut: ["gr"],
preferred_username: "john doe",
name: "john",
} satisfies z.infer<typeof decodedIdTokenSchema>,
},
})
: createReactOidc<TokenInfo>({
issuerUri: import.meta.env.VITE_OIDC_ISSUER,
clientId: import.meta.env.VITE_OIDC_CLIENT_ID,
publicUrl: "/",
extraQueryParams: { kc_idp_hint: import.meta.env.VITE_IDENTITY_PROVIDER },
});
}

return {
Expand Down
12 changes: 8 additions & 4 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ import react from "@vitejs/plugin-react";
import type { InlineConfig } from "vitest";
import type { UserConfig } from "vite";
import tsconfigPaths from "vite-tsconfig-paths";
import { viteEnvs } from 'vite-envs'
import { viteEnvs } from "vite-envs";

type ViteConfig = UserConfig & { test: InlineConfig };

const config: ViteConfig = {
plugins: [react(), tsconfigPaths(), viteEnvs({
declarationFile: ".env"
})],
plugins: [
react(),
tsconfigPaths(),
viteEnvs({
declarationFile: ".env",
}),
],
test: {
globals: true,
environment: "jsdom",
Expand Down
11 changes: 8 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4278,9 +4278,9 @@ [email protected]:
jwt-decode "^3.1.2"

oidc-spa@^4.2.1:
version "4.2.1"
resolved "https://registry.yarnpkg.com/oidc-spa/-/oidc-spa-4.2.1.tgz#1b33214fd4b657f7a09aae70058df76ce7275a8e"
integrity sha512-2Vm3Ohrh+F6Xd+HfybBs20ahQmJf3w852G20hnOl80O7G8wQ2IBKuivVEU/gb2hg4O3X9h4uQr4fuhIMO0/dFA==
version "4.5.0"
resolved "https://registry.yarnpkg.com/oidc-spa/-/oidc-spa-4.5.0.tgz#eab4643f80006ad6d0db906e646241f64c88c304"
integrity sha512-3E32oaOaL2/NfJWyg7vjHPOb1SRe3q9oJ5OMSDcuF9AVZYbfgrKeCTvQcQhkxlIDLfZ4zKVQYVm45ft8Wj5W7w==
dependencies:
jwt-decode "^3.1.2"
oidc-client-ts "2.4.0"
Expand Down Expand Up @@ -5458,6 +5458,11 @@ yocto-queue@^1.0.0:
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-1.0.0.tgz#7f816433fb2cbc511ec8bf7d263c3b58a1a3c251"
integrity sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==

zod@^3.22.5:
version "3.22.5"
resolved "https://registry.yarnpkg.com/zod/-/zod-3.22.5.tgz#b9b09db03f6700b0d0b75bf0dbf0c5fc46155220"
integrity sha512-HqnGsCdVZ2xc0qWPLdO25WnseXThh0kEYKIdV5F/hTHO75hNZFp8thxSeHhiPrHZKrFTo1SOgkAj9po5bexZlw==

zustand@^4.5.2:
version "4.5.2"
resolved "https://registry.yarnpkg.com/zustand/-/zustand-4.5.2.tgz#fddbe7cac1e71d45413b3682cdb47b48034c3848"
Expand Down

0 comments on commit d4fd326

Please sign in to comment.