【发布时间】:2020-11-12 14:26:09
【问题描述】:
为了安全,我想使用基于 OAuth2 的 Angular 9 实现 Spring Boot 项目。我不清楚的问题是在用户身份验证后获取用户角色的最佳方法是什么。我找到了两种方法:
-
在使用 OAuth2 对用户进行身份验证后正确添加到响应负载中:
{ "access_token": "wdwdw", "token_type": "bearer", "refresh_token": "wdwdwdwd", "expires_in": 4, "scope": "read", "role": [ "ROLE_ADMIN" ], "jti": "wfwfe" } -
第二种方法是使用第二个 API 调用
oauth/check_token来获取角色:
$ curl localhost:8080/oauth/check_token/?token=fc9e4ad4-d6e8-4f57-b67e-c0285ddcdeb58
{
"scope": [
"read",
"write"
],
"active": true,
"exp": 1544940147,
"authorities": [
"ROLE_USER"
],
"client_id": "ger-client-id"
}
我对这两种方式中哪一种在安全性和最佳实践方面更好感兴趣。
【问题讨论】:
标签: angular spring-security-oauth2 angular9