Skip to content
This repository was archived by the owner on Jan 10, 2025. It is now read-only.

eShopOnAbp: Keycloak swagger authorization #151

Closed
hikalkan opened this issue Dec 27, 2022 · 5 comments · Fixed by #238
Closed

eShopOnAbp: Keycloak swagger authorization #151

hikalkan opened this issue Dec 27, 2022 · 5 comments · Fixed by #238
Milestone

Comments

@hikalkan
Copy link
Member

Moved from abpframework/abp#14806

@alihdev
Copy link
Contributor

alihdev commented Dec 28, 2022

The cause of the issue is with :
1- authorizationEndpoint in SwaggerConfigurationHelper, which was resolved by update Swashbuckle to 6.0.1 and change to endpoint of keycloak auth instead of default.
2- WebGateway_Swagger and scopes that used by swagger .

Details in #147

@skoc10 skoc10 modified the milestones: 0.5, 0.6 Feb 6, 2023
@chimeramvp
Copy link

chimeramvp commented Feb 9, 2023

Working after modified SwaggerConfigurationHelper like this

    public static void ConfigureWithAuth(
        ServiceConfigurationContext context,
        string authority,
        Dictionary<string, string> scopes,
        string apiTitle,
        string apiVersion = "v1",
        string apiName = "v1"
    )
    {
        string authorizationEndpoint = "/protocol/openid-connect/auth", tokenEndpoint = "/protocol/openid-connect/token";
        var authorizationUrl = new Uri($"{authority.TrimEnd('/')}{authorizationEndpoint.EnsureStartsWith('/')}");
        var tokenUrl = new Uri($"{authority.TrimEnd('/')}{tokenEndpoint.EnsureStartsWith('/')}");

        context.Services
            .AddAbpSwaggerGen()
            .AddSwaggerGen(
                options =>
                {
                    options.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
                    {
                        Type = SecuritySchemeType.OAuth2,
                        Flows = new OpenApiOAuthFlows
                        {
                            AuthorizationCode = new OpenApiOAuthFlow
                            {
                                AuthorizationUrl = authorizationUrl,
                                Scopes = scopes,
                                TokenUrl = tokenUrl
                            }
                        }
                    });

                    options.AddSecurityRequirement(new OpenApiSecurityRequirement
                    {
                            {
                                new OpenApiSecurityScheme
                                {
                                    Reference = new OpenApiReference
                                    {
                                        Type = ReferenceType.SecurityScheme,
                                        Id = "oauth2"
                                    }
                                },
                                Array.Empty<string>()
                            }
                    });

                    options.SwaggerDoc(apiName, new OpenApiInfo { Title = apiTitle, Version = apiVersion });
                    options.DocInclusionPredicate((docName, description) => true);
                    options.CustomSchemaIds(type => type.FullName);
                });
    }

@alihdev
Copy link
Contributor

alihdev commented Feb 9, 2023

Working after modified SwaggerConfigurationHelper like this

    public static void ConfigureWithAuth(
        ServiceConfigurationContext context,
        string authority,
        Dictionary<string, string> scopes,
        string apiTitle,
        string apiVersion = "v1",
        string apiName = "v1"
    )
    {
        string authorizationEndpoint = "/protocol/openid-connect/auth", tokenEndpoint = "/protocol/openid-connect/token";
        var authorizationUrl = new Uri($"{authority.TrimEnd('/')}{authorizationEndpoint.EnsureStartsWith('/')}");
        var tokenUrl = new Uri($"{authority.TrimEnd('/')}{tokenEndpoint.EnsureStartsWith('/')}");

        context.Services
            .AddAbpSwaggerGen()
            .AddSwaggerGen(
                options =>
                {
                    options.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
                    {
                        Type = SecuritySchemeType.OAuth2,
                        Flows = new OpenApiOAuthFlows
                        {
                            AuthorizationCode = new OpenApiOAuthFlow
                            {
                                AuthorizationUrl = authorizationUrl,
                                Scopes = scopes,
                                TokenUrl = tokenUrl
                            }
                        }
                    });

                    options.AddSecurityRequirement(new OpenApiSecurityRequirement
                    {
                            {
                                new OpenApiSecurityScheme
                                {
                                    Reference = new OpenApiReference
                                    {
                                        Type = ReferenceType.SecurityScheme,
                                        Id = "oauth2"
                                    }
                                },
                                Array.Empty<string>()
                            }
                    });

                    options.SwaggerDoc(apiName, new OpenApiInfo { Title = apiTitle, Version = apiVersion });
                    options.DocInclusionPredicate((docName, description) => true);
                    options.CustomSchemaIds(type => type.FullName);
                });
    }

you can only update the version of Volo.Abp.Swashbuckle package to 6.0.1 and update the [SwaggerConfigurationHelper]

check: https://github.com/abpframework/eShopOnAbp/pull/147/files#

@chimeramvp
Copy link

get it. thanks!

1 similar comment
@chimeramvp
Copy link

get it. thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants