Swashbuckle.aspnetcore: Authorization in UI for ApiKeyScheme

Created on 11 Jul 2016  路  4Comments  路  Source: domaindrivendev/Swashbuckle.AspNetCore

Using ApiKeyScheme doesn't give me the ability to specify the API key for authorization on the UI. Not sure if it did, or is supposed to (this is my first time using Swagger and Swashbuckle/Ahoy)

version 6.0.0-beta901

Most helpful comment

I had a similar issue. I was able to see the "Authorize" button in the UI menu, but when I clicked on api key in the popup nothing happened. My issue was that I had to specify the "Type" as "apiKey".... not sure if your issue is related. Not sure why "type" can't be inferred by the ApiKeyScheme class.

        services.AddSwaggerGen(options =>
        {
            options.SingleApiVersion(new Swashbuckle.Swagger.Model.Info()
            {
                TermsOfService = "Copyright, " + DateTime.Now.Year.ToString() + " My Company, Inc. All Rights Reserved. For authorized use only.",
                Description = "For authorized use only.",
                Version = "v1",
                Contact = new Swashbuckle.Swagger.Model.Contact()
                {
                    Email = "myemail.... omitted",
                    Name = "Chris Klepeis"
                },
                Title = "My Services"
            });
            options.IncludeXmlComments(String.Format(@"{0}\SO.WebServices.XML", AppDomain.CurrentDomain.BaseDirectory)); // Use xml comments for Swagger documentation
            options.AddSecurityDefinition("Bearer", new ApiKeyScheme()
            {
                Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
                Name = "Authorization",
                In = "header",
                Type = "apiKey"
            });
        }); 

All 4 comments

Alright, so I've done some testing and it seems that Swagger UI 2.1.4 (which is bundled with Ahoy) doesn't show the authorization UI for ApiKeyScheme. However, the master branch does; any change we could get a release with an updated (prerelease) Swagger UI?

I had a similar issue. I was able to see the "Authorize" button in the UI menu, but when I clicked on api key in the popup nothing happened. My issue was that I had to specify the "Type" as "apiKey".... not sure if your issue is related. Not sure why "type" can't be inferred by the ApiKeyScheme class.

        services.AddSwaggerGen(options =>
        {
            options.SingleApiVersion(new Swashbuckle.Swagger.Model.Info()
            {
                TermsOfService = "Copyright, " + DateTime.Now.Year.ToString() + " My Company, Inc. All Rights Reserved. For authorized use only.",
                Description = "For authorized use only.",
                Version = "v1",
                Contact = new Swashbuckle.Swagger.Model.Contact()
                {
                    Email = "myemail.... omitted",
                    Name = "Chris Klepeis"
                },
                Title = "My Services"
            });
            options.IncludeXmlComments(String.Format(@"{0}\SO.WebServices.XML", AppDomain.CurrentDomain.BaseDirectory)); // Use xml comments for Swagger documentation
            options.AddSecurityDefinition("Bearer", new ApiKeyScheme()
            {
                Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
                Name = "Authorization",
                In = "header",
                Type = "apiKey"
            });
        }); 

This should be available with the latest preview packages available on myget:

https://myget.org/gallery/domaindrivendev

Available with latest pre-release. Note the package rename to "Swashbuckle.AspNetCore.1.0.0-rc1"

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JoelAdamWeiss picture JoelAdamWeiss  路  4Comments

jderus picture jderus  路  4Comments

TimmyGilissen picture TimmyGilissen  路  3Comments

VisualBean picture VisualBean  路  4Comments

brucewilkins picture brucewilkins  路  3Comments