This repository has been archived on 2024-02-08. You can view files and clone it, but cannot push or open issues or pull requests.
frontend/src/helpers/redirectToProvider.ts
kolaente e98e5a0d2f
All checks were successful
continuous-integration/drone/push Build is passing
fix(openid): use the full path when building the redirect url, not only the host
Resolves vikunja/api#1661
2023-12-20 13:23:56 +01:00

20 lines
877 B
TypeScript

import {createRandomID} from '@/helpers/randomId'
import type {IProvider} from '@/types/IProvider'
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.
const redirectUrl = `${window.location.href.replace('/login', '')}/auth/openid/`
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}`
}
export const redirectToProviderOnLogout = (provider: IProvider) => {
if (provider.logoutUrl.length > 0) {
window.location.href = `${provider.logoutUrl}`
}
}