월 24,200원
5개월 할부 시다른 수강생들이 자주 물어보는 질문이 궁금하신가요?
- 해결됨스프링 시큐리티 OAuth2
username, clientId, registrationId
안녕하세요. 섹션 9. OAuth 2.0 Client - Social Login (Google, Naver, KaKao) + FormLogin 에서의 User 도메인에 대한 질문입니다. username 에 대한 질문 폼 로그인에 사용되는 계정과 OAuth 2.0 로그인에 사용되는 계정을 추상화하는 과정에서제공자 계정의 (변경가능한) 별명에 해당하는 값을 username으로 받는 것으로 보입니다. 하지만 클라이언트 자체 계정에서의 username 은 고유하기 때문에 Q1) 이를 동일한 속성을 갖도록하는게 맞는지 혹은 해도 무방한지Q2) 이를 별도의 속성으로 받아도 괜찮은지 궁금합니다. (e.g. nickname) id + username 에 대한 질문"sub" 혹은 "id" 로 매핑되어있는 값을 id라는 필드에 넣도록 구현되어있는데 public class NaverUser extends OAuth2ProviderUser { @Override public String getId() { return (String)getAttributes().get("id"); // ! } public class GoogleUser extends OAuth2ProviderUser { @Override public String getId() { return (String)getAttributes().get("sub"); // ! }네이버 문서에 아래와 같은 내용이 있습니다.위 설명에 따르면 네이버를 기준으로 id가 클라이언트 자체 계정에서의 username 과 동일한 역할을 하는 것으로 보입니다.Q3) 따라서 1번 질문과 반대로 id 필드에 저장되는 값이 오히려 username 에 적합해보이는데 이에 대한 의견을 듣고 싶습니다. clientId 에 대한 질문 User 클래스에 String ci (clientId) 필드가 포함되어 있는데,Q4) 이는 외부 설정파일로부터 설정하는데 저장해야할 필요가 있나요? 지워도 무방한가요? public class User { private String registrationId; private String id; private String ci; // ! private String username; private String password; private String provider; private String email; private String picture; private List<? extends GrantedAuthority> authorities; registrationId 에 대한 질문 registrationId 가 provider(google...) 를 의미하는 것으로 보이는데,Q6) FormLogin 클래스에 registrationId, provider 두 필드가 모두 존재합니다. 하나는 지워도 무방한가요? public abstract class OAuth2ProviderUser implements ProviderUser { @Override public String getProvider() { return clientRegistration.getRegistrationId(); // ! }public class FormUser implements ProviderUser { private String registrationId; // ! private String id; private String username; private String password; private String email; private boolean isCertificated; private String provider; // !
- 미해결스프링 시큐리티 OAuth2
클라이언트 앱 시작하기 - application.yml/ OAuth2ClientProperties
스프링에서 열리는 yml 값으로 실행하면 로그인 페이지가 보이질 않네요 server: port: 8081 spring: security: oauth2: client: registration: keycloak: clientId: oauth2-client-app clientSecret: PrKx878dqs1aQ6xEciYY2BVzZjWBW7PP clientName: oauth2-client-app authorizationGrantType: authorization_code scope: openid,profile clientAuthenticationMethod: client_secret_basic redirectUri: http://localhost:8081/login/oauth2/code/keycloak provider: keycloak provider: keycloak: issuerUri: http://localhost:8080/realms/oauth2 authorizationUri: http://localhost:8080/realms/oauth2/protocol/openid-connect/auth jwkSetUri: http://localhost:8080/realms/oauth2/protocol/openid-connect/certs tokenUri: http://localhost:8080/realms/oauth2/protocol/openid-connect/token userInfoUri: http://localhost:8080/realms/oauth2/protocol/openid-connect/userinfo userNameAttribute: preferred_username #server: # port: 8081 # spring: # # security: # oauth2: # client: # registration: # keycloak: # authorization-grant-type: authoriztion_code # client-id: oauth2-client-app # client-secret: PrKx878dqs1aQ6xEciYY2BVzZjWBW7PP # client-name: oauth2-client-app # redirect-uri: http://localhost:8081/login/oauth2/code/keycloak # client-authentication-method: client_secret_post # scope: openid,email,profile # provider: # keycloak: # authorization-uri: http://localhost:8080/realms/oauth2/protocol/openid-connect/auth # token-uri: http://localhost:8080/realms/oauth2/protocol/openid-connect/token # issuer-uri: http://localhost:8080/realms/oauth2 # # jwk-set-uri: http://localhost:8080/realms/oauth2/protocol/openid-connect/certs # user-info-uri: http://localhost:8080/realms/oauth2/protocol/openid-connect/userinfo # user-name-attribute: preferred_username #
- 해결됨스프링 시큐리티 OAuth2
Certification
OAuth 2.0 Social Login 연동 구현 강의 마지막에 추가한 Certification 은 무엇인가요?
- 해결됨스프링 시큐리티 OAuth2
CustomAuthorityMapper
안녕하세요. 섹션 9. OAuth 2.0 Client - Social Login (Google, Naver, KaKao) + FormLogin 에서 구현 한 CustomAuthorityMapper 에 대한 질문입니다. 아래 메서드의 두 번째 if 문을 통해서 결과적으로 "SCOPE_..." 꼴 앞에도 "ROLE_" 이 붙게 되것으로 보이는데 이는 의도한 형태인가요? 예를들어 "ROLE_SCOPE_email" 과 같은 꼴이 올바른 형태인가요?private final String PREFIX = "ROLE_"; private GrantedAuthority mapAuthority(String name) { if(name.lastIndexOf(".") > 0){ int index = name.lastIndexOf("."); name = "SCOPE_" + name.substring(index+1); } if (!name.startsWith(PREFIX)) { name = PREFIX + name; } return new SimpleGrantedAuthority(name); }
- 해결됨스프링 시큐리티 OAuth2
Spring Authorization Server 1.0 관련
https://spring.io/projects/spring-authorization-serverSpring Authorization Server 1.0이 정식으로 출시되었고 강의는 만들어진 시간으로 보아 0.31 기반인거 같은데 1.0(0.4)에 대한 보강 계획은 있으신지요?
- 미해결스프링 시큐리티 OAuth2
loginProcessingUrl에 관하여
어차피 redirectionEndpoint가 우선순위가 가 더 높고 용도가 같다면 loginProcessingUrl은 그러면 왜 존재하는건가요?
- 해결됨스프링 시큐리티 OAuth2
GrantedAuthority, JPA
현재 강의 내용을 따라 소셜 로그인을 구현한 후 JPA 를 도입하려합니다. 폼 로그인에 사용되는 User 클래스를 엔티티로 만들려면 아래 필드의 타입도 바꾸어야 할 것 같은데,public class User { ... private List<? extends GrantedAuthority> authorities;위와 같은 타입을 일반 User도 사용할 필요가 있나요?DB에 저장하기 위해, User 는 ProviderUser 와 별개의 사용자 정의 권한 객체를 가져도 상관없나요?
- 미해결스프링 시큐리티 OAuth2
OAuth2 로그인 구현 - Authorization Code 요청하기 - OAuth2AuthorizationRequest 객체 세션 저장 문제
안녕하세요! 좋은 강의 너무 감사드립니다! 한가지 질문 드릴께 있습니다. OAuth2 로그인 구현 - Authorization Code 요청하기26:25분내용을 보면 첫번째 인증 단계! (response type = code)OAuth2AuthorizationRequest 객체 담아서인가 서버 (keyclack 서버) 에 전달 하게 되는데요이것과 동시에 OAuth2AuthorizationRequest 객체를 sesstion 에 저장을 하게 됩니다. 그러면 사용자는 인가 서버 (keyclack 서버) 로그인을 성공적으로 해결된다면 미리 지정된 redirect url 통해Authorization Code 값을 전달해주는데요!그런 후 미리 OAuth2AuthorizationRequest 객체를 sesstion 저장된것을 가져오는데 만약 해당 서버가 1개 라서 다행이지만scale out 경우 그러니깐 서버가 2대 이상이라면 맨처음 OAuth2AuthorizationRequest 객체 저장할때가 1번 서버라면 OAuth2AuthorizationRequest 객체를 가져올때가 2번 서버라면 이때 각각 다른 서버이기 때문에 가져오지 못하는 문제가 발생되지 않나요? 이때는 어떻게 해결해야 할까요??.. OAuth2AuthorizationRequest 객체를 외부 세션 서버로 저장 할수 있도록 다시 로직을 재구현 해야 하는걸까요?
- 미해결스프링 시큐리티 OAuth2
권한부여코드 요청 필터
12:49 경에 왜 권한부여코드 요청필터는 2개 다른 객체로 존재하는 것인가요?
- 해결됨스프링 시큐리티 OAuth2
자체 로그인과 소셜 로그인 동시 설정 문의
자체 인증과 OAurh2 로 구글 자원 인가 설정을 진행하였습니다.Spring Security 기본 설정에 oauth2Login 만 활성화 하면 Spring Boot 가 기본으로 설정하는 로그인 화면이 나옵니다. Spring Security 설정구글 계정으로 시스템 인증까지는 필요 없어 access token 받는것까지만 진행 @Bean SecurityFilterChain configureHttp(HttpSecurity httpSecurity) throws Exception { httpSecurity.oauth2Login(Customizer.withDefaults()); return httpSecurity.build(); } 하지만 기존 Spring Security 설정에 oauth2Login 를 활성화 하면 404 에외가 발생하고 있고 있어 디버깅 해보니 강의에 설명된 Spring Security의 OAuth2 Client 관련 필터에 진입하지 못하고 있습니다. Spring Security 설정 @Bean SecurityFilterChain configureHttp(HttpSecurity httpSecurity) throws Exception { httpSecurity .headers() .frameOptions() .disable() .and() .httpBasic() .disable() // rest api 이 므로 기본설정 사용안함.. .csrf() .disable() // CSRF 설정 Disable .cors() .and() .exceptionHandling() .authenticationEntryPoint(authenticationErrorHandler) // 인증 예외 처리 .accessDeniedHandler(jwtAccessDeniedHandler) // 인사 예외 처리 .and() .sessionManagement() .sessionCreationPolicy(SessionCreationPolicy.STATELESS) // JWT token으로 인증하여 세션을 사용하지 않기 때문에 세션 설정을 Stateless 로 설정 .and() .authorizeRequests() // 권한을 설정 .requestMatchers(CorsUtils::isPreFlightRequest).permitAll() // CORS preflight 요청은 인증 처리를 하지 않는다. // 인증이 필요 없는 URI Pattern .antMatchers("/openapi/**").permitAll() .antMatchers("/**/login/**", "/**/mlogin/**").permitAll() .antMatchers("/moblmdm/**").permitAll() .antMatchers("/secuCert/**").permitAll() .antMatchers("/moblview/**", "/moblsecu/**").permitAll() .antMatchers("/websocket/**").permitAll() // ADMIN Role을 가진 경우에만 접근을 허용한다. //.antMatchers("/mng/**").hasAnyRole("ADMIN") .anyRequest().authenticated() .and() .apply(securityConfigurerAdapter()); httpSecurity.oauth2Login(Customizer.withDefaults()); // httpSecurity // .oauth2Login() // .authorizationEndpoint() // .authorizationRequestResolver((new CustomOAuth2AuthorizationRequestResolver(clientRegistrationRepository, DEFAULT_AUTHORIZATION_REQUEST_BASE_URI))) // .and() // .userInfoEndpoint() // .userService(new CustomOAuth2UserService()); return httpSecurity.build(); } 질문) 자체 로그인 설정과 소셜 로그인을 동시에 사용 할 수 있는 설정을 문의 드립니다. 참고로 자체 로그인 설정과 소셜 로그인 설정을 분리하고 아래와 같이 소설 로그인 설정에 우선 순위를 주면 소셜 로그인 기능은 활성하 되는데 존 자체 로그인 기능은 비활성화 됩니다. @Bean @Order(0) SecurityFilterChain configureOauth(HttpSecurity httpSecurity) throws Exception { httpSecurity .oauth2Login() // .loginPage("/login") // .failureUrl("/login") .authorizationEndpoint() .authorizationRequestResolver((new CustomOAuth2AuthorizationRequestResolver(clientRegistrationRepository, DEFAULT_AUTHORIZATION_REQUEST_BASE_URI))) .and() .userInfoEndpoint() .userService(new CustomOAuth2UserService()); return httpSecurity.build();
- 미해결스프링 시큐리티 OAuth2
userinfo 요청 시 403에러
http://localhost:8080/realms/oauth2/protocol/openid-connect/userinfo포스트맨 요청 시 403 에러가 납니다 버전은 20.0.1입니다
- 미해결스프링 시큐리티 OAuth2
강의 내용 velog 포스팅 문의 드립니다.
안녕하세요 강사님 좋은 강의 잘 듣고 있습니다.다름이 아니라 강의 내용과 ppt이미지등과 제 생각을 토대로 벨로그 등에 정리하려고 하는대공개 포스팅으로 등록해도 괜찬을지 문의 드립니다.당연히 출처와 링크를 꼭 남기도록 하겠습니다.
- 미해결스프링 시큐리티 OAuth2
front channel + authrozatio_code with PKCE
1.authorization_code 방식이 백채널에서만 이뤄지는 것이 아닌가요?2. 프론트에서 이뤄지면 client secret + authorization_code 를 http 요청같은데 담아서 보내게 되는건가요?
- 미해결스프링 시큐리티 OAuth2
profile email 권한페이지가 나오지 않습니다.
authorization_code 를 얻어오는 요청 보냄login 페이지가 떠서 로그인함email ,profile 등 이걸 허락하겠는가? (저는 이게 안뜹니다.)8081이 안떠있으니 에러페이지code를 복붙해서 access token 요청 -> accestoken 잘받아옴해당 access token 으로 userinfo 요청시 403 forbidden놓친 설정이 있나 확인을 여러번 하였는데 첫번째 강의에서는 Clients 설정에서 Authentication flow 에 implicit flow를 체크하셨는데 2번째 강의에는 해제 되어있길레 해제 해봤지만 결과는 동일합니다.무엇이 문제인지 알 수 있을까요..? jwt.io에서 토큰 정보를 확인했을떄 다음과 같습니다. 제가 안되길레 여러 RoleMapping을 추가해본것입니다.{ "exp": 1668576888, "iat": 1668576588, "auth_time": 1668576573, "jti": "6775c84b-9f26-4d8c-ab58-a09c136eb782", "iss": "http://localhost:8080/realms/oauth2", "aud": [ "realm-management", "account" ], "sub": "f35e128a-f3a9-48df-a784-5675ade34468", "typ": "Bearer", "azp": "oauth2-client-app", "session_state": "4b46d62b-0dbe-41ba-9901-a2465eed5f41", "acr": "1", "realm_access": { "roles": [ "offline_access", "uma_authorization", "default-roles-oauth2" ] }, "resource_access": { "realm-management": { "roles": [ "manage-users", "view-users", "query-groups", "query-users" ] }, "account": { "roles": [ "manage-account", "manage-account-links", "view-profile" ] } }, "scope": "profile email", "sid": "4b46d62b-0dbe-41ba-9901-a2465eed5f41", "email_verified": false, "name": "kakarot lim", "preferred_username": "user", "given_name": "kakarot", "family_name": "lim", "email": "user@keycloak.com" }구글링 해서 알아본 결과 authorization_code를 요청할때 헤더에 scope=openid 로 하니 잘되었습니다. 이건 버전 차이라고 보면 될까요? 저는 도커로 20 버전을 사용하였습니다.
- 미해결스프링 시큐리티 OAuth2
ProviderUser 인터페이스 질문
ProviderUser 인터페이스에서 OAuth2User getOAuth2User(); 함수를 구현하는 부분을 못찾겠습니다. GoogleUser, KakaoUser, NaverUser클래스에 해당 함수를 오버라이드 해야하지 않나요?
- 미해결스프링 시큐리티 OAuth2
잘 안 들리는 부분이 있어서 질문 남깁니다.
처음 강의 시작하는 부분에서앞서 캔슬된 강의가 있다는 건가요?무슨 내용인지 궁금해서 질문 남깁니다.
- 미해결스프링 시큐리티 OAuth2
질문드립니다. 초기화 과정 이해 - OAuth2AuthorizationServerConfiguration - [06:27]
안녕하세요Spring Authorization Server초기화 과정 이해 - OAuth2AuthorizationServerConfiguration 강의 중[06:27] 에서ResourceOwnerPasswordCredentialsAuthenticationProvider 가 없다고 하셨는데그렇다면 패스워드 자격증명 승인 방식은 사용할수 없나요?
- 미해결스프링 시큐리티 OAuth2
OAuth 2.0 Social Login 연동 구현(5)
OAuth2GoogleProviderUserConverter 클래스와 OAuth2NaverProviderUserConverter 클래스에서 provider가 구글인지 네이버인지 구분하는 조건문에 에러가 발생합니다. 아마 디버깅하는 과정에서 수정됐는데 영상에선 편집된것 같습니다.두 개 클래스 모두 이렇게 변경해야 됩니다.if (!providerUserRequest.clientRegistration().getRegistrationId().equals(OAuth2Config.SocialType.GOOGLE.getSocialName())) { return null; }if (!providerUserRequest.clientRegistration().getRegistrationId().equals(OAuth2Config.SocialType.NAVER.getSocialName())) { return null; }
- 미해결스프링 시큐리티 OAuth2
강의자료 제공여부 문의
- 학습 관련 질문을 남겨주세요. 상세히 작성하면 더 좋아요! - 먼저 유사한 질문이 있었는지 검색해보세요. - 서로 예의를 지키며 존중하는 문화를 만들어가요. - 잠깐! 인프런 서비스 운영 관련 문의는 1:1 문의하기를 이용해주세요.혹시 강의때 사용하신 자료는 받을 수 없는걸까요??
- 미해결스프링 시큐리티 OAuth2
강의 순서 관련
OAuth 2.0 Client - oauth2Client() 챕터의 강의 순서가 바뀐 것 같아 문의드립니다.DefaultOAuth2AuthorizedClientManager - Client Credentials 권한 부여 구현하기 강의가 DefaultOAuth2AuthorizedClientManager - Resource Owner Password 권한 부여 구현하기(1) 강의 이후에 배치되어야 하는 것 같습니다.그러고 보니 DefaultOAuth2AuthorizedClientManager - Resource Owner Password 권한 부여 구현하기(1) 강의도 2편인데 ~구현하기(1)로 표시되어 있습니다.