mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-28 06:50:06 +00:00
FEAT: init url callback
This commit is contained in:
@@ -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