묻고 답해요
169만명의 커뮤니티!! 함께 토론해봐요.
인프런 TOP Writers
-
미해결스프링 시큐리티 OAuth2
OAuth 2.0 Grant Flows 관련 질문
안녕하세요. OAuth 2.0을 배우고 싶어 학습 신청했습니다.유익한 강의 준비해주셔서 감사합니다.막연하게 알고 있는 Spring Security 에 대해 강의를 통해 명확하게 알아가고 있습니다. 강의를 들으며 몇가지 궁금한 점이 있어 질문드립니다. 우선은 자체 로그인만 구현할 예정이라면,소셜 로그인 기능이 없는 경우에는 OAuth 2.0을 도입할 필요가 없는 건가요?Resource Owner Password Credentials Grant Flow 는 Deprecated 된다고 하는데 그럼 어떻게 구현해야하나요? 답변주시면 성장하는데 큰 도움이 될 것 같습니다!감사합니다!
-
해결됨스프링 시큐리티 OAuth2
시큐리티 완전정복(6.x 개정판) 쿠폰 저도 받을수 있을까요.. ㅜ
학습질문과 전혀 관련없는 질문이라 죄송합니다. ㅠ저와같이 할인쿠폰 만료일 지나신 분 쿠폰요청글을 보고 혹시나 저도 아직 가능한지 여쭙고 싶어서 혹시나 하는 마음에 글올립니다.oAuth하고 이전버전 시큐리티 강의 듣고 있습니다.저도 메일을 늦게 확인하여서 쿠폰 만료일이 지났는데받을수있을까요?발급받았던 이메일 주소 는laundryday@naver.com입니다.. 좋은 하루 보내세요 감사합니다.
-
미해결스프링 시큐리티 OAuth2
비대칭키 내용 중 궁금한게 있습니다.
데이터 보안 측면에서 송신자 공개키로 암호화 -> 송신자 개인키로 복호화를 한다고 적혀있는데요.수신자가 송신자의 개인키를 가지고 있다는게 보안적으로 문제가 되는게 아닌가 싶습니다. 수신자 공개키로 암호화 -> 수신자 개인키로 복호화의 오타인 것인지, 아니라면 어떻게 보안적으로 괜찮은건지 궁금합니다.
-
미해결스프링 시큐리티 OAuth2
시큐리티 완전정복(6.x 개정판) 쿠폰
안녕하세요!!수원님의 시큐리티 강의를 듣고 있습니다!!좋은 강의 해주셔서 감사합니다!다름이 아니라, 제가 메일을 늦게 확인하여서기존 수강생에게 제공되는 50%할인 쿠폰을 사용하지 못했는데,혹시 다시 쿠폰 발급이 가능한지 여쭤봐도 되겠습니까?!감사합니다.
-
미해결스프링 시큐리티 OAuth2
access token 의 용도
- 학습 관련 질문을 남겨주세요. 상세히 작성하면 더 좋아요! - 먼저 유사한 질문이 있었는지 검색해보세요. - 서로 예의를 지키며 존중하는 문화를 만들어가요. - 잠깐! 인프런 서비스 운영 관련 문의는 1:1 문의하기를 이용해주세요. keycloak,kakao 같은 authorization server 에서 발급하는 access token 은 userinfo 를 가져오기 위한 token 이라고 생각했는데, resource server 같은 자원도 이 토큰으로 접근 하는게 맞는지 궁금합니다. 수업을 위한 예제인지 실제로 이렇게 사용을 많이 하는지요. 카카오같은 인증서버에서 받은 access token 은 카카오에서 유저 정보를 가져오기 위함이고, resource server 의 다른 api 접근 목적은 아니라고 생각했었는데요. 제가 잘못 알고 있었는지 궁금합니다.
-
미해결스프링 시큐리티 OAuth2
client 의 token 발행 가능 여부
- 학습 관련 질문을 남겨주세요. 상세히 작성하면 더 좋아요! - 먼저 유사한 질문이 있었는지 검색해보세요. - 서로 예의를 지키며 존중하는 문화를 만들어가요. - 잠깐! 인프런 서비스 운영 관련 문의는 1:1 문의하기를 이용해주세요. keycloak 을 authorization server 로 사용하는데요.키클록에 등록되는 유저와 유저별 권한과 별개로,서비스의 메뉴별 권한을 상세 설정하기 위해서 client 에서 서비스 권한 관리를 하고 메뉴 접근 권한 관련된 token 을 발행한다고 하면, resource-server 에 jwt-set-uri 를 client 서버 endpoint 로 하고, client 에서 jwkset 을 반환하는 방식이 가능한지 궁금합니다.
-
미해결스프링 시큐리티 OAuth2
client-credentials 방식 accessToken null 이슈
Cannot invoke "org.springframework.security.oauth2.client.OAuth2AuthorizedClient.getAccessToken()" because "oAuth2AuthorizedClient" is null] with root causekeycloak 버전은 : 21.1.2 @GetMapping("/oauth2Login") public String oauth2Login(Model model, HttpServletRequest request, HttpServletResponse response) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); OAuth2AuthorizeRequest oAuth2AuthorizeRequest = OAuth2AuthorizeRequest .withClientRegistrationId("keycloak") .principal(authentication) .attribute(HttpServletRequest.class.getName(), request) .attribute(HttpServletResponse.class.getName(), response) .build(); OAuth2AuthorizationSuccessHandler successHandler = (authorizedClient, principal, attributes) -> { oAuth2AuthorizedClientRepository .saveAuthorizedClient(authorizedClient, principal, (HttpServletRequest) attributes.get(HttpServletRequest.class.getName()), (HttpServletResponse) attributes.get(HttpServletResponse.class.getName())); System.out.println("authorizedClient : " + authorizedClient); System.out.println("principal : " + principal); System.out.println("attributes : " + attributes); }; auth2AuthorizedClientManager.setAuthorizationSuccessHandler(successHandler); OAuth2AuthorizedClient oAuth2AuthorizedClient = auth2AuthorizedClientManager.authorize(oAuth2AuthorizeRequest); model.addAttribute("oAuth2AuthorizedClient", oAuth2AuthorizedClient.getAccessToken().getTokenValue()); return "home"; } keycloak: clientId: oauath2-client-app clientSecret: HPWAsKr9dEy9DPU1babedRmpstowiXOs clientName: oauath2-client-app authorizationGrantType: client-credentials clientAuthenticationMethod: client_secret_basic provider: keycloak <form sec:authorize="isAnonymous()" action="#"> <p><input type="button" onclick="authorizationCode()" value="AuthorizationCode Grant"/></p> <p><div sec:authorize="isAnonymous()"><a th:href="@{/oauth2Login(username='user',password='1234')}">Password flow</a></div></p> <div sec:authorize="isAnonymous()"><a th:href="@{/oauth2Login}">Client Credentials Flow Login</a></div> </form> @Configuration public class AppConfig { @Bean public DefaultOAuth2AuthorizedClientManager auth2AuthorizedClientManager(ClientRegistrationRepository clientRegistrationRepository, OAuth2AuthorizedClientRepository oAuth2AuthorizedClientRepository) { OAuth2AuthorizedClientProvider oAuth2AuthorizedClientProvider = OAuth2AuthorizedClientProviderBuilder.builder() .authorizationCode() .password() .clientCredentials() .refreshToken() .build(); DefaultOAuth2AuthorizedClientManager defaultOAuth2AuthorizedClientManager = new DefaultOAuth2AuthorizedClientManager(clientRegistrationRepository, oAuth2AuthorizedClientRepository); defaultOAuth2AuthorizedClientManager.setAuthorizedClientProvider(oAuth2AuthorizedClientProvider); defaultOAuth2AuthorizedClientManager.setContextAttributesMapper(contextAttributeManager()); return defaultOAuth2AuthorizedClientManager; } private Function<OAuth2AuthorizeRequest, Map<String, Object>> contextAttributeManager() { return oAuth2AuthorizeRequest -> { Map<String, Object> contextAttributes = new HashMap<>(); HttpServletRequest httpServletRequest = oAuth2AuthorizeRequest.getAttribute(HttpServletRequest.class.getName()); String userName = httpServletRequest.getParameter(OAuth2ParameterNames.USERNAME); String userPassword = httpServletRequest.getParameter(OAuth2ParameterNames.PASSWORD); if(StringUtils.hasText(userName) && StringUtils.hasText(userPassword)) { contextAttributes.put(OAuth2AuthorizationContext.USERNAME_ATTRIBUTE_NAME, userName); contextAttributes.put(OAuth2AuthorizationContext.PASSWORD_ATTRIBUTE_NAME, userPassword); } return contextAttributes; }; } } 이렇게 됩니다. 현재 상황으로 문제가 되어 있는 부분이 없는 것 같습니다.어디부터 다시 확인해야 될지 조언 부탁드립니다.
-
미해결스프링 시큐리티 OAuth2
AuthorizationEndpoint 커스텀 질문
안녕하세요.AuthorizationEndpoint.baseUri(”~~”) 는 OAuth2 로그인 단계중에서 1단계에 해당하는 code, state 값 등을 받아서 처리하는 부분의 uri를 변경하는게 맞을까요?아니면, 클라이언트가 로그인할때 인가서버로 요청을 보낼때 이를 처리할 인가서버의 경로로 사용되어지는 경로일까요?
-
미해결스프링 시큐리티 OAuth2
강의에서 사용하는 keycloak 버전인 19.0.1 다운로드 URI 공유
강의를 매끄럽게 따라하려면 똑같은 keycloak 버전을 사용하셔야 합니다.2x.x.x 버전 사용 시 openid를 강제로 사용해야 할 수 있습니다. 다운로드 URI : https://github.com/keycloak/keycloak/releases/download/19.0.1/keycloak-19.0.1.tar.gz
-
미해결스프링 시큐리티 OAuth2
Missing parameter: code 에러
Oauth 2.0 User 모델 소개(2)영상에서 assessToken 호출을 위한 과정을 진행하는데 발생한 문제입니다.keycloack 버전이 달라 발생한 문제인지 질문드립니다.현재 keycloack 버전 21.1.2 입니다.
-
미해결스프링 시큐리티 OAuth2
프론트엔드 + 서버 oauth2 연동
안녕하세요, 좋은 강의 감사합니다. 현재 제가 개발중인 react 로 된 SPA 어플리케이션이 있는데요, 프론트엔드에서 직접 authorization server 로 access token 을 가져오자니 페이지가 새로고침 될때 날라가는 현상이 발생합니다. 이를 localStorage, sessionStorage, cookie 등에 저장하는것도 안전하지 않아서 (혹시 안전하게 하는 방법이 있나요?)아예 "로그인"만 서버쪽에서 수행하고 access token, refresh token 을 프론트로 전달해줘서 refresh token 만 httpOnly Cookie 에 넣으려고 합니다. 이제 새로고침 될때마다 서버에 access token 요청을 refresh token 으로 한다음, 그 access token 을 사용하려고 합니다. 혹시 이 같은 방식이 쓰이는지 알 수 있을까요? 아니면 추천해 주시고 싶은 방식이 있으신가요? 2. 서버 사이드 view 를 통해 로그인만 oauth2Login 으로 수행하고, 로그인 후 나머지는 SPA 프론트엔드로 리다이렉트 가 가능한가요? 혹은 이렇게 쓰기도 하나요?
-
미해결스프링 시큐리티 OAuth2
통합 로그인 구축 관련해서 질문 드립니다.
안녕하세요.통합인증서버 - 클라이언트 - 백엔드서버 이런식으로 구성 되어 있는데요.플로우 관해서 질문이 있습니다.client -> auth server : return url / client id 통합인증서버로 보내고auth server -> client : auth id 통합인증서버에서 받고client -> be server : client id / auth id 클라이언트에서 받고be server -> auth server : client id / auth id 백엔드서버에서 통합인증서버로 보내고auth server -> be server : access token / refresh token 백엔드서버에서 통합인증서버로 받고be server -> client : access token / refresh token 백엔드서버에서 클라이언트 보내기이런식으로 구성을 한다고 하더라구요.저는 3번에서 바로 auth id를 통합인증서버로 보내고 토큰을 클라에서 받고 저장 그리고 백엔드 보내고 저장이라고 생각이 드는데요.불필요한 작업이 추가로 하는거 같다라는 생각을 했는데요. 클라에서 auth id를 통합인증서버로 보낼때 get으로 보내서 보안 문제가 있어서 서버 투 서버로 보낸다고 하더라구요.(백앤드 서버에서 보내는 것만 받으려고)어떠한 방식이 옳은건지, 저렇게 하면 보안적으로 더 좋은건지 잘 모르겠습니다.제가 생각하는 방식으로 해도 되는건지.. 고견 부탁드립니다.
-
미해결스프링 시큐리티 OAuth2
안드로이드, iOS에서 sdk를 사용할 때 어떻게 해야할까요?
앱에서 sdk를 사용하면 인증 코드 또는 엑세스 토큰을 발급받는 과정에서 클라이언트(spring boot)와 통신을 하지 않는데요.이 때는 스프링 oauth2 client를 활용할 수 없는걸까요?sdk에서 발급 받은 인증 서버(구글, 카카오 등)의 엑세스 토큰을 앱 -> 클라이언트로 넘겨서 회원가입 및 로그인 처리를 해야하는 건지 궁금합니다.
-
미해결스프링 시큐리티 OAuth2
동의 후 인증 절차의 구현이 변경됐습니다.
Scope 동의단계2, 즉 최종사용자의 동의가 이루어졌을 경우이 요청은 POST /oauth2/authorize 로 보내지는데요이 과정에서 내부구현의 차이가 강의 버전과 맞지 않아서 코드를 확인해봤습니다.1. 0.4.0 버전부터이때 작동하는 AuthenticationConverter 는 OAuth2AuthorizationConsentAuthenticationConverter 입니다.여기서 OAuth2AuthorizationConsentAuthenticationToken 가 구성됩니다.2.OAuth2AuthorizationConsentAuthenticationToken 의 처리는 OAuth2AuthorizationConsentAuthenticationProvider 가 맡게 됩니다.여기서 code 생성 절차가 진행되는 차이가 있습니다.
-
미해결스프링 시큐리티 OAuth2
서버간의 인증에 Oauth활용
안녕하세요...! 클라이언트단에서 로그인을 통한 OAuth가 아닌 서버간의 통신에 인증을 위해 OAuth를 활용하고 싶은데 이때에는 그럼 WAS01(클라이언트1, 리소스서버1) , WAS02(리소스서버2) , 인가서버로 구성해서클라이언트1이 인가서버로 토큰 요청클라이언트1이 받은 access token을 셋팅해서 RestTemplate을 통해 WAS02의 특정 api 호출WAS02에서 클라이언트 자격 증명WAS01로 응답 제공 => 이렇게 해야하는건가 구성을 생각하고 있는데, 한대의 서버에 클라이언트와 리소스서버를 같이두고 이렇게 구성하는게 맞는 방향일까요? 그리고 인가서버를 꼭 다른 포트로 띄워야하는지도 궁금합니다...!
-
미해결스프링 시큐리티 OAuth2
컨트롤러에서 Authentication이 null 일 때
"/home" 으로 리다이렉트 할 떄 Authentication 이 null로 가져와지는 문제가 있습니다.왜 그럴까?OAuth2AuthenticationToken 은 Principal의 하위 클래스입니다. 이는 ServletRequestMethodArgumentResolver 에서 잡아서 resolve 해줍니다.그런데 여기서 resolve 하는 과정에서 SecurityContext로부터 Authentication 을 꺼내는데 익명사용자일 경우 null 로 반환하게 됩니다. 인증되지 않았다는 것이죠.아까 우리는 인증을 했지만 이 결과가 장기적인 저장을 담당하는 SecurityContextRepository에 저장이 제대로 되지 않았기 때문입니다.CustomOAuth2LoginAuthenticationFilter 의 부모인 AbstractAuthenticationProcessingFilter 가 사용하는 securityContextRepository가 RequestAttributeSecurityContextRepository 또는 NullSecurityContextRepository(예전버전 기준) 로 되어 있습니다.이렇게 되어 있으면 다시 "/home" 으로 리다이렉트되어 요청될 때 SecurityContextHolderFilter에서 인증 결과를 못 불러오는 문제가 생깁니다.실습의 편의상 세션에 저장하는게 좋은데, filter.setSecurityContextRepository(HttpSessionSecurityContextRepository()) 코드를 추가하셔서 설정하시면 될 것 같습니다. 다시 요청이 들어왔을 때 SecurityContextHolderFilter를 거치면서 세션의 Authentication 을 꺼내서 SecurityContext에 담아주기 때문에 성공적으로 인증된 OAuth2AuthenticationToken 을 바인딩 받으실 수 있을겁니다.
-
미해결스프링 시큐리티 OAuth2
OAuth2 로그인 구현 - Oauth 2.0 User 모델 소개 issuer-uri에러
섹션 7OAuth2 로그인 구현 - Oauth 2.0 User 모델 소개(2)진행시 설정시 에러가 납니다uli 클릭하면realm: "oauth2",public_key: "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqFd5+xNaJoQzccdweHH4hxMOOirdHcbGx7tAkl7YWFAD0kBpVmpFN3sWaz3T3CLa0zSULmEWuepEkf/T376JKs+opBRb8pfnDSvvq1va4UXhw5j1mMgN8a6kME2TfM4cd2XnnT9huTIJ2+4nTYPTwKhYd+KvgB1ruzUe4ApMw0injfbsyufS17bhGtHYn4Ysq7THWsOAPVQ+FMYd8e1T4tfY1jkQg68UYB43dHST34y0JWkStPowP80qLMbsPvJ4JrOCzSGk08sBvmd6Fo1KD9RAqZyGvQFXEyo1Y5jVcKGCgwin0ijQBCKhRpHmWGlmyamrW6fsgAnAJH+clUdAwQIDAQAB",token-service: "http://localhost:8080/realms/oauth2/protocol/openid-connect",account-service: "http://localhost:8080/realms/oauth2/account",tokens-not-before: 0}이렇게 잘나옵니다. implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor' annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.security:spring-security-test'spring: application: name: inf_oauth2 security: oauth2: client: registration: keycloak: authorization-grant-type: authorization_code client-id: oauth2-client-app client-name: oauth2-client-app client-secret: 90GVrQtfYCp1u9cc0VAJNFiY8ZzCyjHD redirect-uri: http://localhost:8081/login/oauth2/code/keycloak client-authentication-method: client_secret_basic scope: openid, profile, email provider: keycloak: issuer-uri: http://localhost:8080/realms/oauth2 authorization-uri: http://localhost:8080/realms/oauth2/protocol/openid-connect/auth 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 org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'indexContoller': Unsatisfied dependency expressed through field 'clientRegistrationRepository': Error creating bean with name 'clientRegistrationRepository' defined in class path resource [org/springframework/boot/autoconfigure/security/oauth2/client/servlet/OAuth2ClientRegistrationRepositoryConfiguration.class]: Failed to instantiate [org.springframework.security.oauth2.client.registration.InMemoryClientRegistrationRepository]: Factory method 'clientRegistrationRepository' threw exception with message: Unable to resolve Configuration with the provided Issuer of "http://localhost:8080/realms/oauth2" at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessorAutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:787) ~[spring-beans-6.1.6.jar:6.1.6] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessorAutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:767) ~[spring-beans-6.1.6.jar:6.1.6] Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clientRegistrationRepository' defined in class path resource [org/springframework/boot/autoconfigure/security/oauth2/client/servlet/OAuth2ClientRegistrationRepositoryConfiguration.class]: Failed to instantiate [org.springframework.security.oauth2.client.registration.InMemoryClientRegistrationRepository]: Factory method 'clientRegistrationRepository' threw exception with message: Unable to resolve Configuration with the provided Issuer of "http://localhost:8080/realms/oauth2" at java.base/java.util.HashMap.forEach(HashMap.java:1421) ~[na:na] at org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientPropertiesMapper.asClientRegistrations(OAuth2ClientPropertiesMapper.java:64) ~[spring-boot-autoconfigure-3.2.5.jar:3.2.5] at org.springframework.boot.autoconfigure.security.oauth2.client.servlet.OAuth2ClientRegistrationRepositoryConfiguration.clientRegistrationRepository(OAuth2ClientRegistrationRepositoryConfiguration.java:49) ~[spring-boot-autoconfigure-3.2.5.jar:3.2.5] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:140) ~[spring-beans-6.1.6.jar:6.1.6] ... 34 common frames omitted
-
미해결스프링 시큐리티 OAuth2
AuthenticationManager 질문 있습니다.
강사님 강의 스프링 시큐리티 6 에서 AuthenticationManager를 생성할 때 HttpSecurity.getSharedObject()를 사용하는 것으로 공부했는데 AuthenticationConfiguration 으로 생성하는 것과는 어떤 차이가 있는 건가요?더 권장되는 방식이 있는 건가요?? 좋은 강의 감사합니다.
-
미해결스프링 시큐리티 OAuth2
403 에러
전에도 남겼었는데 이번에 실습을 하면서 AuthorizationCode Grant 를 누르면 인증을 받기 위한 로그인을 하고 나면 403 에러가 발생합니다. 그래서 Clientcontroller 에서 만든 로직에다가 breakpoint 를 찍으면서 확인해보면 결과 정보들은 강사님과 똑같이 들어있었습니다. 근데 return "/client" 부분만 가면 403 에러가 나와서 화면이 나오질 않는데 어느 부분을 먼저 봐야할까요..? 계속 수정해봐도 계속 403 에러가 발생해서 다시 질문드립니다!
-
미해결스프링 시큐리티 OAuth2
keycloak이 강의 버전과 맞지 않아서 생기는 오류 일부 정리
keycloak 버전이 제일 낮은 게 20 버전이라서 저는 가장 최근 버전인 23 버전으로 사용했습니다. 23 버전 기준으로, 제가 파악한, 강의와 다른 부분입니다.20 버전부터는 최초 로그인 할 때 동의 항목이 안 나올텐데요. 관리자 콘솔에서 Clients -> Cliend details에서 Login settings에서 Consent required를 켜면 됩니다.엑세스 토큰 발급 이후에 userinfo 엔드포인트로 user 데이터를 요청하면 body에 아무 것도 안 나올 겁니다. 응답 헤더 살펴보면 insufficient_scope이며 Missing openid scope이라고 나오는데요.이렇게만 써있으면 userinfo 요청할 때 param에 scope=openid 넣으면 될 것 같지만 안 됩니다. 토큰에 해당 정보가 없는 거라서, 토큰 발급 전에(code 얻어야할 때) scop에 openid를 추가하면 됩니다.http://localhost:8080/realms/oauth2/protocol/openid-connect/auth?response_type=code&client_id=oauth2-client-app&scope=profile email openid&redirect_uri=http://localhost:8081 공식문서에 나와 있습니다. In case an access token is missing openid scope.