Swagger with Bearer Token .Net6

Bernardo Teixeira
Geek Culture
Published in
3 min readDec 11, 2021

--

Swagger is a language-agnostic specification for describing REST APIs. It allows both computers and humans to understand the capabilities of a REST API without direct access to the source code. Its primary goals are to:

  • Minimize the amount of work needed to connect decoupled services.
  • Reduce the amount of time required to document a service accurately.

ASP.NET Core web API documentation with Swagger / OpenAPI | Microsoft Docs

Swagger UI

Swagger UI offers a web-based UI that provides information about the service using the generated OpenAPI specification. Both Swashbuckle and NSwag include an embedded version of Swagger UI so that it can be hosted in your ASP.NET Core app using a middleware registration call.

Now that we finish the introduction let’s do some code.

Implementation

Let’s create a web solution with .Net6.

When you create a web solution, Swagger is already implemented by default. We need to give some input to Swagger could use the Bearer Token in the Header.

Quick note, if you don’t have a running IdentityServer watch, this article -> Getting Started with Duende IdentityServer + .Net5 | by Bernardo Teixeira | Geek Culture | Nov, 2021 | Medium. I’m using the Duende IdentityServer to have authorization and Authentication.

--

--