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