Mur*_*art 7 java spring spring-security angularjs spring-oauth2
我必须将我的系统与第三方提供商集成.该系统由Spring和Angular制作.
请记住,我需要创建自定义登录表单,而不是重定向到OAuth2等第三方提供商表单.
他创建了以下端点:
POST http://example.com/webapi/api/web/token
“username=972.344.780-00&password=123456&grant_type=password”
Run Code Online (Sandbox Code Playgroud)
响应发送给我一个我必须在所有下一个请求中使用的令牌.
Authorization: Bearer V4SQRUucwbtxbt4lP2Ot_LpkpBUUAl5guvxAHXh7oJpyTCGcXVTT-yKbPrPDU9QII43RWt6zKcF5m0HAUSLSlrcyzOuJE7Bjgk48enIoawef5IyGhM_PUkMVmmdMg_1IdIb3Glipx88yZn3AWaneoWPIYI1yqZ9fYaxA-_QGP17Q-H2NZWCn2lfF57aHz8evrRXNt_tpOj_nPwwF5r86crEFoDTewmYhVREMQQjxo80
GET http://example.com/webapi/api/web/userInfo
Run Code Online (Sandbox Code Playgroud)
那就是说,我需要实现自定义身份验证?
在这种情况下我可以使用Spring OAuth2吗?
是的,您可以使用 Spring Oauth2。您必须实施资源所有者密码凭据授予 Oauth2 流程。您必须为最终用户创建一个登录页面,并且您的客户端应用程序会将用户的凭据以及您的客户端系统凭据(对客户端系统凭据使用 HTTP 基本身份验证)发送到授权服务器以获取令牌。
有两种方法可以实现它 -
卷曲-u 972.344.780-00:123456“ http://example.com/webapi/api/web/token?grant_type=password&username=addEndUserNameHere&password=addEndUserPasswordHere ”
AuthorizationServerConfigurerAdapter 的子类应具有以下代码 -
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
.withClient("clientId")
.authorizedGrantTypes("password")
.authorities("ROLE_CLIENT")
.scopes("read");
}
}
@Override
public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
oauthServer.allowFormAuthenticationForClients();
}
Run Code Online (Sandbox Code Playgroud)
现在您可以使用以下内容 -
注意 - 此流程的安全性低于其他 Oauth2 流程,仅建议用于受信任的客户端应用程序,因为用户必须向客户端应用程序提供凭据。
归档时间: |
|
查看次数: |
1779 次 |
最近记录: |