안녕하세요, Apple을 사용하여 Discourse 로그인용 API를 구축하고 있습니다. 이미 플러그인을 설치하고 Discourse Apple Authentication의 지시를 따랐습니다. 웹사이트에서 Apple 계정으로 Discourse에 로그인할 때는 정상적으로 작동합니다.
웹에서 Apple 로그인 흐름을 확인해 보니, 로그인용 Apple 페이지로 리디렉션되고, 로그인 성공 시 Apple에서 생성된 코드를 획득한 다음 다음으로 리디렉션됩니다:
state:{state}, code:{Apple에서 받은 code} 파라미터를 가진 POST {{discourse_host}}/auth/apple/callback
그 후, Discourse API에서 사용될 새로운 쿠키를 생성하는 GET {{discourse_host}}/auth/apple/callback?code={{Apple에서 받은 code}}&state={state}로 리디렉션됩니다.
이 흐름에서 /auth/apple/callback 호출 후 새로운 쿠키가 생성될 것으로 예상합니다.
하지만 API를 호출하려고 하면 Authorization timed out, or you have switched browsers. Please try again.(인증이 시간 초과되었거나 브라우저를 전환했습니다. 다시 시도해 주세요.)라는 오류가 표시됩니다.
그래서 Apple에서 생성한 새로운 코드로 다시 시도해 보았지만 여전히 같은 오류가 발생했습니다.
로그를 확인해 보니 다음과 같이 표시됩니다.
Started GET "/auth/apple/callback?code=c32f105b5084d42b8bd3e7051873ddb55.0.rrzxz.pChPU9zGlXIHHhgEXLiA5g&state=fbi3bbboud" for>
(apple) Setup endpoint detected, running now.
(apple) Callback phase initiated.
(apple) Authentication failure! csrf_detected: OmniAuth::Strategies::OAuth2::CallbackError, csrf_detected | CSRF detected
Started GET "/auth/failure?message=csrf_detected&strategy=apple" for 123.253.233.16 at 2023-11-27 06:10:28 +0000
Processing by Users::OmniauthCallbacksController#failure as HTML
Parameters: {"message"=>"csrf_detected", "strategy"=>"apple"}
Rendered users/omniauth_callbacks/failure.html.erb within layouts/no_ember (Duration: 4.1ms | Allocations: 17)
Rendered layout layouts/no_ember.html.erb (Duration: 57.5ms | Allocations: 2882)
Message (47 copies reported)
(apple) Authentication failure! csrf_detected: OmniAuth::Strategies::OAuth2::CallbackError, csrf_detected | CSRF detected
Backtrace
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/omniauth-1.9.2/lib/omniauth/strategy.rb:163:in `log'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/omniauth-1.9.2/lib/omniauth/strategy.rb:486:in `fail!'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/omniauth-oauth2-1.7.3/lib/omniauth/strategies/oauth2.rb:87:in `callback_phase'
/var/www/discourse/plugins/discourse-apple-auth/lib/omniauth_apple.rb:60:in `callback_phase'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/omniauth-1.9.2/lib/omniauth/strategy.rb:238:in `callback_call'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/omniauth-1.9.2/lib/omniauth/strategy.rb:189:in `call!'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/omniauth-1.9.2/lib/omniauth/strategy.rb:169:in `call'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/omniauth-1.9.2/lib/omniauth/strategy.rb:192:in `call!'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/omniauth-1.9.2/lib/omniauth/strategy.rb:169:in `call'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/omniauth-1.9.2/lib/omniauth/strategy.rb:192:in `call!'
따라서 API를 사용하여 Discourse Apple Sign-in을 사용하는 이 방향성이 이미 올바른지, 그리고 csrf_detected 오류 문제를 어떻게 해결해야 하는지 질문드립니다.





