awais
awais

Reputation: 515

Swagger Bearer Authentication isn't showing Authorization JWT token field for [GET] request

Authorization field is showing for HTTP POST request but it's not showing for GET request to add a token for authentication of Web API.

enter image description here

enter image description here

config.EnableSwagger(c =>
            {
                c.SingleApiVersion("v1", "Mach.CharterPad.API");
                c.OperationFilter<SwaggerAuthorizationFilter>();
                c.RootUrl(req => $"{req.RequestUri.GetLeftPart(UriPartial.Authority)}{req.GetConfiguration().VirtualPathRoot.TrimEnd('/')}{appvirtualpath}/api");
            }).EnableSwaggerUi();
public class SwaggerAuthorizationFilter : IOperationFilter
    {
        public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
        {
            if (operation.parameters != null)
            {
                operation.parameters.Add(new Parameter
                {
                    name = "Authorization",
                    @in = "header",
                    description = "access token",
                    required = false,
                    type = "string"
                });
            }
        }
    }

Upvotes: 0

Views: 1133

Answers (1)

awais
awais

Reputation: 515

I have updated API parameters and it's working fine.

[Route("")]
public IHttpActionResult Get([FromUri] Paging paging)
{
    var result = TripManager.Get(paging.Index, paging.Size);
    return Ok(result != null ? new ApiResponse(true, "Results found", result) : new ApiResponse(false, "No record found", result));
}

enter image description here

Upvotes: 1

Related Questions