mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-13 12:09:09 +00:00
FEAT: send user id to refresh token endpoint
This commit is contained in:
@@ -104,15 +104,14 @@ export class AuthController {
|
||||
@Headers('origin') origin: string,
|
||||
) {
|
||||
this.logger.info('/auth - RefreshAccessToken');
|
||||
const { refreshToken, customerName: customer_name, accessToken } = body;
|
||||
const { refreshToken, userId } = body;
|
||||
const frontHost = origin.replace(/^https?:\/\//, '');
|
||||
const metadata = PackTheMetadata({
|
||||
language,
|
||||
customer_name,
|
||||
custom_host: frontHost,
|
||||
});
|
||||
|
||||
return this.authClient.refreshAccessToken({ refreshToken, accessToken }, metadata);
|
||||
return this.authClient.refreshAccessToken({ refreshToken, userId }, metadata);
|
||||
}
|
||||
|
||||
@ApiInternalOnlyEndpoint()
|
||||
|
||||
@@ -74,13 +74,13 @@ export class AuthClientService implements OnModuleInit {
|
||||
}
|
||||
|
||||
async refreshAccessToken(
|
||||
{ refreshToken, accessToken }: AuthRefreshAccessTokenRequest,
|
||||
{ refreshToken, userId }: AuthRefreshAccessTokenRequest,
|
||||
metadata: Metadata,
|
||||
) {
|
||||
this.logger.info('RefreshAccessToken');
|
||||
|
||||
return lastValueFrom(
|
||||
this.authService.AuthRefreshAccessToken({ refreshToken, accessToken }, metadata),
|
||||
this.authService.AuthRefreshAccessToken({ refreshToken, userId }, metadata),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -122,9 +122,7 @@ export class AuthRefreshAccessTokenReq {
|
||||
@ApiProperty()
|
||||
refreshToken: string;
|
||||
@ApiProperty()
|
||||
accessToken: string;
|
||||
@ApiProperty()
|
||||
customerName: string;
|
||||
userId: string;
|
||||
}
|
||||
export class AuthRefreshAccessTokenRes {
|
||||
@ApiProperty()
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { BadRequestException, Inject, Injectable, OnModuleInit } from '@nestjs/common';
|
||||
import {
|
||||
BadRequestException,
|
||||
Inject,
|
||||
Injectable,
|
||||
OnModuleInit,
|
||||
} from '@nestjs/common';
|
||||
import { DucClient } from '../duc/client.config';
|
||||
import { ClientGrpc } from '@nestjs/microservices';
|
||||
import { ProtoServices } from '@dadosfera/protospack-v2/dist/lib/Duc';
|
||||
@@ -17,7 +22,7 @@ export class IdentityProviderService implements OnModuleInit {
|
||||
private identityProviderService: IdentityProviderProtoService;
|
||||
constructor(
|
||||
@Inject(DucClient.name) private readonly grpcClient: ClientGrpc,
|
||||
private readonly cacheService: CacheService<SsoSignInDto>
|
||||
private readonly cacheService: CacheService<SsoSignInDto>,
|
||||
) {}
|
||||
|
||||
onModuleInit() {
|
||||
@@ -41,7 +46,7 @@ export class IdentityProviderService implements OnModuleInit {
|
||||
|
||||
async loginIdentityProvider(id: string) {
|
||||
const idp = await lastValueFrom(
|
||||
this.identityProviderService.FindIdentityProvider({ id}),
|
||||
this.identityProviderService.FindIdentityProvider({ id }),
|
||||
);
|
||||
|
||||
const redirectUri = this.getCallbackUrl();
|
||||
@@ -79,9 +84,9 @@ export class IdentityProviderService implements OnModuleInit {
|
||||
code_challenge,
|
||||
code_challenge_method: 'S256',
|
||||
state,
|
||||
nonce
|
||||
nonce,
|
||||
});
|
||||
const idpUrl = url + '&identity_provider=' + idp.name
|
||||
const idpUrl = url + '&identity_provider=' + idp.name;
|
||||
return idpUrl;
|
||||
}
|
||||
|
||||
@@ -108,34 +113,36 @@ export class IdentityProviderService implements OnModuleInit {
|
||||
client_id: ssoSign.clientId,
|
||||
client_secret: ssoSign.clientSecret,
|
||||
redirect_uris: [callbackUrl],
|
||||
response_types: ['code'],
|
||||
});
|
||||
|
||||
if (ssoSign === null) {
|
||||
throw new BadRequestException('SSO sign-in is expired or not found');
|
||||
}
|
||||
|
||||
const params = client.callbackParams(`${callbackUrl}?code=${code}&state=${state}`);
|
||||
const tokenSet = await client.callback(
|
||||
callbackUrl,
|
||||
params,
|
||||
{
|
||||
const params = client.callbackParams(
|
||||
`${callbackUrl}?code=${code}&state=${state}`,
|
||||
);
|
||||
try {
|
||||
const tokenSet = await client.callback(callbackUrl, params, {
|
||||
nonce: ssoSign.nonce,
|
||||
code_verifier: ssoSign.codeVerifier,
|
||||
state: ssoSign.state,
|
||||
}
|
||||
);
|
||||
state: ssoSign.state
|
||||
});
|
||||
|
||||
await this.cacheService.delete(ssoSign.state);
|
||||
await this.cacheService.delete(ssoSign.state);
|
||||
|
||||
return await lastValueFrom(
|
||||
this.identityProviderService.SignInUser({
|
||||
accessToken: tokenSet.access_token,
|
||||
idToken: tokenSet.id_token,
|
||||
refreshToken: tokenSet.refresh_token,
|
||||
id: ssoSign.id
|
||||
}),
|
||||
);
|
||||
return await lastValueFrom(
|
||||
this.identityProviderService.SignInUser({
|
||||
accessToken: tokenSet.access_token,
|
||||
idToken: tokenSet.id_token,
|
||||
refreshToken: tokenSet.refresh_token,
|
||||
id: ssoSign.id,
|
||||
}),
|
||||
);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async deleteIdentityProvider(id: string, metadata: Metadata) {
|
||||
@@ -144,12 +151,19 @@ export class IdentityProviderService implements OnModuleInit {
|
||||
);
|
||||
}
|
||||
|
||||
async updateIdentityProviders(id: string, body: CreateIdentityProvider, metadata: Metadata) {
|
||||
async updateIdentityProviders(
|
||||
id: string,
|
||||
body: CreateIdentityProvider,
|
||||
metadata: Metadata,
|
||||
) {
|
||||
return await lastValueFrom(
|
||||
this.identityProviderService.UpdateIdentityProvider({
|
||||
id,
|
||||
...body,
|
||||
}, metadata),
|
||||
this.identityProviderService.UpdateIdentityProvider(
|
||||
{
|
||||
id,
|
||||
...body,
|
||||
},
|
||||
metadata,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -158,5 +172,4 @@ export class IdentityProviderService implements OnModuleInit {
|
||||
this.identityProviderService.GetProviderLinksFromDomain({ frontDomain }),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user