Skip to content

Commit

Permalink
Add OIDC with Passage2
Browse files Browse the repository at this point in the history
  • Loading branch information
thomashbrnrd committed Jun 19, 2024
1 parent a8d1eef commit 1fdf389
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VUE_APP_OIDC_AUTHORITY=http://localhost:8080/realms/master/
VUE_APP_OIDC_CLIENT_ID=basegun
2 changes: 2 additions & 0 deletions .env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VUE_APP_OIDC_AUTHORITY=https://auth.sso.interieur.rie.gouv.fr/.well-known/openid-configuration
VUE_APP_OIDC_CLIENT_ID=basegun
10 changes: 9 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ services:
target: ${BUILD_TARGET:-dev}
container_name: basegun-frontend
ports:
- 8080:80 # if BUILD_TARGET = prod
- 3000:5173
volumes:
- ./frontend/src:/app/src
Expand All @@ -49,3 +48,12 @@ services:
ports:
- 9000:9000
- 9001:9001

keycloak:
image: quay.io/keycloak/keycloak:25.0.0
command: start-dev
environment:
- KEYCLOAK_ADMIN=admin
- KEYCLOAK_ADMIN_PASSWORD=password
ports:
- 8080:8080
3 changes: 2 additions & 1 deletion frontend/.eslintrc-auto-import.json
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@
"provideLocal": true,
"useClipboardItems": true,
"useScheme": true,
"useTabs": true
"useTabs": true,
"useStore": true
}
}
64 changes: 60 additions & 4 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@gouvminint/vue-dsfr": "^5.8.0",
"axios": "^1.6.7",
"luxon": "^3.4.4",
"oidc-client-ts": "^3.0.1",
"pinia": "^2.1.7",
"pinia-plugin-persistedstate": "^3.2.1",
"swiper": "^11.0.6",
Expand Down
18 changes: 3 additions & 15 deletions frontend/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,14 @@ export {}

declare module "vue" {
export interface GlobalComponents {
AccessibilityPage: (typeof import("./components/AccessibilityPage.vue"))["default"];
AskingExpert: (typeof import("./components/AskingExpert.vue"))["default"];
AuthCallback: (typeof import("./components/authentication/AuthCallback.vue"))["default"];
AuthRedirect: (typeof import("./components/authentication/AuthRedirect.vue"))["default"];
ContactExpert: (typeof import("./components/ContactExpert.vue"))["default"];
DsfrAccordion: (typeof import("@gouvminint/vue-dsfr"))["DsfrAccordion"];
DsfrAccordionsGroup: (typeof import("@gouvminint/vue-dsfr"))["DsfrAccordionsGroup"];
DsfrAlert: (typeof import("@gouvminint/vue-dsfr"))["DsfrAlert"];
DsfrButton: (typeof import("@gouvminint/vue-dsfr"))["DsfrButton"];
DsfrCheckbox: (typeof import("@gouvminint/vue-dsfr"))["DsfrCheckbox"];
DsfrFileUpload: (typeof import("@gouvminint/vue-dsfr"))["DsfrFileUpload"];
DsfrHeader: (typeof import("@gouvminint/vue-dsfr"))["DsfrHeader"];
DsfrInput: (typeof import("@gouvminint/vue-dsfr"))["DsfrInput"];
DsfrInputGroup: (typeof import("@gouvminint/vue-dsfr"))["DsfrInputGroup"];
DsfrModal: (typeof import("@gouvminint/vue-dsfr"))["DsfrModal"];
DsfrPicture: (typeof import("@gouvminint/vue-dsfr"))["DsfrPicture"];
DsfrRadioButton: (typeof import("@gouvminint/vue-dsfr"))["DsfrRadioButton"];
DsfrRadioButtonSet: (typeof import("@gouvminint/vue-dsfr"))["DsfrRadioButtonSet"];
DsfrSelect: (typeof import("@gouvminint/vue-dsfr"))["DsfrSelect"];
DsfrTable: (typeof import("@gouvminint/vue-dsfr"))["DsfrTable"];
DsfrTag: (typeof import("@gouvminint/vue-dsfr"))["DsfrTag"];
FooterMES: (typeof import("./components/FooterMES.vue"))["default"];
HeaderMain: (typeof import("./components/HeaderMain.vue"))["default"];
MissingCardAlert: (typeof import("./components/MissingCardAlert.vue"))["default"];
OnboardingSwiper: (typeof import("./components/OnboardingSwiper.vue"))["default"];
Expand All @@ -35,9 +23,9 @@ declare module "vue" {
ResultPage: (typeof import("./components/ResultPage.vue"))["default"];
RouterLink: (typeof import("vue-router"))["RouterLink"];
RouterView: (typeof import("vue-router"))["RouterView"];
SigninRedirect: (typeof import("./components/authentication/SigninRedirect.vue"))["default"];
SnackbarAlert: (typeof import("./components/SnackbarAlert.vue"))["default"];
StepsGuide: (typeof import("./components/StepsGuide.vue"))["default"];
UploadButton: (typeof import("./components/UploadButton.vue"))["default"];
VIcon: (typeof import("oh-vue-icons"))["OhVueIcon"];
}
}
6 changes: 6 additions & 0 deletions frontend/src/components/authentication/AuthCallback.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script setup>
import { mgr } from "@/utils/authentication";
mgr.signinCallback();
mgr.getUser().then((user) => console.log(user));
</script>
5 changes: 5 additions & 0 deletions frontend/src/components/authentication/AuthRedirect.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script setup>
import { mgr } from "@/utils/authentication";
mgr.signinRedirect();
</script>
20 changes: 20 additions & 0 deletions frontend/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ const IdentificationBlankGun = () =>
const ExpertSituation = () =>
import("@/views/GuideContactExpert/ExpertSituation.vue");

const AuthRedirect = () =>
import("@/components/authentication/AuthRedirect.vue");
const AuthCallback = () =>
import("@/components/authentication/AuthCallback.vue");

const routes: RouteRecordRaw[] = [
{
path: "/",
Expand Down Expand Up @@ -205,6 +210,21 @@ const routes: RouteRecordRaw[] = [
name: "ExpertSituationGN",
component: ExpertSituation,
},
{
path: "/auth",
children: [
{
path: "redirect",
name: "AuthRedirect",
component: AuthRedirect,
},
{
path: "callback",
name: "AuthCallback",
component: AuthCallback,
},
],
},
];

const router = createRouter({
Expand Down
15 changes: 15 additions & 0 deletions frontend/src/utils/authentication.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { UserManager } from "oidc-client-ts";

const FRONTEND_URL = window.location.origin;

export const mgr = new UserManager({
authority: process.env.VUE_APP_OIDC_AUTHORITY,
client_id: process.env.VUE_APP_OIDC_CLIENT_ID,
redirect_uri: `${FRONTEND_URL}/auth/callback`,
silent_redirect_uri: `${FRONTEND_URL}/auth/callback`,
post_logout_redirect_uri: `${FRONTEND_URL}`,
response_type: "code",
});
mgr.events.addAccessTokenExpiring(function () {
console.log("token expiring...");
});

0 comments on commit 1fdf389

Please sign in to comment.