Den*_*edo 9 spring-security spring-security-oauth2 jhipster postman spring-oauth2
Postman有身份验证帮助程序来帮助进行身份验证调用,我正在尝试使用OAuth 2.0帮助程序使用Spring(安全,社交等)调用由JHipster创建的REST服务器.
我尝试了很多配置,这是屏幕(客户端ID和秘密被屏蔽):
对于我尝试过的授权URL:
我从收到令牌回到邮递员的距离越近:
我不知道为什么这样犯错.也许我错误地设置了回拨网址?我是否需要在服务器或客户端(AngularJS)中执行此操作?
有没有人知道什么是错的?我感谢您的帮助.
sdo*_*see 19
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
Run Code Online (Sandbox Code Playgroud)
例如,您的用户名和密码分别为"user"和"user",并且设置了一个标头:
Authorization: Basic AAAAAA
Run Code Online (Sandbox Code Playgroud)
其中AAAAAA是您的(clientId +":"+ clientSecret) - 所有base64编码.您可以使用https://www.base64encode.org/.例如,如果您的clientId是"jhipsterapp"而您的clientSecret是"mySecretOAuthSecret",则将AAAAAA替换为"amhpcHN0ZXJhcHA6bXlTZWNyZXRPQXV0aFNlY3JldA ==",因为这是"jhipsterapp:mySecretOAuthSecret"base64-encoded.
那应该给你一个access_token.现在点击您的API端点,通过您的标头中的密码请求使用access_token调用它们,就像这样.
Authorization: Bearer access_token_from_earlier_token_request
Run Code Online (Sandbox Code Playgroud)
更新:如果您正在使用微服务和UAA,请参阅Niel的回答/sf/answers/3188485261/
以@sdoxsee的答案为基础:
当前(2017年8月),JHipster生成一个类,该类UaaConfiguration使用configure(ClientDetailsServiceConfigurer)设置客户端ID,客户端密码,范围和授予类型的方法来调用。请参考这些设置(包括中引用的JHipster属性application*.yml)以/oauth/token同时使用Auth URL和Access Token URL来填充Postman身份验证帮助器。
例:
@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");
}
Run Code Online (Sandbox Code Playgroud)
和,
jhipster:
security:
client-authorization:
client-id: internal
client-secret: internal
Run Code Online (Sandbox Code Playgroud)
意味着您的身份验证助手应如下填充:
| 归档时间: |
|
| 查看次数: |
7278 次 |
| 最近记录: |