【发布时间】:2018-05-08 14:18:14
【问题描述】:
我想将 oauth2 身份验证添加到我的 Web API,因此我创建了一个带有安全定义的规范:
"securityDefinitions": {
"OauthSecurity": {
"type": "oauth2",
"authorizationUrl": "http://localhost/oauth/dialog",
"flow": "implicit",
"scopes": {
"admin": "Admin scope",
"user": "User scope",
"media": "Media scope"
}
}
},
"security": [
{
"OauthSecurity": [
"user"
]
}
],
所以它在我的 API 上生成了一些注释:
@io.swagger.annotations.Authorization(value = "OauthSecurity", scopes = {
@io.swagger.annotations.AuthorizationScope(scope = "user", description = "User scope")
})
那么我现在该如何继续呢?我仍然可以毫无问题地访问(没有任何标题或令牌或其他任何东西的卷曲)我的 API。
当然我可以创建 auth endpdoint,但我不知何故错过了生成的 API 和 oauth 之间的链接。
【问题讨论】:
-
除非您在 API 端指定用户或媒体或管理员范围指定的内容,否则我怀疑这会起作用。
-
整个 api 现在是这个设置的用户范围。当我从 swagger 中查看 petstore 示例时,他们使用了 read_pets 和 write_pets 但也没有明确指定它们 editor.swagger.io/#
-
这有什么更新吗?我也找不到关于该主题的好的文档。
-
@SuleymanArslan 看到我的答案
标签: java rest authentication oauth-2.0 swagger