Skip to content

[Question]: bearer tokens not working in .net 10 #3651

@BasieP

Description

@BasieP

What are you wanting to achieve?

I upgrade my .net 9 application to .net 10 today.
I used the https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/master/docs/migrating-to-v10.md upgrade guide (though it was very basic)

What code or approach do you have so far?

I had trouble with 2 pieces of code.

The most important is that I can't seem to get the bearer tokens to work, but think it's a basic documentation issue.

my old (.net 9) code was

options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
            {
                Description = "JWT Authorization header using the Bearer scheme. \r\n\r\n Enter your token in the text input below.\r\n\r\nExample: \"12345abcdef\"",
                Name = "Authorization",
                Type = SecuritySchemeType.Http,
                Scheme = "bearer"
            });

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

which gives trouble in the AddSecurityRequirement section where 'Reference' no longer exists in OpenApiSecurityScheme.
As documented i upgraded that to the new OpenApiSecuritySchemeReference.
But it seems to work totally different. For starters it requires a 'referenceId' string. With 0 context i don't have a clue what to put in there.
I tried both 'Bearer' and 'Authorization' (the 2 magic strings i used in the 'AddSecurityDefinition' part, but both didn't work
And to be clear, i mean that i get the swagger UI, i have to option to fill in a bearer token, but the token doesn't get send along with the request...

Also, it's not clear to me if (when i create the OpenApiSecuritySchemeReference with a referenceId) I should also use the 'Reference' property, and if so, what i should fill it with...

In other words, are there any working examples of bearer tokens in .net 10?

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions