Spring

https를 사용하지 않는 Spring OAuth 리디렉션_uri 해결방법

kimc 2023. 9. 14. 21:39
반응형

 


 

이번 글을 통해 배워 갈 내용

  1. Oauth 로그인 시에 https 대신 http 가 떠서 소셜로그인이 안 되는 경우 해결방법입니다

구글 OAuth 로그인 시에 

https 로 redirect를 설정했는데 http로 전송이 돼서 아래와 같은 오류 메시지가 뜨는 경우

 

-------------------- 액세스 차단됨: 이 앱의 요청이 잘못되었습니다 앱이름.com@gmail.com 이 앱에서 잘못된 요청을 전송했으므로 로그인할 수 없습니다. 나중에 다시 시도하거나 개발자에게 이 문제를 문의하세요. 이 오류에 관해 자세히 알아보기 이 앱의 개발자인 경우 오류 세부정보를 참고하세요. --------------------
--------------------오류 400: redirect_uri_mismatch앱이 Google의 OAuth 2.0 정책을 준수하지 않기 때문에 앱에 로그인할 수 없습니다.앱 개발자라면 Google Cloud Console에서 리디렉션 URI를 등록하세요.요청 세부정보: redirect_uri=http://www.앱이름.net/login/oauth2/code/google--------------------

 

일단 application.properties 파일에 아래와 같이 추가해 줍니다

 

server.forward-headers-strategy=native

그다음 nginx를 사용하신다면 아래와 같이 프락시 설정을 해줍니다

        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

간단 설명

forward-headers-strategy:native

forwared header를 다루는 방법을 설정하며

proxy 서버(예 Nginx)에서 설정한 header를 다룹니다

이번 예제에서는 스프링 부트 앱 앞에 있는 nginx에서 다루는 reverse 프락시를 다루었습니다

서버에서 기본으로 제공하는 native 방법을 채택합니다

 

proxy_set_header Host $http_host;

도메인명 같은 host header를 설정합니다

이를 통해 nginx가 원본 host header를 스프링에 보내는 것을 보장합니다

 

proxy_set_header X-Real-IP $remote_addr;

remote_addr를 판별하는데 유용하게 사용됩니다

 

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

거쳐서 온 프록시의 IP 주소들을 보여줍니다

 

proxy_set_header X-Forwarded-Proto $scheme;

원본 request 가 http인지 https 인지 판별해 줍니다

 


참조 및 인용

https://stackoverflow.com/questions/33812471

 

Spring OAuth redirect_uri not using https

I have a Spring Boot 1.3.0 application with Spring Security OAuth included as a sort of SSO integration. The problem is that the application is running in a non-SSL environment with a non-standard...

stackoverflow.com


블로그 추천 포스트

https://codemasterkimc.tistory.com/50

 

300년차 개발자의 좋은 코드 5계명 (Clean Code)

이번 글을 통해 배워갈 내용  좋은 코드(Clean Code)를 작성하기 위해 개발자로서 생각해볼 5가지 요소를 알아보겠습니다. 개요 좋은 코드란 무엇일까요? 저는 자원이 한정적인 컴퓨터 세상에서 좋

codemasterkimc.tistory.com

 

 

오늘도 즐거운 코딩 하시길 바랍니다 ~ :)

 


 

반응형