shinsunyoung / springboot-developer

📚 <스프링부트 3 백엔드 개발자 되기> 예제코드
222 stars 87 forks source link

[Chapter 12] 358p "application.yml 파일을 열어 비밀값으로 정의한 client-id와 client-secret, 그리고 jwt 항목을 삭제하세요." 를 진행하면 오류가 뜹니다 #20

Closed K-tuna closed 1 year ago

K-tuna commented 1 year ago

image 처음엔 이런식으로 해보고 다음에는 저자님 깃허브 yml파일 복붙해봤는데 둘다 오류가 뜹니다.

image 깃헙액션 오류 메세지는 이렇고


APPLICATION FAILED TO START


Description:

Method filterChain in springbootdeveloper.config.WebOAuthSecurityConfig required a bean of type 'org.springframework.security.oauth2.client.registration.ClientRegistrationRepository' that could not be found.

Action:

Consider defining a bean of type 'org.springframework.security.oauth2.client.registration.ClientRegistrationRepository' in your configuration.

Process finished with exit code 1 저자님꺼 yml복붙하면 이런 오류가 뜹니다👆 yml 파일 안바꾸면 괜찮은데 바꾸기만 하면 오류가 뜹니다 어제 하루종일 해봤는데 모르겠네요 ㅠㅠ

K-tuna commented 1 year ago

깃허브 주소 안올려 드렸네요 https://github.com/dongwonkwon/myBlog

shinsunyoung commented 1 year ago

안녕하세요.

spring:
  jpa:
    show-sql: true
    properties:
      hibernate:
        format_sql: true
    defer-datasource-initialization: true
  h2:
    console:
      enabled: true
  security:
    oauth2:
      client:
        registration:
          google:
            client-id: client-id
            client-secret: client-secret
            scope:
              - email
              - profile
jwt:
  issuer: ajufresh@gmail.com
  secret_key: secret-key

이 코드 그대로로 바꿔보시고 다시 시도해보시겠어요?

K-tuna commented 1 year ago

이렇게 하니까 바로 성공했네요! 감사합니다! 그리고 질문이 더 있는데

  1. 로컬에서는 안 돌아가는게 정상이죠? 안지워야 돌아가고?
  2. 그리고 jwt issuer 값은 제 이메일로 해야 되는거죠?
shinsunyoung commented 1 year ago
  1. 로컬에서는 안 돌아가는게 정상이죠? 안지워야 돌아가고?

로컬에서도 저렇게 바꾸면 돌아가야합니다. 제가 예제코드를 합치다가 잘못 올라간 것 같은데 항목 자체를 지우면 안되고 의미없는 값으로 바꿔주셔야합니다. 그리고 실제로 서버에서 배포될때는 override되게 AWS에서 환경변수를 설정해줘야합니다!

  1. 그리고 jwt issuer 값은 제 이메일로 해야 되는거죠?

넵 issuer 자체가 발행자를 의미하기 때문에 본인 이메일로 적어주시면 됩니다.

K-tuna commented 1 year ago

로컬에서는 값 빼면 이런식으로 401 invalid_client 오류 떠서 image

이런식으로 실제 유효한 값을 넣어야 돌아가더라구요

spring:
  jpa:
    show-sql: true
    properties:
      hibernate:
        format_sql: true
    defer-datasource-initialization: true
  h2:
    console:
      enabled: true
  security:
    oauth2:
      client:
        registration:
          google:
            client-id: 617971.....
            client-secret: GOCSPX-KV...
            scope:
              - email
              - profile
jwt:
  issuer: ehddnjs0710@gmail.com
  secret_key: secret-key

로컬에서는 AWS 환경변수 설정이 없으니까 유효한 값을 직접 넣어야 돌아가는게 정상인거 맞나요? 제가 이해한게 맞죠?

shinsunyoung commented 1 year ago

네네 실행 자체는 되지만 실제로 로컬에서 동작을 확인하려면 유효한 값을 직접 넣어야하는게 맞습니다. 다만 깃허브에 민감한 값을 올리게 되면 탈취의 위험이 있기 때문에 빼고 커밋 - 푸시해달라고 말씀 드렸던 것이었습니다! 그래서 보통 로컬용 프로필을 따로 만들고(application-local.yml과 같은) .gitignore에 추가하는 방식으로 진행하기도 하는데 분량상 넣지 못했습니다 ... 🥲

K-tuna commented 1 year ago

그렇군요 주말에도 자세하게 알려주셔서 감사합니다! 덕분에 공부 많이 됐습니다! 👍👍