mirror of
https://github.com/dadosfera/maestro.git
synced 2026-10-29 11:49:08 +00:00
Merge pull request #330 from dadosfera/feature/sso-openid
FIX: send redirect uri
This commit is contained in:
@@ -8,7 +8,6 @@ import {
|
||||
HttpStatus,
|
||||
Inject,
|
||||
Param,
|
||||
Patch,
|
||||
Post,
|
||||
Put,
|
||||
Redirect,
|
||||
@@ -155,9 +154,8 @@ export class IdentityProviderController {
|
||||
}
|
||||
|
||||
const origin = req.headers['origin'] as string;
|
||||
const langHeader = req.headers['dadosfera-lang'] as string;
|
||||
|
||||
const lang = langHeader.substring(0, 2) + langHeader.substring(2).toUpperCase();
|
||||
const lang = language.substring(0, 2) + language.substring(2).toUpperCase();
|
||||
const callbackUrl = process.env.ENV !== "prd" ? `${origin}/auth/callback` : `${origin}/${lang}/auth/callback`;
|
||||
|
||||
return await this.identityProviderService.getTokenByIdp(code, state, callbackUrl);
|
||||
@@ -184,11 +182,18 @@ export class IdentityProviderController {
|
||||
@Get(':id')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@Redirect()
|
||||
async loginIdp(@Param('id') id: string) {
|
||||
async loginIdp(@Param('id') id: string, @Req() req: Request, @Language() language: LanguageEnum) {
|
||||
this.logger.info('GET /identity-providers/:id');
|
||||
|
||||
|
||||
const origin = req.headers['origin'] as string || req.headers['referer'] as string;
|
||||
console.log('Origin:', origin);
|
||||
|
||||
const lang = language.substring(0, 2) + language.substring(2).toUpperCase();
|
||||
const callbackUrl = process.env.ENV !== "prd" ? `${origin}/auth/callback` : `${origin}/${lang}/auth/callback`;
|
||||
|
||||
const redirectUrl =
|
||||
await this.identityProviderService.loginIdentityProvider(id);
|
||||
await this.identityProviderService.loginIdentityProvider(id, callbackUrl);
|
||||
|
||||
this.logger.info(`Redirecting to: ${redirectUrl}`);
|
||||
return {
|
||||
|
||||
@@ -44,7 +44,7 @@ export class IdentityProviderService implements OnModuleInit {
|
||||
);
|
||||
}
|
||||
|
||||
async loginIdentityProvider(id: string) {
|
||||
async loginIdentityProvider(id: string, callbackUrl: string) {
|
||||
const idp = await lastValueFrom(
|
||||
this.identityProviderService.FindIdentityProvider({ id }),
|
||||
);
|
||||
@@ -83,6 +83,7 @@ export class IdentityProviderService implements OnModuleInit {
|
||||
code_challenge_method: 'S256',
|
||||
state,
|
||||
nonce,
|
||||
redirect_uri: callbackUrl,
|
||||
});
|
||||
const idpUrl = url + '&identity_provider=' + idp.name;
|
||||
return idpUrl;
|
||||
|
||||
Reference in New Issue
Block a user