1
0

fix(openid): use the calculated redirect url when authenticating with openid providers

Resolves https://github.com/go-vikunja/desktop/issues/12
This commit is contained in:
kolaente
2024-01-28 12:42:39 +01:00
parent 394dbe0055
commit ee980e2a00
2 changed files with 19 additions and 5 deletions

View File

@ -2,17 +2,22 @@ import {createRandomID} from '@/helpers/randomId'
import type {IProvider} from '@/types/IProvider'
import {parseURL} from 'ufo'
export const redirectToProvider = (provider: IProvider) => {
export function getRedirectUrlFromCurrentFrontendPath(provider: IProvider): string {
// 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.
const url = parseURL(window.location.href)
const redirectUrl = `${url.protocol}//${url.host}/auth/openid/`
return `${url.protocol}//${url.host}/auth/openid/${provider.key}`
}
export const redirectToProvider = (provider: IProvider) => {
console.log({provider})
const redirectUrl = getRedirectUrlFromCurrentFrontendPath(provider)
const state = createRandomID(24)
localStorage.setItem('state', state)
window.location.href = `${provider.authUrl}?client_id=${provider.clientId}&redirect_uri=${redirectUrl}${provider.key}&response_type=code&scope=openid email profile&state=${state}`
window.location.href = `${provider.authUrl}?client_id=${provider.clientId}&redirect_uri=${redirectUrl}&response_type=code&scope=openid email profile&state=${state}`
}
export const redirectToProviderOnLogout = (provider: IProvider) => {
if (provider.logoutUrl.length > 0) {