我有一个非常简单的Spring Boot应用程序
全部的
需要通过Google Oauth2验证的页面。我跟着
Spring Oauth2 tuotrial
看着
code under the /simple implementation
。(My application.yml文件是为Google而不是FB设置的)
对我的应用程序的任何请求都会返回401个未经授权的响应,并转到localhost:8080/登录。。。(Spring security自动生成的登录页面,在Google开发者控制台中设置为重定向URI)
我已经研究了所有其他试图回答这个问题的问题,但都没有任何帮助。
我的应用程序类别:
@SpringBootApplication
@EnableOAuth2Sso
@RestController
public class ControlApplication extends WebSecurityConfigurerAdapter {
public static void main(String[] args) {
SpringApplication.run(ControlApplication.class, args);
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.antMatcher("/**").authorizeRequests().anyRequest().authenticated().and().formLogin().defaultSuccessUrl("/", false);
}
}
还有我的申请。yml:
security:
oauth2:
client:
clientId: [MyClientID]
clientSecret: [MyClientSecret]
accessTokenUri: https://accounts.google.com/o/auth2/token
userAuthorizationUri: https://accounts.google.com/o/oauth2/auth?hd=xyz.com
redirectUri: http://localhost:8080
clientAuthenticationScheme: form
tokenName: oauth_token
authenticationScheme: query
scope:
- email
- profile
resource:
userInfoUri: https://www.googleapis.com/oauth2/v3/userinfo
preferTokenInfo: true