Add JWT Bearer Authorization to Swagger and ASP.NET Core

Written by ppolyzos

Software engineer based in Athens, Greece

20 Comments

    1. ppolyzos

      For swagger 2.x I have used the following code:

  1. SIMON J WEAVER

    This is great, but kinda sucks that it doesn’t remember the token when you refresh the page.

    Is there anything planned or possible with that?
    (right now I’m keeping notepad open with a token to copy each time i recompile)

    1. ppolyzos

      You can use the [AllowAnonymous] attribute if you want your API endpoint to be public.
      Otherwise use [Authorized(Roles="Admin")] for Role-based Authentication or [Authorize(Policy = "EmployeeOnly")] for claims-based authorization.
      You can read more here and here if you want to do filtering based on security policies in Swagger.

Leave a Comment

Your email address will not be published. Required fields are marked *