mirror of
https://github.com/dadosfera/maestro.git
synced 2026-12-05 20:00:04 +00:00
FEAT: dynamic callback and issuer urls
This commit is contained in:
@@ -27,7 +27,11 @@ import {
|
||||
} from './dto/identity-provider.dto';
|
||||
import { Request } from 'express';
|
||||
import ErrorCodes from 'src/utils/errorCodes';
|
||||
import { Authenticated, RequireModule, RequireSomePermission } from 'src/decorators/authentication.decorator';
|
||||
import {
|
||||
Authenticated,
|
||||
RequireModule,
|
||||
RequireSomePermission,
|
||||
} from 'src/decorators/authentication.decorator';
|
||||
import { PERMISSIONS_GROUPS } from 'src/authentication/permissions.enum';
|
||||
|
||||
@Controller('identity-providers')
|
||||
@@ -119,15 +123,24 @@ export class IdentityProviderController {
|
||||
...user,
|
||||
});
|
||||
|
||||
return await this.identityProviderService.updateIdentityProviders(id, body, metadata);
|
||||
return await this.identityProviderService.updateIdentityProviders(
|
||||
id,
|
||||
body,
|
||||
metadata,
|
||||
);
|
||||
}
|
||||
|
||||
@Post('/callback')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
async callbackIdp(@Req() req: Request, @Body() body: {
|
||||
state: string,
|
||||
code: string
|
||||
}) {
|
||||
async callbackIdp(
|
||||
@Req() req: Request,
|
||||
@Language() language: LanguageEnum,
|
||||
@Body()
|
||||
body: {
|
||||
state: string;
|
||||
code: string;
|
||||
},
|
||||
) {
|
||||
this.logger.info('GET /identity-providers/callback');
|
||||
const { code, state } = body;
|
||||
|
||||
@@ -141,7 +154,13 @@ export class IdentityProviderController {
|
||||
throw new Error(ErrorCodes.IDENTITY_PROVIDER.INVALID_RESPONSE);
|
||||
}
|
||||
|
||||
return await this.identityProviderService.getTokenByIdp(code, state);
|
||||
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 callbackUrl = process.env.ENV !== "prd" ? `${origin}/auth/callback` : `${origin}/${lang}/auth/callback`;
|
||||
|
||||
return await this.identityProviderService.getTokenByIdp(code, state, callbackUrl);
|
||||
}
|
||||
|
||||
@Get('/links')
|
||||
@@ -155,7 +174,10 @@ export class IdentityProviderController {
|
||||
throw new Error(ErrorCodes.IDENTITY_PROVIDER.INVALID_HEADER);
|
||||
}
|
||||
|
||||
const result = await this.identityProviderService.identityProvidersLinksPerDomain(frontDomain);
|
||||
const result =
|
||||
await this.identityProviderService.identityProvidersLinksPerDomain(
|
||||
frontDomain,
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -171,5 +193,4 @@ export class IdentityProviderController {
|
||||
url: redirectUrl,
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user