【发布时间】:2017-04-12 07:59:25
【问题描述】:
我通过定义以下配置以及相应的 application.yml 文件来启用 google auth。
@EnableOAuth2Sso
@Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.antMatcher("/**")
.authorizeRequests()
.antMatchers("/", "/login**").permitAll()
.anyRequest().authenticated()
.and()
.exceptionHandling()
.authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/"));
}
}
我可以通过浏览器访问我的各种端点。但客户端可能并不总是浏览器。
我有一个控制器方法定义如下
@GetMapping("/user")
public Principal getUser(Principal principal) {
return principal;
}
从返回的 Principal 我可以看到类型为 Bearer 的 tokenValue。我怎样才能对我的api使用它?或其他代币。我只是想使用 google auth 和 oauth 访问我自己的 api。
wget -i http://localhost:8080/user -H "Authorization: Bearer $TOKEN"
将我重定向到登录页面。
为了澄清一点,我想使用 google auth 进行身份验证,但能够使用 oauth 访问我的 api。天气是谷歌返回的令牌还是春天生成的令牌都没有关系。关于如何实现这一点的任何线索?
【问题讨论】:
标签: spring spring-security oauth google-oauth spring-security-oauth2