fix(openid): use the full path when building the redirect url, not only the host
continuous-integration/drone/push Build is passing Details

Resolves vikunja/api#1661
This commit is contained in:
kolaente 2023-12-20 13:23:02 +01:00
parent 21e34d6d54
commit e98e5a0d2f
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 4 additions and 9 deletions

View File

@ -1,16 +1,11 @@
import {parseURL} from 'ufo'
import {createRandomID} from '@/helpers/randomId'
import type {IProvider} from '@/types/IProvider'
export const redirectToProvider = (provider: IProvider, redirectUrl = '') => {
export const redirectToProvider = (provider: IProvider) => {
// We're not using the redirect url provided by the server to allow redirects when using the electron app.
// The implications are not quite clear yet hence the logic to pass in another redirect url still exists.
if (redirectUrl === '') {
const {host, protocol} = parseURL(window.location.href)
redirectUrl = `${protocol}//${host}/auth/openid/`
}
const redirectUrl = `${window.location.href.replace('/login', '')}/auth/openid/`
const state = createRandomID(24)
localStorage.setItem('state', state)
@ -18,7 +13,7 @@ export const redirectToProvider = (provider: IProvider, redirectUrl = '') => {
window.location.href = `${provider.authUrl}?client_id=${provider.clientId}&redirect_uri=${redirectUrl}${provider.key}&response_type=code&scope=openid email profile&state=${state}`
}
export const redirectToProviderOnLogout = (provider: IProvider) => {
if (provider.logoutUrl.length > 0){
if (provider.logoutUrl.length > 0) {
window.location.href = `${provider.logoutUrl}`
}
}

View File

@ -27,7 +27,7 @@ function redirectToProviderIfNothingElseIsEnabled() {
(window.location.pathname.startsWith('/login') || window.location.pathname === '/') && // Kinda hacky, but prevents an endless loop.
window.location.search.includes('redirectToProvider=true')
) {
redirectToProvider(auth.openidConnect.providers[0], auth.openidConnect.redirectUrl)
redirectToProvider(auth.openidConnect.providers[0])
}
}