相关疑难解决方法(0)

使用授权标头(Bearer)设置Swagger(ASP.NET Core)

我有一个Web API(ASP.NET核心),我正在尝试调整swagger来进行调用.这些调用必须包含Authorization标头,我正在使用Bearer身份验证.来自Postman等第三方应用的电话也没问题.但我遇到了设置swagger标头的问题(由于某种原因我没有收到标头).这就是现在的样子:

  "host": "localhost:50352",
  "basePath": "/" ,
  "schemes": [
    "http",
    "https"
  ],
 "securityDefinitions":  {
    "Bearer": {
      "name": "Authorization",
      "in": "header",
      "type": "apiKey",
      "description": "HTTP/HTTPS Bearer"
    }
  },
  "paths": { 
    "/v1/{subAccountId}/test1": {
      "post": {
        "tags": [
          "auth"
        ],
        "operationId": "op1",
        "consumes": ["application/json", "application/html"],
        "produces": ["application/json", "application/html"],
        "parameters": [
          {
            "name": "subAccountId",
            "in": "path",
            "required": true,
            "type": "string"
          }
        ],
        "security":[{
          "Bearer": []
        }],
        "responses": {
          "204": {
            "description": "No Content"
          },
          "400": {
            "description": "BadRequest",
            "schema": {
              "$ref": "#/definitions/ErrorResponse"
            }
          }, …
Run Code Online (Sandbox Code Playgroud)

c# swagger-ui asp.net-core

45
推荐指数
7
解决办法
4万
查看次数

在ASP.NET Core中使用Swagger中的JWT(授权:承载)

我正在ASP.NET Core 1.0中创建一个REST api.我正在使用Swagger进行测试,但现在我为某些路线添加了JWT授权.(带UseJwtBearerAuthentication)

是否可以修改Swagger请求的标头,以便[Authorize]可以测试具有该属性的路由?

c# jwt swagger asp.net-core

26
推荐指数
5
解决办法
3万
查看次数

标签 统计

asp.net-core ×2

c# ×2

jwt ×1

swagger ×1

swagger-ui ×1