Skip to content

Commit

Permalink
wip: Add a Keycloak provider for OAuth (#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
claustres committed Dec 20, 2024
1 parent 203bc65 commit aab6574
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
14 changes: 13 additions & 1 deletion api/config/default.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ if (process.env.SUBDOMAIN) {
}
// On a developer machine will do domain = gateway = localhost
const gateway = (process.env.API_GATEWAY_URL ? process.env.API_GATEWAY_URL : domain.replace('kano', 'api'))
// Keycloak base url
const keycloakBaseUrl = `${process.env.KEYCLOAK_URL}/realms/${process.env.KEYCLOAK_REALM}/protocol/openid-connect`

// Just used for testing purpose now
apiLimiter = null
Expand Down Expand Up @@ -189,7 +191,17 @@ module.exports = {
redirect: domain + '/',
defaults: {
origin: domain
}
},
keycloak: (process.env.KEYCLOAK_CLIENT_ID ? {
key: process.env.KEYCLOAK_CLIENT_ID,
secret: process.env.KEYCLOAK_CLIENT_SECRET,
oauth: 2,
scope: ['openid'],
authorize_url: `${keycloakBaseUrl}/auth`,
access_url: `${keycloakBaseUrl}/token`,
profile_url: `${keycloakBaseUrl}/userinfo`,
nonce: true
} : undefined)
},
passwordPolicy: {
minLength: 8,
Expand Down
9 changes: 7 additions & 2 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function showError (error) {
logger.error(error)
return
}
const notification = { type: 'negative', message: error.message || error.error_message, html: true }
const notification = { type: 'negative', message: error.message || error.error_message || error.error, html: true }
// Check if user can retry to avoid this error
if (error.retryHandler) {
notification.actions = [{
Expand All @@ -55,9 +55,14 @@ function showError (error) {
}
function showRouteError (route) {
// We handle error on any page with query string
if (route.query && route.query.error_message) {
if (route.query && (route.query.error_message || route.query.error)) {
showError(route.query)
}
// OAuth login is using token set as route param like 'access_token=jwt'.
// However in case of error it will be like 'error=message' instead.
else if (route.params && route.params.token && route.params.token.startsWith('error=')) {
showError({ message: route.params.token.split('=')[1] })
}
}
function addRequest (hook) {
// Check if this request is a quiet one or not
Expand Down
1 change: 1 addition & 0 deletions src/i18n/app_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
}
},
"screen": {
"LOGIN_WITH_KEYCLOAK": "Login with Keycloak",
"ABOUT_KALISIO": "About",
"CONTACT": "Contact",
"TERMS_AND_POLICIES": "Terms and Policies"
Expand Down
1 change: 1 addition & 0 deletions src/i18n/app_fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
}
},
"screen": {
"LOGIN_WITH_KEYCLOAK": "Se connecter avec Keycloak",
"ABOUT_KALISIO": "A propos",
"CONTACT": "Contact",
"TERMS_AND_POLICIES": "Conditions générales"
Expand Down
2 changes: 1 addition & 1 deletion src/router/routes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const tours = require('../tours')

module.exports = [{
path: '/',
path: '/:token?',
name: 'index',
component: 'Index',
meta: { unauthenticated: true },
Expand Down

0 comments on commit aab6574

Please sign in to comment.