【问题标题】:How can i access spring oauth2 client backend api by token instead of jsession in cookie?如何通过令牌而不是cookie中的jsession访问spring oauth2客户端后端api?
【发布时间】:2020-03-28 09:45:46
【问题描述】:

我知道你可能被标题弄糊涂了。请看图片。

我有一个由 spring security 和 spring security oauth2 客户端保护的后端服务器。

@EnableWebSecurity
public class OAuth2ClientSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .anyRequest().authenticated()
                .and()
                .oauth2Login();
    }
}

当我访问 localhost:8080/api/get/{id} 在 cookie 中使用 JSessionId 时,这工作正常。

但我想使用基于令牌的身份验证,以便我的 Angular 应用程序可以访问我的后端。我该怎么办?

登录后如何获取令牌而不是 cookie?

请给我一些建议,提前谢谢你。

【问题讨论】:

    标签: angular spring spring-security oauth-2.0


    【解决方案1】:

    此解决方案有 3 个部分,如我的教程 + 代码示例中所述: https://authguidance.com/2017/09/24/basicspa-overview/

    第 1 步:使用基于标准的授权服务器 (AS)

    第 2 步:在 Angular 应用中使用 oidc 客户端库将用户重定向到 AS 以登录并获取访问令牌

    第 3 步:验证 API 中的访问令牌

    【讨论】:

      最近更新 更多