mirror of
https://github.com/dadosfera/maestro.git
synced 2026-09-21 05:54:49 +00:00
FEAT: map permission to identity provider
This commit is contained in:
+56
-2
@@ -5923,6 +5923,46 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/identity-providers/{id}": {
|
||||
"get": {
|
||||
"operationId": "IdentityProviderController_loginIdp",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "id",
|
||||
"required": true,
|
||||
"in": "path",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/identity-providers/{name}/callback": {
|
||||
"get": {
|
||||
"operationId": "IdentityProviderController_callbackIdp",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "name",
|
||||
"required": true,
|
||||
"in": "path",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/network-policy": {
|
||||
"get": {
|
||||
"operationId": "NetworkPolicyController_getNetworks",
|
||||
@@ -8893,13 +8933,20 @@
|
||||
},
|
||||
"issuerUrl": {
|
||||
"type": "string"
|
||||
},
|
||||
"permissions": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "number"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name",
|
||||
"clientId",
|
||||
"clientSecret",
|
||||
"issuerUrl"
|
||||
"issuerUrl",
|
||||
"permissions"
|
||||
]
|
||||
},
|
||||
"IdentityProviderResponse": {
|
||||
@@ -8916,13 +8963,20 @@
|
||||
},
|
||||
"issueUrl": {
|
||||
"type": "string"
|
||||
},
|
||||
"permissions": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"id",
|
||||
"name",
|
||||
"clientId",
|
||||
"issueUrl"
|
||||
"issueUrl",
|
||||
"permissions"
|
||||
]
|
||||
},
|
||||
"IdentityProviderListResponse": {
|
||||
|
||||
Generated
+1
-1
@@ -1405,7 +1405,7 @@
|
||||
"node_modules/@dadosfera/protospack-v2": {
|
||||
"version": "0.0.0",
|
||||
"resolved": "file:../protospack-v2/dadosfera-protospack-v2-0.0.0.tgz",
|
||||
"integrity": "sha512-b8cBIXQAgEtrqLltJ5n4CycTH9Pm43VmQvoGL7PwyvErysXviWpwhtz5Qp8ELpfu5+rquQ2vRhqSaDmCFlGzew==",
|
||||
"integrity": "sha512-gT6JX/mh57cc/f9ey3ZPZ03fYKCqTj6CewazOnkf1juSAON65IR/9pD8lx/KMMcc3mYUT3Z3yjVAmXjvN09jPw==",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@grpc/grpc-js": "^1.9.3",
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@
|
||||
"@aws-sdk/client-secrets-manager": "^3.414.0",
|
||||
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
|
||||
"@dadosfera/protospack": "2.5.3",
|
||||
"@dadosfera/protospack-v2": "file:../protospack-v2/dadosfera-protospack-v2-0.0.0.tgz",
|
||||
"@dadosfera/protospack-v2": "3.38.0-beta.4",
|
||||
"@grpc/grpc-js": "^1.9.3",
|
||||
"@grpc/proto-loader": "^0.7.9",
|
||||
"@nestjs/cli": "^9.5.0",
|
||||
|
||||
@@ -13,6 +13,9 @@ export class CreateIdentityProvider {
|
||||
|
||||
@ApiProperty()
|
||||
issuerUrl: string;
|
||||
|
||||
@ApiProperty()
|
||||
permissions: number[];
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +32,12 @@ export class IdentityProviderResponse {
|
||||
|
||||
@ApiProperty()
|
||||
issueUrl: string;
|
||||
|
||||
@ApiProperty()
|
||||
permissions: {
|
||||
id: number;
|
||||
name: string;
|
||||
}[];
|
||||
}
|
||||
|
||||
export class IdentityProviderListResponse {
|
||||
|
||||
@@ -43,7 +43,7 @@ export class IdentityProviderController {
|
||||
this.logger.info('/openid - addIdentityProvider');
|
||||
|
||||
const metadata = PackTheMetadata({
|
||||
customer_id: user.customer_id,
|
||||
...user,
|
||||
language,
|
||||
});
|
||||
|
||||
@@ -66,24 +66,26 @@ export class IdentityProviderController {
|
||||
return await this.identityProviderService.getList(metadata)
|
||||
}
|
||||
|
||||
// @Get(':name')
|
||||
// @HttpCode(HttpStatus.OK)
|
||||
// @Redirect()
|
||||
// async loginIdp(@Param('name') name: string , @Req() req: Request) {
|
||||
// this.logger.info('/openid - :name');
|
||||
@Get(':id')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@Redirect()
|
||||
async loginIdp(@Param('id') id: string) {
|
||||
this.logger.info('/openid - :name');
|
||||
|
||||
// const redirectUrl = await this.openidService.loginIdp(name, req);
|
||||
// return {
|
||||
|
||||
// url: redirectUrl,
|
||||
// };
|
||||
// }
|
||||
const redirectUrl = await this.identityProviderService.loginIdentityProvider(id);
|
||||
return {
|
||||
url: redirectUrl,
|
||||
};
|
||||
}
|
||||
|
||||
// @Get('/:name/callback')
|
||||
// @HttpCode(HttpStatus.OK)
|
||||
// async callbackIdp(@Param('name') name: string, @Req() req: Request) {
|
||||
// this.logger.info('/openid - /:name/callback');
|
||||
@Get('/:name/callback')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
async callbackIdp(@Param('name') name: string, @Req() req: Request) {
|
||||
this.logger.info('/openid - /:name/callback');
|
||||
|
||||
// return await this.openidService.authorizeIdp(name, req);
|
||||
// }
|
||||
return {
|
||||
name,
|
||||
params: req.params
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,21 +35,19 @@ export class IdentityProviderService implements OnModuleInit {
|
||||
);
|
||||
}
|
||||
|
||||
// async loginIdp(name: string, req: Request) {
|
||||
// const client = await this.buildOpenIdClient(name);
|
||||
async loginIdentityProvider(id: string) {
|
||||
const client = await this.buildOpenIdClient(id);
|
||||
|
||||
// const code_verifier: string = generators.codeVerifier();
|
||||
// const code_challenge: string = generators.codeChallenge(code_verifier);
|
||||
const code_verifier: string = generators.codeVerifier();
|
||||
const code_challenge: string = generators.codeChallenge(code_verifier);
|
||||
|
||||
// req.session.code_verifier = code_verifier;
|
||||
|
||||
// return client.authorizationUrl({
|
||||
// scope: 'openid email',
|
||||
// response_type: 'code',
|
||||
// code_challenge,
|
||||
// code_challenge_method: 'S256',
|
||||
// });
|
||||
// }
|
||||
return client.authorizationUrl({
|
||||
scope: 'openid email',
|
||||
response_type: 'code',
|
||||
code_challenge,
|
||||
code_challenge_method: 'S256',
|
||||
});
|
||||
}
|
||||
|
||||
// async authorizeIdp(name: string, req: Request) {
|
||||
// const client = await this.buildOpenIdClient(name);
|
||||
@@ -69,17 +67,17 @@ export class IdentityProviderService implements OnModuleInit {
|
||||
// return tokenSet.claims();
|
||||
// }
|
||||
|
||||
// private async buildOpenIdClient(name: string) {
|
||||
// const idp = await lastValueFrom(
|
||||
// this.identityProviderService.FindIdentityProvider({ name }),
|
||||
// );
|
||||
private async buildOpenIdClient(id: string) {
|
||||
const idp = await lastValueFrom(
|
||||
this.identityProviderService.FindIdentityProvider({ id }),
|
||||
);
|
||||
|
||||
// const issuer = await Issuer.discover(idp.issueUrl);
|
||||
// return new issuer.Client({
|
||||
// client_id: idp.clientId,
|
||||
// client_secret: idp.clientSecret,
|
||||
// redirect_uris: [`http://localhost:3333/openid/${idp.name}/callback`],
|
||||
// response_types: ['code'],
|
||||
// });
|
||||
// }
|
||||
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