У меня проблемы с авторизацией моей учетной записи с помощью Spotify API. Когда я пытаюсь перенаправить со страницы авторизации Spotify на мой localhost:9090/home
, браузер сообщает мне, что меня перенаправляли слишком много раз. Я предполагаю, что проблема в том, что он не распознает / не знает, что я только что вошел в систему, и при попытке получить доступ к странице, требующей авторизации, я отклоняюсь и застреваю в цикле перенаправления.
ApplicationSecurity.java
package com.programmer.gate;
import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
@EnableOAuth2Sso
public class ApplicationSecurity extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.antMatcher("/**")
.authorizeRequests()
.antMatchers("/", "/callback", "/login**", "/webjars/**", "/error**","/oauth/token")
.permitAll()
.antMatchers("/**","/callback","/home/**").authenticated()
.anyRequest()
.authenticated();
}
}
HomeController.java
package com.programmer.gate;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class HomeController {
@RequestMapping("/")
public String login() {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
System.out.println(auth.getPrincipal());
return "/index";
}
@RequestMapping(value = "/home")
@ResponseBody
public String callback(@RequestParam(value = "code") String code, @RequestParam(value = "state") String state) {
System.out.println("redirecting to home page");
System.out.println("CODE: " + code);
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
System.out.println(auth.getDetails());
return "/home";
}
}
application.properties
server.port=9090
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
server.error.whitelabel.enabled=false
security.oauth2.client.clientId=<CLIENT_ID>
security.oauth2.client.clientSecret=<CLIENT_SECRET>
security.oauth2.client.preEstablishedRedirectUri=http://localhost:9090/home
security.oauth2.client.accessTokenUri=https://accounts.spotify.com/api/token
security.oauth2.client.userAuthorizationUri=https://accounts.spotify.com/authorize
security.oauth2.client.tokenName=oauth_token
security.oauth2.client.authenticationScheme=query
security.oauth2.client.clientAuthenticationScheme=form
security.oauth2.client.scope=playlist-read-private
security.oauth2.resource.user-info-uri=https://accounts.spotify.com/me
security.oauth2.client.useCurrentUri=false
Есть ли здесь что-нибудь, что можно изменить, что позволит фону распознаватьчто я не "анонимный пользователь"?