【问题标题】:Spring Oauth2 and Rest BackendSpring Oauth2 和 Rest 后端
【发布时间】:2018-03-24 15:12:14
【问题描述】:

我已成功完成本教程。 https://spring.io/guides/tutorials/spring-boot-oauth2/#_social_login_authserver

但是,我似乎无法将其用作休息后端服务。我总是从授权服务器获取登录页面。

我怎样才能让它工作?

我在帖子中使用以下标题。

Authorization: Bearer <my access token from facebook>
Content-type: application/x-www-form-urlencoded

客户端/资源服务器如下所示:

@EnableAutoConfiguration
@Configuration
@EnableOAuth2Sso
@RestController
public class ClientApplication extends WebSecurityConfigurerAdapter {

    @RequestMapping("/")
    public String home(Principal user) {
        return "Hello " + user.getName();
    }

    public static void main(String[] args) {
        new SpringApplicationBuilder(ClientApplication.class)
            .properties("spring.config.name=client").run(args);
    }

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http.antMatcher("/**").authorizeRequests().anyRequest().authenticated().and().exceptionHandling().and().csrf().disable();
    }
}

【问题讨论】:

    标签: spring spring-boot spring-security spring-security-oauth2


    【解决方案1】:

    在访问资源服务器之前首先访问授权服务器,这就是为什么您总是从授权服务器看到页面的原因。我建议您对 OAuth2 概念有很好的理解。我遵循了本教程,它非常有帮助。 [http://websystique.com/spring-security/secure-spring-rest-api-using-oauth2/][1]

    【讨论】:

    • 所以基本上我需要禁用授权服务器上的登录表单并让资源服务器使用rest来授权发布的访问令牌,对吗?编辑:我想使用 Facebook 作为授权服务器,我不想自己创建自定义用户/用户详细信息。
    • 在这里,我相信您尝试使用 facebook oauth2 作为授权服务器,对吗?如果是这种情况,那么您需要按照您所说的从授权服务器中删除登录表单。
    猜你喜欢
    • 2017-05-28
    • 2017-02-12
    • 2018-05-07
    • 2020-07-13
    • 2021-06-05
    • 2015-05-22
    • 2017-03-30
    • 1970-01-01
    • 2017-04-04
    相关资源
    最近更新 更多