묻고 답해요
161만명의 커뮤니티!! 함께 토론해봐요.
인프런 TOP Writers
-
미해결스프링 시큐리티 OAuth2
jwt token의 토큰 검증
안녕하세요강의에서는 resource 서버가 받은 토큰 검증 과정에서 opaqueToken을 사용하고 있는데요.JWT 경우로 질문을 드리고 싶습니다.JWT토큰도 opaqueToken과 마찬가지로 oauth2/revoke api를 호출하면 정상적으로 meta.invalidated 필드가 true로 변경되는 것을 확인했습니다.해당 필드가 true로 변경되었음에도 불과하고 resource 서버에 동일한 토큰으로 요청을 보내도 정상적으로 동작하고 있는 것을 확인했는데요. jwtToken 방식의 경우에는 토큰 검증시 최초에만 jwkSet을 가져오기 위해 한번만 authorization server를 호출하고 이후에는 내부적으로 jwtDecoder를 사용해 검증하는 것으로 보입니다. 결론적으로 jwtToken을 사용할때는 oauth2/revoke를 통해 meta.invalidated 값과 무관하게 토큰 만료 전까지는 지속적으로 접근이 가능한 것으로 보이는데요.제가 이해한 흐름이 맞을까요?
-
미해결스프링 시큐리티 OAuth2
Resources Server 질문
안녕하세요 수원님 ! 강의를 수강하다가 헷갈리는 내용이 생겨 질문드립니다 ! 위와 같은 그림을 설명하실때, 스프링 서버는 Client 의 역할을 하신다고 하셨습니다. 이후 Resource Server 를 강의하시는 파트에서는 스프링 서버가 리소스 서버가 된다고 하셨는데, 이 부분에서 혼동이 발생하여 질문드립니다. 카카오와 같은 소셜 로그인 기능을 구현한다고 가정하겠습니다.스프링 서버가 JWT 의 의존성을 갖고, 프론트에게 토큰을 발행해주는 서비스를 구현한다면, 이때 스프링 서버는 Client 와 Resourse Server 의 역할을 동시에 하는 것일까요??위와 같은 구조에서 토큰을 프론트에 발행할 때, 스프링은 카카오 인가 서버로 부터 토큰을 받고 해당 토큰을 그대로 내려주는 것일까요?? 보안상 문제가 발생하니 발급 받은 토큰을 기반으로 새로운 JWT 생성해서 내려주는 것일까요??소셜 로그인을 연동했다면, issuer-uri 에는 카카오의 인가 서버 Url 을 입력 하면 될까요??
-
미해결스프링 시큐리티 OAuth2
intellij 에서 스프링부트2.7.1 이 없어요
인텔리제이에서 하려고 합니다. 그런데 2.7.1도 없고 2.x.x중에 하나를 골랐는데 에러가 뜹니다. >=3.0.0-M1 이라고 처음부터 뜨고, 그냥 무시하고 만들어서 실행해보면 아예 빨간글이 쫙쫙 그어지면서 에러가 뜹니다. 이거를 어떻게 해결해야할지 모르겠습니다... 도와주세요...ㅠㅠㅠㅠ
-
미해결스프링 시큐리티 OAuth2
OAuth2 + JWT : 소셜 로그인 시 JWT 발급
제가 일반적은 시큐리티와 JWT 로그인하는 방법과 소셜 로그인 2개를 구현해서 어느 방법으로 하던 accessToken을 발급해주고 accessToken을 통해서 게시판이라던지 해당 유저 인지 판별할 때 accessToken으로 판별하려고 합니다.질문 1:해당 수업이 OAuth2가 메인이고 OAuth2와 JWT 토큰과는 별개인 것은 알고 있지만 찾아봐도 못찾겠어서 질문을 남깁니다. accessToken을 발급받으면 클라이언트가 header에 accessToken을 같이 요청을 보내 줄 때 보내주고(저 같은 경우 TokenDTO와 TokenEntitty를 만들어줘서 DB에 넣어줌 )DB에 담긴 정보:grantTypeaccessTokenrefreshTokenuserEmailnickName서버(백엔드)에서는 그 accessToken을 받아서 유효성 검사를 통과하면 컨트롤러나 서비스에서 뭔가 해주지 않아도 클라이언트 요청을 실행해줌// 클라이언트 요청 시 JWT 인증을 하기 위해 설치하는 커스텀 필터로 // UsernamePasswordAuthenticationFiler 이전에 실행된다. // 이전에 실행된다는 뜻은 JwtAuthenticationFilter를 통과하면 // UsernamePasswordAuthenticationFilter 이후의 필터는 통과한 것으로 본다는 뜻이다. // 쉽게 말해서, Username + Password를 통한 인증을 Jwt를 통해 수행한다는 것이다. // JWT 방식은 세션과 다르게 Filter 하나를 추가해야 합니다. // 이제 사용자가 로그인을 했을 때, Request에 가지고 있는 Token을 해석해주는 로직이 필요합니다. // 이 역할을 해주는것이 JwtAuthenticationFilter입니다. // 세부 비즈니스 로직들은 TokenProvider에 적어둡니다. 일종의 service 클래스라고 생각하면 편합니다. // 1. 사용자의 Request Header에 토큰을 가져옵니다. // 2. 해당 토큰의 유효성 검사를 실시하고 유효하면 // 3. Authentication 인증 객체를 만들고 // 4. ContextHolder에 저장해줍니다. // 5. 해당 Filter 과정이 끝나면 이제 시큐리티에 다음 Filter로 이동하게 됩니다. @RequiredArgsConstructor @Slf4j public class JwtAuthenticationFilter extends GenericFilterBean { public static final String HEADER_AUTHORIZATION = "Authorization"; private final JwtProvider jwtProvider; // doFilter는 토큰의 인증정보를 SecurityContext에 저장하는 역할 수행 @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpServletRequest = (HttpServletRequest) request; // Request Header에서 JWT 토큰을 추출 String jwt = resolveToken(httpServletRequest); String requestURI = httpServletRequest.getRequestURI(); if(StringUtils.hasText(jwt) && jwtProvider.validateToken(jwt)){ // 토큰이 유효할 경우 토큰에서 Authentication 객체를 가지고 와서 SecurityContext에 저장 Authentication authentication = jwtProvider.getAuthentication(jwt); SecurityContextHolder.getContext().setAuthentication(authentication); log.info("Security Context에 '{}' 인증 정보를 저장했습니다., uri : {}", authentication.getName(), requestURI); } else { log.debug("유효한 JWT 토큰이 없습니다. uri : {}", requestURI); } chain.doFilter(request, response); } // Request Header 에서 토큰 정보를 꺼내오기 위한 메소드 private String resolveToken(HttpServletRequest httpServletRequest) { String bearerToken = httpServletRequest.getHeader(HEADER_AUTHORIZATION); if(StringUtils.hasText(bearerToken) && bearerToken.startsWith("Bearer ")) { return bearerToken.substring(7); } else { return null; } } }여기서 필요하거나 자세히 진행하고 싶다면 DB에서 체크해서DB에서 accessToken과 비교해서 맞으면UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(userEmail, userPw);로 아이디와 비밀번호를 기반으로 생성했으니 해당 유저가 맞으므로 요청을 성공적으로 받아준다. 이게 맞는 흐름인가요? 질문 2:먼저, 로그인 시 accessToken과 refreshToken을 발급해주는 것은 구현을 했는데 소셜 로그인에서 JWT를 발급해주는 것이 헷갈리더군요. // 로그인 @PostMapping("/login") public ResponseEntity<TokenDTO> login(@RequestBody MemberDTO memberDTO) throws Exception { try { return memberService.login(memberDTO.getUserEmail(), memberDTO.getUserPw()); } catch (Exception e) { return ResponseEntity.badRequest().build(); } }// 로그인 public ResponseEntity<TokenDTO> login(String userEmail, String userPw) throws Exception { // Login ID/PW를 기반으로 UsernamePasswordAuthenticationToken 생성 UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(userEmail, userPw); // 실제 검증(사용자 비밀번호 체크)이 이루어지는 부분 // authenticateToken을 이용해서 Authentication 객체를 생성하고 // authentication 메서드가 실행될 때 // CustomUserDetailsService에서 만든 loadUserbyUsername 메서드가 실행 Authentication authentication = authenticationManagerBuilder .getObject() .authenticate(authenticationToken); // 해당 객체를 SecurityContextHolder에 저장 SecurityContextHolder.getContext().setAuthentication(authentication); // authentication 객체를 createToken 메소드를 통해서 생성 // 인증 정보를 기반으로 생성 TokenDTO tokenDTO = jwtProvider.createToken(authentication); HttpHeaders headers = new HttpHeaders(); // response header에 jwt token을 넣어줌 headers.add(JwtAuthenticationFilter.HEADER_AUTHORIZATION, "Bearer " + tokenDTO); MemberEntity member = memberRepository.findByUserEmail(userEmail); log.info("member : " + member); TokenEntity tokenEntity = TokenEntity.builder() .grantType(tokenDTO.getGrantType()) .accessToken(tokenDTO.getAccessToken()) .refreshToken(tokenDTO.getRefreshToken()) .userEmail(tokenDTO.getUserEmail()) .nickName(member.getNickName()) .build(); log.info("token : " + tokenEntity); tokenRepository.save(tokenEntity); TokenDTO token = TokenDTO.toTokenDTO(tokenEntity); return new ResponseEntity<>(token, headers, HttpStatus.OK); }(JWT 설정을 생략...) 소셜 로그인 같은 경우는 프론트에서 특정 URL로 보내주잖아요<a href="/oauth2/authorization/google">구글 로그인</a>위의 방법은 그냥 아이디, 비밀번호를 치면 되는 방법이고 소셜 로그인도 1차 인증을 받고 JWT를 발급해주면 된다고 알고있는데 위에서 구현한 방법으로 사용하기에는 URL이 다르잖아요? 프론트 URL은 고정으로 저 방법을 사용해야 한다고 알고 있는데... 그러면 소셜 로그인을 여러개 사용하면 예를들어, 구글, 카카오톡, 네이버 이런식으로 사용하면 컨트롤러에 각각의 URL로 위의 방식처럼 만들어야 JWT 발급해주는 기능을 구현할 수 있는건가요?
-
미해결스프링 시큐리티 OAuth2
소셜 로그인 인증이 안되는 문제
security: oauth2: client: registration: kakao: clientId: client-secret: scope: account_email, profile_nickname, profile_image , openid client-name: Kakao authorization-grant-type: authorization_code redirect-uri: http://127.0.0.1:9000/login/oauth2/code/kakao client-authentication-method: POST provider: kakao: authorization-uri: https://kauth.kakao.com/oauth/authorize token-uri: https://kauth.kakao.com/oauth/token user-info-uri: https://kapi.kakao.com/v2/user/me user-name-attribute: id gateway.yml 은 다음과 같이 설정했고 코드는 강사님 코드를 참고하였습니다. oidc 방식으로 인증 요청을 카카오에 보내고 loaduser 가 실행될줄알고 디버그를 찍어봤는데 디버그도 안찍히고 위 화면에서 동의하고 계속하기를 누르면 다음과같이 나옵니다. 로그도 디버그도 안찍혀서 문제가 예측이안되네요 ㅠㅠㅠ scope 설정이나 localhost, 127.0.0.1 이런 자잘한 수정은 계속 해보는데 원인을 모르겠습니다..
-
미해결스프링 시큐리티 OAuth2
프론트 연동한 소셜 로그인 질문드립니다!
안녕하세요, 강사님. 타임리프를 이용하지 않고, React 로 화면을 구성 후구글, 카카오, 네이버, 깃허브 등 소셜 로그인을 구현하려고 합니다. 버튼 클릭 -> 소셜 로그인 창 팝업간단한 로직이 안되어 질문을 남깁니다 ㅜ.ㅜ강의에서는 <a th:href="@{/oauth2/authorization/google, kakao, naver}"> </a>위 코드로 진행이 잘 되었는데 해당 url 을 프론트에서 맵핑 시키기 위해서는 어떤 url 을 사용해야 하나요? @{/oauth2/authorization/google}위 url 이 어디에 맵핑이 되는건지 알고싶습니다. (강의 잘 듣고있고, 뒤쪽 resource server 까지 달려가고 있습니다!)
-
미해결스프링 시큐리티 OAuth2
안녕하세요! 소셜로그인 관련 질문입니다!
프로젝트MSA 환경에서 프론트는 외부 서버에서 별도로 배포합니다.프론트는 APIGateway 로만 데이터를 교환하고자 합니다.현재 카카오 로그인 기능만 구현하고자 하는데 이를 JWT + Redis 를 활용하여 JWT 토큰을 검증하고 Gateway 에서 검증하고 각 서비스를 호출 하는방식으로 구현하고자 합니다. 제가 이해한게 맞다면 자체 포함타입일거같습니다.플로우는 다음과 같습니다Front kakao click -> kakao 검증 -> 프로젝트 서비스의 회원(member) 별도 저장 이때 Front 요청-> gateway(Auth-client) 로드밸런싱-> Authorization Server(Auth-Server) kakao인증후 User권한 인가 jwt -> Front 요청 -> gateway(redis 에 세션,jwt 저장) 이렇게 될것이라고 생각하고 있었는데 강의를 보다보니 Kakao login 과 jwt 는 client 쪽인 apigateway 에서 구현을 해야하는건가요? 또한 개념적으로 접근하게 된다면 카카오로그인으로 회원을 인증하고 제가 만든 프로젝트의 권한을 인가개념을 분리해야하는건지 어렵더라구요 ㅠㅠ 기존에 모놀리식으로 할땐 검색하며 예제를 복붙하면서 따라하다보니 막상 인증/인가를 분리하려니 어려움을 겪고있습니다.
-
미해결스프링 시큐리티 OAuth2
권한 부여 타입 authorization code, credential, refresh token 타입만 지원??
OAuth 2.0 Authorization Server Metadata Endpoint / JWK Set Endpoint 2:40~2:55권한 부여 타입이 authorization code, credential, refresh token 타입만 지원한다고 하셨는데 좀 헷갈립니다. 인증 서비스를 개발할 때 권한 부여 타입에는 위 3가지말고도 Resource owner password 방식을 사용할 수도 있긴한거죠? 공식문서에서 어디를 참고하면 될까요..?근데 스프링 시큐리티에서 이 Resource owner password 방식의 자체 configure 를 지원하진 않는다. 로 이해하면 될까요.만약에 Resource owner password 타입으로 권한 부여 서비스를 개발하려면 저희가 직접 ~configure, provider 클래스를 생성하는 건가요?
-
미해결스프링 시큐리티 OAuth2
Authorization required for Client Registration Id
안녕하세요. 강의를 보다가 한 가지 궁금한게 있는데요!springsecurityconfig 클래스에서 어노테이션을 @Configuration@EnableWebSecurity 2개를 붙이게 되면 Authorization required for Client Registration Id: keycloak 에러가 발생하고 있는데, 이때는 yml파일에 설정해놓은 부분들을 다시 다 bean으로 등록을 해야하는걸까요..?
-
미해결스프링 시큐리티 OAuth2
springboot 3.1 마이그레이션
- 학습 관련 질문을 남겨주세요. 상세히 작성하면 더 좋아요! - 먼저 유사한 질문이 있었는지 검색해보세요. - 서로 예의를 지키며 존중하는 문화를 만들어가요. - 잠깐! 인프런 서비스 운영 관련 문의는 1:1 문의하기를 이용해주세요. 먼저, 유익한 강의를 나눠 주셔서 감사합니다.springboot 3.1버전을 사용 하면서 안되는 부분에 대해서 질문드립니다. 강의 간에 진행되는 springboot 버전을 2.7 버전으로 설정 하셨는데, end of support가 11월로 예정이 되어 있더라구요,,현재 섹션 9. OAuth 2.0 Client - Social Login (Google, Naver, KaKao) + FormLogin 파트까지 3.1 버전으로 마이그레이션 진행 하려 했으나, config의 메서드가 Deprecated된 부분을 해결 해야했습니다.공식 문서를 참고해서 일단 제가 바꾼 부분은 다음과 같습니다.authorizeRequests -> authorizeHttpRequestsantMatchers -> requestMatchershttp.formLogin(), http.logout() -> 람다 사용import io.security.oauth2.springsecurityoauth2.service.CustomOAuth2UserService; import io.security.oauth2.springsecurityoauth2.service.CustomOidcUserService; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer; import org.springframework.security.core.authority.mapping.GrantedAuthoritiesMapper; import org.springframework.security.web.SecurityFilterChain; @RequiredArgsConstructor @EnableWebSecurity public class OAuth2ClientConfig { private final CustomOAuth2UserService customOAuth2UserService; private final CustomOidcUserService customOidcUserService; @Bean public WebSecurityCustomizer webSecurityCustomizer() { return (web) -> web.ignoring().requestMatchers("/static/js/**", "/static/images/**", "/static/css/**", "/static/scss/**"); } @Bean SecurityFilterChain oauth2SecurityFilterChain(HttpSecurity http) throws Exception { http.authorizeHttpRequests((requests) -> requests .requestMatchers("/api/user") .hasAnyRole("SCOPE_profile','SCOPE_email") // .access("hasAuthority('SCOPE_profile')") .requestMatchers("/api/oidc") .hasRole("SCOPE_openid") //.access("hasAuthority('SCOPE_openid')") .requestMatchers("/") .permitAll() .anyRequest().authenticated()); http.oauth2Login(oauth2 -> oauth2.userInfoEndpoint( userInfoEndpointConfig -> userInfoEndpointConfig .userService(customOAuth2UserService) .oidcUserService(customOidcUserService))); http.logout(form -> form.logoutSuccessUrl("/")); return http.build(); } /*@Bean // hasAuthority 일경우 정의하지 않는다 public GrantedAuthoritiesMapper grantedAuthoritiesMapper(){ SimpleAuthorityMapper simpleAuthorityMapper = new SimpleAuthorityMapper(); simpleAuthorityMapper.setPrefix("ROLE_"); return simpleAuthorityMapper; }*/ @Bean public GrantedAuthoritiesMapper customAuthorityMapper() { return new CustomAuthorityMapper(); } } 이렇게 수정을 하니 메인 페이지("/")가 무조건 로그인 페이지("/login)로 리다이렉트 되는 문제(?)를 발견 했습니다. 이 부분에 대해서 어떻게 해결해야할지 여쭤보고 싶습니다.
-
미해결스프링 시큐리티 OAuth2
로그인 화면을 쓰지않는다면??
- 안녕하세요! 강의 정말 잘 듣고 있습니다. 강의를 듣다가 궁금한점이 생겨서요! - keycloak 관련해서 로그인처리할 때 지금은 keycloak에서 제공하는 로그인 페이지를 사용하고 있는데, 만약 그 로그인페이지를 사용하지 않고 Front에서 만든 로그인 페이지를 사용하고, POST 요청으로 사용하면 http://localhost:8080/realms/bts/protocol/openid-connect/token URL로 직접 호출해서 토큰을 받는게 맞을지... 궁금합니다.
-
해결됨스프링 시큐리티 OAuth2
OpenId Provider와 인가서버의 차이에 대해 질문드립니다.
안녕하세요 강사님.매번 너무나도 좋은 강의 감사드립니다. 강의 내용 중 OIDC 부분을 학습하다 궁금증이 생겨 질문드립니다.위의 이미지는 제공해주신 ppt 자료 중 96번 슬라이드의 내용입니다. 이전 내용에서 OIDC를 사용하지 않는 클라이언트의 요청을 확인하여 액세스 토큰을 발급하는 주체는 인가 서버라고 설명을 해 주셨는데 위의 이미지에서는 OP가 ID토큰과 액세스 토큰을 발급한다고 설명을 해 주셨습니다. 혹시 OIDC를 사용하는 경우에는 OpenID Provider가 인가 서버의 역할을 같이 하는 것이라고 생각해도 될까요?감사합니다.
-
미해결스프링 시큐리티 OAuth2
Oauth2 + jwt 에 대한 질문이 있습니다.
시큐리티 + jwt만을 사용한다면 회원가입하고 로그인하면 jwt를 클라이언트에게 보내줘서 다른 요청을 할 때 jwt를 함께 보내고 게시판이 해당 유저인지 판별할 때 예전에는 세션으로 사용했지만 이제는 jwt로 구별한다고 알고있습니다. 그러면 Oauth2 + jwt는 회원가입, 로그인만 소셜로그인 즉, 외부로 빼기만 한거고 소셜 로그인이 성공하면 jwt를 클라이언트에게 주고 그걸로 로그인을 유지한다던지 나머지 역할은 같나요? 소셜 로그인하면 accessToken을 발급해주는데 그거는 단지 서버에서 소셜로그인할 때 연결하기 위한거고 클라이언트에겐 따로 jwt를 만들어서 accessToken, refreshToken을 발급해줘야 하는건가요?
-
해결됨스프링 시큐리티 OAuth2
Authorization server 에서 localhost 를 사용하지 못하는 이유가 있을까요?
안녕하세요.말씀해주신 대로 호스트를 localhost 로 사용하는 경우에는 17::24 화면처럼 세션을 찾을수 없는 문제가 있는것을 확인하였습니다.redirect uri 를 모두 localhost 로 세팅 하였을때도 문제가 있는것을 확인했는데요, 그렇다면 authorization server 에서 로그인 성공시 host 가 localhost 이면 별도로 쿠키에 세팅을 해주지 않는다는 의미인가 해서 보니 권한 동의 이후 /oauth2/authorize 로 submit 을 할 Authorization Server 의 OAuth2AuthorizationEndpointFilter.java 에서 187 line 의 sessionAuthenticationStrategy 에서는 정상적으로 세션을 세팅하는것 같아보였습니다. (아래는 세팅되는 OAuth2AuthorizationServerConfigurer.java 282line. 의 lamda 로직입니다그렇다면 Client 쪽에서 같은 localhost 의 쿠키 id를 가져와서 사용하지 못한다는 말 같은데, 제가 빠뜨린 부분이 있는지 확인부탁드리겠습니다.
-
해결됨스프링 시큐리티 OAuth2
code verifier 질문 있습니다.
안녕하세요 강사님.시큐리티에 이어 OAuth 강의까지 잘 듣고 있습니다.PKCE 학습 중 Code Verifier에 관해 찾아보다 강의 내용과 조금 다른 부분이 있어 질문 드립니다.Code Verifier에서 48~128 글자수를 가진 무작위 문자열이라고 설명이 되어 있는데, RFC 문서를 보니까 43 ~128 글자수라고 설명이 되어 있습니다.https://www.rfc-editor.org/rfc/rfc7636혹시 어떤 내용이 맞는건지 확인 부탁드리겠습니다
-
해결됨스프링 시큐리티 OAuth2
Spring Authorization Server 을 OAuth Client Client 로 등록
Spring Authorization Server 1.x 와 OAuthClient 를 사용하고 있습니다.강의 내용과 레퍼런스를 참조하여 Spring Authorization Server 사용하여 SSO 시스템을 개발을 진행하고 있습니다.OAuth2 Client 등록등 관리자 화면 접속을 위하여 로그인 페이가 필요한데 개발중인 SSO 시스템을 OAuth2 Client 로 등록하여 인증처리를 하기 위하여 설정 파일에 provider 로 등록하였습니다.spring: security: oauth2: client: registration: local: authorization-grant-type: authorization_code client-id: 'default' client-secret: '325ee4c4-94e9-435b-a3c4-579f84d1e211' client-name: '인증서버' redirect-uri: SSO서버URL/social-login/oauth2/code/naon-iam scope: - openid - profile provider: local: issuer-uri: SSO서버URL문제는 Spring Boot 가 기동될떄 oauth2 client 설정이 초기화 되는 과자에서 issuer-uri 에 접속을 하는데 아직 WAS 가 실행이 안된 상태이기 때문에 issuer-uri 로 ODIC Provider 정보를 가져 올떄 Connection refused 예외가 발생합니다.Caused by: org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://SSO서버URL/.well-known/openid-configuration": Connection refused: no further information at org.springframework.web.client.RestTemplate.createResourceAccessException(RestTemplate.java:888) ~[spring-web-6.0.9.jar:6.0.9] at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:868) ~[spring-web-6.0.9.jar:6.0.9] at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:714) ~[spring-web-6.0.9.jar:6.0.9] at org.springframework.security.oauth2.client.registration.ClientRegistrations.lambda$oidc$0(ClientRegistrations.java:163) ~[spring-security-oauth2-client-6.1.0.jar:6.1.0] at org.springframework.security.oauth2.client.registration.ClientRegistrations.getBuilder(ClientRegistrations.java:216) ~[spring-security-oauth2-client-6.1.0.jar:6.1.0] ... 178 common frames omittedyaml 의 설정을 제거 하고 Java Config 에서 등록을 하면 @Bean public ClientRegistrationRepository clientRegistrationRepository() { return new InMemoryClientRegistrationRepository(this.localRegistration()); } private ClientRegistration localRegistration() { return ClientRegistration.withRegistrationId("local") .clientId("google-client-id")순한 참조 예외가 발생합니다.Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'clientRegistrationRepository': Requested bean is currently in creation: Is there an unresolvable circular reference? at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.beforeSingletonCreation(DefaultSingletonBeanRegistry.java:355) ~[spring-beans-6.0.9.jar:6.0.9] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:227) ~[spring-beans-6.0.9.jar:6.0.9]Spring Authorization Sever 와 충돌의 의심해보았는데 RegisteredClientRepository 로 등록하거 있어 원인을 아닌거 같고 ClientRegistrationRepository 을 등록하는 코드에 문제가 있는거 같이 문의 합니다.개발은 Spring Authorization 1.1 로 진행하고 있습니다. OIDC Logout Endpoint 기능이 필요하여 지난주에 Spring Authorization 1.0.2 -> 1.1 로 업그레이드 하였습니다.
-
미해결스프링 시큐리티 OAuth2
운영서버에서 활용할 때 적합한가요?
안녕하세요강의 잘 듣고 있습니다! 강의해주시는대로 소셜 로그인을 구현했을 때 운영 서버에서도 문제가 없을까요?시큐리티를 활용하는 방법이 너무 많아서, 강의의 내용만으로도 운영서버에 적합한지, 적합하지 않다면 어떤점을 보완해야 할지 궁금합니다!
-
미해결스프링 시큐리티 OAuth2
코드를 가지고 at를 요청하는 걸 custom 할 수 있나요?
프론트에서 코드를 백으로 보내면 해당 코드로 at 를 받아서 유저 정보를 가져오고 싶은데 이렇게 하는게 가능한가요?
-
미해결스프링 시큐리티 OAuth2
oauth2Login() vs oauth2Client() 선택 고민입니다.
안녕하세요. SpringSecurity를 공식문서만으로 공부하기 벅차서 강의를 듣고있는데 도움을 많이 받고있습니다. 회사에서 인증서버를 구현하려고 하는데 요구사항이 고객사의 인가서버에서 OAuth2.0로 User정보를 회사 인증서버로 가져와서 그 User정보를 토대로 JWT토큰을 생성해서 회사 인증서버 자체에서 인증/권한 관리를 따로 하려고하는데 이런 경우 oauth2Client()를 써야하는게 맞는거죠?
-
미해결스프링 시큐리티 OAuth2
[OAuth 2.0 Social Login 연동 구현 3] 에서 계속 index 문자열만 보이고 index 페이지가 보이지 않습니다.
server: port: 8081 spring: security: oauth2: client: registration: keycloak: authorization-grant-type: authorization_code client-id: oauth2-client-app client-name: oauth2-client-app client-secret: dXf021lMWuZ9kZafqxZn230MvVEdROIo redirect-uri: http://localhost:8081/login/oauth2/code/keycloak scope: profile,email google: client-id: 발급받은ID client-secret: 발급받은비밀번호 scope: profile,email naver: client-id: 발급받은ID client-secret: 발급받은비밀번호 authorization-grant-type: authorization_code client-name: naver-client-app redirect-uri: http://localhost:8081/login/oauth2/code/naver scope: profile,email provider: keycloak: authorization-uri: http://localhost:8080/realms/oauth2/protocol/openid-connect/auth issuer-uri: http://localhost:8080/realms/oauth2 jwk-set-uri: http://localhost:8080/realms/oauth2/protocol/openid-connect/certs token-uri: http://localhost:8080/realms/oauth2/protocol/openid-connect/token user-info-uri: http://localhost:8080/realms/oauth2/protocol/openid-connect/userinfo user-name-attribute: preferred_username naver: authorization-uri: https://nid.naver.com/oauth2.0/authorize token-uri: https://nid.naver.com/oauth2.0/token user-info-uri: https://openapi.naver.com/v1/nid/me user-name-attribute: response mvc: static-path-pattern: /static/** package springsecurityoauth2.demo.controller; import org.springframework.security.core.Authentication; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken; import org.springframework.security.oauth2.core.user.OAuth2User; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import java.util.Map; @RestController public class IndexController { @GetMapping("/") public String index(Model model, Authentication authentication, @AuthenticationPrincipal OAuth2User oAuth2User) { OAuth2AuthenticationToken oAuth2AuthenticationToken = (OAuth2AuthenticationToken) authentication; if (oAuth2AuthenticationToken != null) { Map<String, Object> attributes = oAuth2User.getAttributes(); String name = (String) attributes.get("name"); // 네이버는 response 계층이 하나 더 있으므로 별도 처리 필요 if (oAuth2AuthenticationToken.getAuthorizedClientRegistrationId().equals("naver")) { Map<String, Object> response = (Map<String, Object>) attributes.get("response"); name = (String) response.get("name"); } model.addAttribute("user", name); } return "index"; } } 안녕하세요.resource 파일들은 깃헙의 소셜로그인 브랜치에서 그대로 가져왔고, IndexController 와 application.yml 파일은 위와 같습니다. 브라우저에서 localhost:8081 로 접속하면이렇게만 나옵니다 ㅠㅠ어디가 잘못됐을까요?