Authorization for JWT bearer in Swashbuckle .NET Core 2

前端 未结 3 1188
-上瘾入骨i
-上瘾入骨i 2020-12-16 19:06

I use tokens generated by an authentication service for my app. No problems there. Now I have introduced Swashbuckle to document my API an I can authenticate as follows by s

3条回答
  •  甜味超标
    2020-12-16 19:33

    In the end I moved to NSwag so I am not sure what the original issue was. The solution in Nswag is as follows;

        services.AddSwaggerDocument(document =>
            {
                document.DocumentName = "CPSwagger";
                document.Title = "My Mobile API";
                document.Version = "v10.3.4";
                document.Description = "An interface for some software.";
    
                document.DocumentProcessors.Add(
                    new SecurityDefinitionAppender("JWT token", new NSwag.OpenApiSecurityScheme
                    {
                        Type = NSwag.OpenApiSecuritySchemeType.ApiKey,
                        Name = "Authorization",
                        Description = "Copy 'Bearer ' + valid JWT token into field",
                        In = NSwag.OpenApiSecurityApiKeyLocation.Header
                    }));
                document.OperationProcessors.Add(new OperationSecurityScopeProcessor("JWT token"));
            });
    

提交回复
热议问题