Postman 有身份验证助手来帮助进行身份验证的调用,我正在尝试使用OAuth 2.0 助手来调用JHipster使用Spring(安全、社交等)创建的 REST 服务器。
我已经尝试了很多配置,这是屏幕(客户端 ID 和 Secret 被屏蔽):
对于我尝试过的授权 URL :
我从收到一个令牌返回 Postman 越接近:
我不知道为什么会出现这样的错误。也许我错误地设置了回调 URL?我需要在服务器或客户端(AngularJS)中执行此操作吗?
有谁知道出了什么问题?我感谢您的帮助。
Postman 有身份验证助手来帮助进行身份验证的调用,我正在尝试使用OAuth 2.0 助手来调用JHipster使用Spring(安全、社交等)创建的 REST 服务器。
我已经尝试了很多配置,这是屏幕(客户端 ID 和 Secret 被屏蔽):
对于我尝试过的授权 URL :
我从收到一个令牌返回 Postman 越接近:
我不知道为什么会出现这样的错误。也许我错误地设置了回调 URL?我需要在服务器或客户端(AngularJS)中执行此操作吗?
有谁知道出了什么问题?我感谢您的帮助。
JHipster 当前设置为使用“密码”oauth2 授权类型。助手 oauth2 助手似乎只适用于“授权码”和“客户端凭据”授权类型。
您要做的是首先直接调用您的应用程序的令牌端点,就像角度应用程序在 src/main/webapp/scripts/components/auth/provider/auth.oauth2.service.js 中所做的那样
POST http://localhost:8080/oauth/token?username=MY_USERNAME&password=MY_PASSWORD&grant_type=password&scope=read%20write
例如,您的用户名和密码可以分别是“用户”和“用户”,并设置一个标头:
Authorization: Basic AAAAAA
其中 AAAAAA 是您的 (clientId + ":" + clientSecret) - 所有 base64 编码。您可以使用https://www.base64encode.org/。例如,如果您的 clientId 是“jhipsterapp”并且您的 clientSecret 是“mySecretOAuthSecret”,请将 AAAAAA 替换为“amhpcHN0ZXJhcHA6bXlTZWNyZXRPQXV0aFNlY3JldA==”,因为它是“jhipsterapp:mySecretOAuthSecret”base64 编码的。
那应该会返回一个 access_token。现在,通过在您的标头中使用您的密码请求中的 access_token 调用它们来访问您的 API 端点,如下所示。
Authorization: Bearer access_token_from_earlier_token_request
更新:如果您使用微服务和 UAA,请参阅 Niel 的回答https://stackoverflow.com/a/45549789/1098564
以@sdoxsee 的回答为基础:
目前(2017 年 8 月)JHipster 生成一个类,该类使用设置客户端 ID、客户端密码、范围和授权类型UaaConfiguration的方法调用。configure(ClientDetailsServiceConfigurer)请参考这些设置(包括 中引用的 JHipster 属性application*.yml)来填充 Postman 身份验证帮助程序,/oauth/token同时使用Auth URL和Access Token URL。
例子:
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
/*
For a better client design, this should be done by a ClientDetailsService (similar to UserDetailsService).
*/
clients.inMemory()
.withClient("web_app")
.scopes("openid")
.autoApprove(true)
.authorizedGrantTypes("implicit", "refresh_token", "password", "authorization_code")
.and()
.withClient(jHipsterProperties.getSecurity().getClientAuthorization().getClientId())
.secret(jHipsterProperties.getSecurity().getClientAuthorization().getClientSecret())
.scopes("web-app")
.autoApprove(true)
.authorizedGrantTypes("client_credentials");
}
和,
jhipster:
security:
client-authorization:
client-id: internal
client-secret: internal
意味着您的身份验证助手应按如下方式填充: