Swagger 编辑器未通过请求中的授权 Header
Swagger Editor Not Passing Authorization in the Request Header
我第一次使用 Swagger Editor 来测试 API。我 运行 在本地使用它。我的授权有效,但我的第一个 GET 路径模式一直返回 "Failed to fetch" 错误。
当我 运行 Swagger 在 GitBash 中生成 Curl 代码时,我得到了我期望的结果,所以我需要的一切都在模式中。当我在 Swagger 编辑器中 运行 时,我无法得到响应。
据我所知,Swagger Editor 没有在请求中包含授权令牌 Header。这是来自我的浏览器控制台的请求...
我知道这可能是一个 CORS 问题 - 但我不是服务器管理员,我无权对服务器进行更改。有什么我需要告诉服务器管理员的吗?或者我需要在我的本地计算机上更改某些内容以将授权代码包含在 header 请求中吗?我的服务器管理员说 CORS 已正确启用。
奇怪的是,如果我复制由 Swagger Editor 生成的 CURL 字符串,并将其粘贴到 GitBash 中,它 运行 正确并且我得到了我期望的结果。这是 CURL 刺...
如果有帮助,这是我的 Swagger JSON。
{
"swagger":"2.0",
"info":{
"description":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi molestie sem nec nibh blandit efficitur. Donec arcu massa, semper ut mauris eu, fermentum dictum turpis. [Test Link](http://google.com) Duis efficitur at sapien non maximus. ",
"version":"1.0.0",
"title":"LA-API",
"termsOfService":"http://swagger.io/terms/",
"contact":{
"email":"apiteam@swagger.io"
},
"license":{
"name":"Apache 2.0",
"url":"http://www.apache.org/licenses/LICENSE-2.0.html"
}
},
"host":"betaapi.myDomain.com",
"basePath":"/",
"tags":[
{
"name":"Account",
"description":"First try at adding LA-API Swagger paths",
"externalDocs":{
"description":"Find out more",
"url":"http://swagger.io"
}
}
],
"schemes":[
"http"
],
"securityDefinitions":{
"la-api_auth":{
"type":"oauth2",
"tokenUrl":"http://betaauthorize.myDomain.com/access_token",
"flow":"password",
"scopes":{
"write:la":"Lorem ipsum",
"read:la":"Dolor sit amet"
}
},
"api_key":{
"type":"apiKey",
"name":"Authorization",
"in":"header"
}
},
"paths":{
"/api/account/{account_id}":{
"get":{
"tags":[
"Account"
],
"summary":"Account - View",
"description":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
"operationId":"AccountView",
"produces":[
"application/json"
],
"parameters":[
{
"name":"account_id",
"in":"path",
"description":"ID of Account to return",
"required":true,
"type":"integer",
"format":"int64"
}
],
"security":[
{
"la-api_auth":[
"write:la",
"read:la"
]
}
],
"responses":{
"200":{
"description":"successful operation"
},
"400":{
"description":"Invalid Account ID supplied"
},
"401":{
"description":"Authorization token is required and has failed or has not yet been provided"
},
"404":{
"description":"Account ID not found"
}
}
}
}
},
"definitions":{
"Account":{
"type":"object",
"properties":{
"sms_id":{
"type":"integer",
"format":"int64",
"example":"370"
},
"address1":{
"type":"string",
"example":"123%"
},
"city":{
"type":"string",
"example":"Test%"
},
"state_id":{
"type":"string",
"example":"TN"
}
}
},
"ApiResponse":{
"type":"object",
"properties":{
"code":{
"type":"integer",
"format":"int32"
},
"type":{
"type":"string"
},
"message":{
"type":"string"
}
}
}
},
"externalDocs":{
"description":"Find out more about Swagger",
"url":"http://swagger.io"
}
}
如有任何建议,我们将不胜感激。谢谢
使用此资源:https://www.w3.org/TR/cors/#cross-origin-request-with-preflight-0
OPTIONS 请求应排除用户凭据,因此服务器也不应响应 401。
我第一次使用 Swagger Editor 来测试 API。我 运行 在本地使用它。我的授权有效,但我的第一个 GET 路径模式一直返回 "Failed to fetch" 错误。
当我 运行 Swagger 在 GitBash 中生成 Curl 代码时,我得到了我期望的结果,所以我需要的一切都在模式中。当我在 Swagger 编辑器中 运行 时,我无法得到响应。
据我所知,Swagger Editor 没有在请求中包含授权令牌 Header。这是来自我的浏览器控制台的请求...
我知道这可能是一个 CORS 问题 - 但我不是服务器管理员,我无权对服务器进行更改。有什么我需要告诉服务器管理员的吗?或者我需要在我的本地计算机上更改某些内容以将授权代码包含在 header 请求中吗?我的服务器管理员说 CORS 已正确启用。
奇怪的是,如果我复制由 Swagger Editor 生成的 CURL 字符串,并将其粘贴到 GitBash 中,它 运行 正确并且我得到了我期望的结果。这是 CURL 刺...
如果有帮助,这是我的 Swagger JSON。
{
"swagger":"2.0",
"info":{
"description":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi molestie sem nec nibh blandit efficitur. Donec arcu massa, semper ut mauris eu, fermentum dictum turpis. [Test Link](http://google.com) Duis efficitur at sapien non maximus. ",
"version":"1.0.0",
"title":"LA-API",
"termsOfService":"http://swagger.io/terms/",
"contact":{
"email":"apiteam@swagger.io"
},
"license":{
"name":"Apache 2.0",
"url":"http://www.apache.org/licenses/LICENSE-2.0.html"
}
},
"host":"betaapi.myDomain.com",
"basePath":"/",
"tags":[
{
"name":"Account",
"description":"First try at adding LA-API Swagger paths",
"externalDocs":{
"description":"Find out more",
"url":"http://swagger.io"
}
}
],
"schemes":[
"http"
],
"securityDefinitions":{
"la-api_auth":{
"type":"oauth2",
"tokenUrl":"http://betaauthorize.myDomain.com/access_token",
"flow":"password",
"scopes":{
"write:la":"Lorem ipsum",
"read:la":"Dolor sit amet"
}
},
"api_key":{
"type":"apiKey",
"name":"Authorization",
"in":"header"
}
},
"paths":{
"/api/account/{account_id}":{
"get":{
"tags":[
"Account"
],
"summary":"Account - View",
"description":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
"operationId":"AccountView",
"produces":[
"application/json"
],
"parameters":[
{
"name":"account_id",
"in":"path",
"description":"ID of Account to return",
"required":true,
"type":"integer",
"format":"int64"
}
],
"security":[
{
"la-api_auth":[
"write:la",
"read:la"
]
}
],
"responses":{
"200":{
"description":"successful operation"
},
"400":{
"description":"Invalid Account ID supplied"
},
"401":{
"description":"Authorization token is required and has failed or has not yet been provided"
},
"404":{
"description":"Account ID not found"
}
}
}
}
},
"definitions":{
"Account":{
"type":"object",
"properties":{
"sms_id":{
"type":"integer",
"format":"int64",
"example":"370"
},
"address1":{
"type":"string",
"example":"123%"
},
"city":{
"type":"string",
"example":"Test%"
},
"state_id":{
"type":"string",
"example":"TN"
}
}
},
"ApiResponse":{
"type":"object",
"properties":{
"code":{
"type":"integer",
"format":"int32"
},
"type":{
"type":"string"
},
"message":{
"type":"string"
}
}
}
},
"externalDocs":{
"description":"Find out more about Swagger",
"url":"http://swagger.io"
}
}
如有任何建议,我们将不胜感激。谢谢
使用此资源:https://www.w3.org/TR/cors/#cross-origin-request-with-preflight-0
OPTIONS 请求应排除用户凭据,因此服务器也不应响应 401。