Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Fix auth flow

Blue Mouse91badf1c0922
diff --git a/backend/apps/community/src/auth/auth.controller.ts b/backend/apps/community/src/auth/auth.controller.ts
index a700a6fdf..d7f623feb 100644
--- a/backend/apps/community/src/auth/auth.controller.ts
+++ b/backend/apps/community/src/auth/auth.controller.ts
@@ -196,10 +196,10 @@ export class AuthController {
const ip = getIPFromHeaders(headers) || reqIP || ''
await checkRateLimit(ip, 'oidc-process-token', 15, 1800)
- const { code, hash } = body
+ const { code, hash, redirectUrl } = body
try {
- await this.authService.processOidcToken(code, hash)
+ await this.authService.processOidcToken(code, hash, redirectUrl)
} catch (reason) {
console.error('[ERROR] OIDC Callback Error:', reason)
return res
diff --git a/backend/apps/community/src/auth/auth.service.ts b/backend/apps/community/src/auth/auth.service.ts
index c10f30f5b..ffe2d5e70 100644
--- a/backend/apps/community/src/auth/auth.service.ts
+++ b/backend/apps/community/src/auth/auth.service.ts
@@ -232,7 +232,7 @@ export class AuthService {
return idToken
}
- async processOidcToken(code: string, state: string) {
+ async processOidcToken(code: string, state: string, redirectUrl: string) {
const config = this.getOidcConfig()
const discovery = await this.getOidcDiscovery()
@@ -253,7 +253,7 @@ export class AuthService {
client_id: config.clientID,
client_secret: config.clientSecret,
code,
- // redirect_uri: config.callbackURL,
+ redirect_uri: redirectUrl,
}).toString(),
})
diff --git a/backend/apps/community/src/auth/dtos/oidc-auth.dto.ts b/backend/apps/community/src/auth/dtos/oidc-auth.dto.ts
index f8b1defbe..b8b0e251d 100644
--- a/backend/apps/community/src/auth/dtos/oidc-auth.dto.ts
+++ b/backend/apps/community/src/auth/dtos/oidc-auth.dto.ts
@@ -28,6 +28,12 @@ export class OIDCProcessTokenDto {
})
@IsString()
hash: string
+
+ @ApiProperty({
+ description: 'Redirect URL after successful authentication',
+ })
+ @IsString()
+ redirectUrl: string
}
export class OIDCGetJWTByHashDto {
diff --git a/web/app/api/index.ts b/web/app/api/index.ts
index 1d36d0c42..e8813d39f 100644
--- a/web/app/api/index.ts
+++ b/web/app/api/index.ts
@@ -1281,9 +1281,9 @@ export const getJWTBySSOHash = async (hash: string, provider: SSOProvider, refCo
})
}
-export const processSSOTokenCommunityEdition = (code: string, hash: string) =>
+export const processSSOTokenCommunityEdition = (code: string, hash: string, redirectUrl: string) =>
api
- .post('v1/auth/oidc/process-token', { code, hash })
+ .post('v1/auth/oidc/process-token', { code, hash, redirectUrl })
.then((response): unknown => response.data)
.catch((error) => {
throw _isEmpty(error.response.data?.message) ? error.response.data : error.response.data.message
diff --git a/web/app/pages/Auth/Socialised/index.tsx b/web/app/pages/Auth/Socialised/index.tsx
index d9c33f900..094c9a388 100644
--- a/web/app/pages/Auth/Socialised/index.tsx
+++ b/web/app/pages/Auth/Socialised/index.tsx
@@ -63,7 +63,7 @@ const Socialised = () => {
}
try {
- await processSSOTokenCommunityEdition(code, state)
+ await processSSOTokenCommunityEdition(code, state, `${window.location.origin}${routes.socialised}`)
} catch (reason) {
setIsError(true)
console.error(`[ERROR] Error while processing OIDC code: ${reason}`)