我想将oauth2身份验证添加到我的Web API中,因此我创建了一个带有securitydefinitions的规范:
"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之间的链接。
答案 0 :(得分:1)
根据this,通过使用OpenAPI 3.0,您可以这样做:
components:
securitySchemes:
oAuthSample: # <---- arbitrary name
type: oauth2
description: This API uses OAuth 2 with the implicit grant flow. [More info](https://api.example.com/docs/auth)
flows:
implicit: # <---- OAuth flow(authorizationCode, implicit, password or clientCredentials)
authorizationUrl: https://api.example.com/oauth2/authorize
scopes:
read_pets: read your pets
write_pets: modify pets in your account
我目前正在使用Bearer Auth,效果非常好。
希望它有所帮助!