abpframework / eShopOnAbp

Reference microservice solution built with the ABP Framework and .NET, runs on Kubernetes with Helm configuration, includes API Gateways, Angular and ASP.NET Core MVC applications, PostgreSQL and MongoDB databases
https://www.eShopOnAbp.com/
MIT License
664 stars 259 forks source link

Fix Swagger Authorization and Client Creation #215

Closed alihdev closed 3 months ago

alihdev commented 6 months ago

Issue 1: URL Misconfiguration

Encountered an issue with Swagger's integration with Keycloak due to misconfigured authorization URLs:

Resolved the issue by updating the authentication URLs in the SwaggerConfigurationHelper class within AddAbpSwaggerGenWithOAuth:

Code changes:

context.Services.AddAbpSwaggerGenWithOAuth(
    authority: authority,
    scopes: scopes,
    options =>
    {
        options.SwaggerDoc(apiName, new OpenApiInfo { Title = apiTitle, Version = apiVersion });
        options.DocInclusionPredicate((docName, description) => true);
        options.CustomSchemaIds(type => type.FullName);
    },
    authorizationEndpoint: "/protocol/openid-connect/auth",
    tokenEndpoint: "/protocol/openid-connect/token"
);

Issue 2: Missing Client and Scopes

Encountered errors due to missing client configurations and scopes for WebGateway_Swagger & SwaggerClient in KeyCloakDataSeeder , resulting in:

Resolved by:

Testing Done

Additional Notes

gterdem commented 4 months ago

I think this PR is no longer necessary, the client creation is already done.

The problem however is shifted to the custom header CORS problem for the keycloak:

image

This is set for the antiforgery security by the Abp.Swashbucke package: https://github.com/abpframework/abp/blob/ce1235a4034f05cfd8bb8add49db529f7ac23c8c/framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.js#L87-L95

However currently, it is not possible to allow custom headers for CORS on Keycloak server: https://github.com/keycloak/keycloak/issues/12682

I'll investigate more.

gterdem commented 3 months ago

Closing the PR, the problems are fixed and I shared the commit details.