Ala*_*tan 3 oauth-2.0 spring-boot
我创建了一个Spring Boot应用程序,我有授权和资源服务器,这是我的主要类:
@SpringBootApplication
@EnableResourceServer
@EnableAuthorizationServer
public class OauthServerApplication {
public static void main(String[] args) {
SpringApplication.run(OauthServerApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的application.yml:
security:
user:
name: guest
password: guest123
oauth2:
client:
client-id: trustedclient
client-secret: trustedclient123
authorized-grant-types: authorization_code,refresh_token,password
scope: openid
Run Code Online (Sandbox Code Playgroud)
要生成访问令牌,我只执行此URL(POST):
http://trustedclient:trustedclient123@localhost:8080/oauth/token?username=guest&password=guest123&grant_type=password
Run Code Online (Sandbox Code Playgroud)
它返回:
{
"access_token": "f2e722b7-3807-4a27-9281-5b28b7bd3d0d",
"token_type": "bearer",
"refresh_token": "f96d472c-8259-42e2-b939-4963dfeeb086",
"scope": "openid"
}
Run Code Online (Sandbox Code Playgroud)
现在我需要知道如何验证令牌是否正确,任何帮助?
您有多种可能性,您可以:
1)将令牌存储在a中,TokenStore并在资源服务器的授权服务器上打开安全的验证令牌点.
2)如果授权服务器和资源服务器可以共享一个DataSource,(在您的情况下,它很容易,因为两者都在同一个应用程序中).它们都可以使用JdbcTokenStore指向同一数据库,资源服务器可以直接检查此令牌存储中令牌的有效性.请参阅本教程:Spring REST API + OAuth2 + AngularJS
3)您可以使用签名的JWT令牌与JwtTokenStore和JwtAccessTokenConverter.请参阅本教程:将JWT与Spring Security OAuth配合使用
这两个教程都基于以下github存储库:https://github.com/Baeldung/spring-security-oauth
| 归档时间: |
|
| 查看次数: |
11010 次 |
| 最近记录: |