question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I have this configuration:

            services.ConfigureSwaggerGen(x =>
            {
                //x.DocumentFilter
                x.SingleApiVersion(new Info
                {
                    Version = "v1",
                    Title = "API",
                    Description = "API templates for app.",
                    TermsOfService = "None",
                    Contact = new Contact()
                    {
                        Email = "email@d.com",
                        Name = "vendor",
                        Url = "website",
                    },
                    License = new License()
                    {
                        Name = "dd",
                        Url = "https://ddd/support/license"
                    },
                });
                x.IncludeXmlComments(AppContext.BaseDirectory + @"/app.xml");
                x.IgnoreObsoleteProperties();
                x.IgnoreObsoleteActions();
                x.DescribeAllEnumsAsStrings();
                x.AddSecurityDefinition("Bearer", new ApiKeyScheme()
                {
                    Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
                    Name = "Authorization",
                    In = "header",
                    Type = "apiKey"
                });
            });

There is no provision in UI for input of Bearer token?

image

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:16 (2 by maintainers)

github_iconTop GitHub Comments

26reactions
goforgoldcommented, Jun 19, 2017

@mjabian

I tried your solution, fortunately it worked for me with a minor change (not in your code). I used below part of your code

x.AddSecurityDefinition("Bearer", new ApiKeyScheme()
{
    Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
    Name = "Authorization",
    In = "header",
    Type = "apiKey"
});

It creates an Authorize button in Swagger UI like below for me

image

When I click this button, it opens up a popup where I was able to put JWT value. It didn’t work.

I observed the request using F12 tools and found that the required header was being added but suffix bearer was not added. So, I just put this manually in token value like bearer <token-here>. And, yo, It worked!!.

Thanks a lot to you.

21reactions
domaindrivendevcommented, Mar 20, 2018

@ajbeaven @Behnam-Emamian - to get this to work in 2.x, you need to accompany your scheme definition with a corresponding requirement to indicate that the scheme is applicable to all operations in your API:

c.AddSecurityRequirement(new Dictionary<string, IEnumerable<string>>
{
    { "Bearer", new string[] { } }
});

NOTE: it turns out that the old UI worked without this despite being an incomplete description, as per the Swagger 2.0 spec. The new swagger-ui correctly requires this

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bearer Authentication
Bearer authentication (also called token authentication) is an HTTP authentication scheme that involves security tokens called bearer tokens.
Read more >
What is Bearer token and How it works?
Bearer tokens are a much simpler way of making API requests, since they don't require cryptographic signing of each request.
Read more >
OAuth 2.0 Bearer Token Usage
A Bearer Token is an opaque string, not intended to have any meaning to clients using it. Some servers will issue tokens that...
Read more >
Generating and using app-only Bearer Tokens | Docs
A Bearer Token is a byte array of unspecified format that you generate using a script like a curl command. You can also...
Read more >
What are Bearer Tokens? - YouTube
01:43 Proof of Possession would increase security Bearer tokens are commonly used for authorization and authentication on the web.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found