Spring security 如何使用Postman身份验证帮助程序调用JHipster(Spring)OAuth2 Rest服务器
Postman必须帮助进行身份验证呼叫,我正在尝试使用调用JHipster使用Spring(安全、社交等)创建的REST服务器 我尝试了很多配置,这是屏幕(客户端ID和密码被屏蔽): 对于我尝试过的授权URL:Spring security 如何使用Postman身份验证帮助程序调用JHipster(Spring)OAuth2 Rest服务器,spring-security,spring-security-oauth2,jhipster,postman,spring-oauth2,Spring Security,Spring Security Oauth2,Jhipster,Postman,Spring Oauth2,Postman必须帮助进行身份验证呼叫,我正在尝试使用调用JHipster使用Spring(安全、社交等)创建的REST服务器 我尝试了很多配置,这是屏幕(客户端ID和密码被屏蔽): 对于我尝试过的授权URL: (应用程序的登录路径) 我收到邮递员的代币越近: 我不知道为什么会这样出错。也许我设置的回调URL不正确?我需要在服务器或客户端(AngularJS)中执行此操作吗 有人知道怎么回事吗?非常感谢您的帮助。JHipster当前设置为使用“密码”oauth2授权类型。助手oauth
- (应用程序的登录路径)
有人知道怎么回事吗?非常感谢您的帮助。JHipster当前设置为使用“密码”oauth2授权类型。助手oauth2助手似乎只处理“授权代码”和“客户端凭据”授权类型 您要做的是首先直接调用应用程序的令牌端点,就像angular应用程序在中所做的那样 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
其中,您的用户名和密码可以分别为“user”和“user”,例如,设置了一个标题:
Authorization: Basic AAAAAA
其中AAAAAA是您的(clientId+:“+clientSecret)--所有base64编码。你可以用。例如,如果您的clientId是“jhipsterapp”,而您的clientSecret是“mySecretOAuthSecret”,则将AAAAA替换为“amhpcHN0ZXJhcHA6bXlTZWNyZXRPQXV0aFNlY3JldA=”,因为这是“jhipsterapp:mySecretOAuthSecret”base64编码的
这将返回一个访问令牌。现在,使用头中的密码请求中的access_令牌调用API端点,如下所示
Authorization: Bearer access_token_from_earlier_token_request
更新:如果您使用的是微服务和UAA,请参阅Niel的答案以@sdoxsee的答案为基础: 目前(2017年8月),JHipster使用
configure(ClientDetailsServiceConfigurer)
方法生成一个名为UaaConfiguration
的类,该方法设置客户端ID、客户端机密、范围和授权类型。参考这些设置(包括应用程序*.yml
中引用的JHipster属性),使用/oauth/token
作为身份验证URL和访问令牌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