mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-10 01:39:08 +00:00
FEAT: init url callback
This commit is contained in:
@@ -420,4 +420,22 @@ export class AuthController {
|
||||
|
||||
return this.authClient.resetUsers(body.users, metadata);
|
||||
}
|
||||
|
||||
@Get('/idp/:name/callback')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
async callbackIdp(@Param('name') idpName: string, @Req() req: Request) {
|
||||
this.logger.info('/auth/idp/:name/callback');
|
||||
|
||||
const { params } = req;
|
||||
|
||||
if (!params || !params.code) {
|
||||
this.logger.error('No code received from IDP');
|
||||
throw new Error(ErrorCodes.IDENTITY_PROVIDER.INVALID_RESPONSE);
|
||||
}
|
||||
|
||||
return {
|
||||
ok: true
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,17 +36,29 @@ export class IdentityProviderService implements OnModuleInit {
|
||||
}
|
||||
|
||||
async loginIdentityProvider(id: string) {
|
||||
const client = await this.buildOpenIdClient(id);
|
||||
const idp = await lastValueFrom(
|
||||
this.identityProviderService.FindIdentityProvider({ id }),
|
||||
);
|
||||
|
||||
const issuer = await Issuer.discover(idp.issuerUrl);
|
||||
const client = new issuer.Client({
|
||||
client_id: idp.clientId,
|
||||
client_secret: idp.clientSecret,
|
||||
redirect_uris: [`http://localhost:3333/auth/idp/${idp.name}/callback`],
|
||||
response_types: ['code'],
|
||||
});
|
||||
|
||||
const code_verifier: string = generators.codeVerifier();
|
||||
const code_challenge: string = generators.codeChallenge(code_verifier);
|
||||
|
||||
return client.authorizationUrl({
|
||||
scope: 'openid email',
|
||||
const url = client.authorizationUrl({
|
||||
scope: 'openid email profile',
|
||||
response_type: 'code',
|
||||
code_challenge,
|
||||
code_challenge_method: 'S256',
|
||||
});
|
||||
const idpUrl = url + '&identity_provider=' + idp.name
|
||||
return idpUrl;
|
||||
}
|
||||
|
||||
// async authorizeIdp(name: string, req: Request) {
|
||||
@@ -67,17 +79,4 @@ export class IdentityProviderService implements OnModuleInit {
|
||||
// return tokenSet.claims();
|
||||
// }
|
||||
|
||||
private async buildOpenIdClient(id: string) {
|
||||
const idp = await lastValueFrom(
|
||||
this.identityProviderService.FindIdentityProvider({ id }),
|
||||
);
|
||||
|
||||
const issuer = await Issuer.discover(idp.issuerUrl);
|
||||
return new issuer.Client({
|
||||
client_id: idp.clientId,
|
||||
client_secret: idp.clientSecret,
|
||||
redirect_uris: [`http://localhost:3333/auth/idp/${idp.name}/callback`],
|
||||
response_types: ['code'],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user