Twitter 로그인 401 Authorization Required
5747 단어 TwitterAPIRailssorcery
개요
Sorcery의 External을 사용하여 Twitter 로그인 기능을 구현하는 동안 오류를 해결합니다.
우선 이 기사 을 참고로 해소하려고 했지만 무리였으므로 디버그해 나가기로 했다.
브라우저 오류 화면
로그인 버튼으로 OauthsController/oauth
에 요청, 콜백으로 401 Authorization Required

로그 보기
log/development.log

잘 리디렉션되지 않은 것 같지만 원인을 모른다.
Unpermitted parameters: :oauth_token, :oauth_verifier
가 있기 때문에 OauthsController/auth_params에 추가해도 오류는 변함없이.
binding.pry에서 멈춰보세요

login_from(provider)
여기서 true도 false도 nil도 아니고 에러가 들어가 있습니까?
마지막 줄에 from/Users/...consumer.rb:236
그리고 이기 때문에 gem 안쪽을 보러 간다.
consumer.rb에서 pry
첫 번째
Twitter 측에 갈 때의 거동?

response
200response.body
oauth_token과 oauth_token_secret이 저장되어 있습니다.
문제 없을 것 같아서 exit
두 번째
Twitter측에서 인증 처리를 한다?

response
200response.body
oauth_token과 oauth_token_secret이 저장되어 있습니다.
첫 번째와 정확히 동일exit
에서 빠진다
세 번째
앱 측으로 돌아오는(콜백)시의 처리?

response
401 Authorization Requiredresponse.body
Error processing your OAuth request: Invalid oauth_verifier parameter
드디어 검색 할 수있는 것 같은 오류 메시지가 나왔기 때문에 검색.
Error processing your OAuth request: Invalid oauth_verifier parameter
한쪽 끝에서 봤는데 아무것도 잘 안된다.
콜백 처리 같을 때에 에러 나왔기 때문에 그 쪽을 보아 가는 것에.
다시 전화 요청할 때
[Twitter Developer에 등록한 콜백 URL]

[애플리케이션 측에서 설정한 콜백 URL]

쿼리가 붙어 있다고 하고 있을지 없는지만으로 URL의 무결성은 취하고 있다.
여기서 막힌다.
다른 URL에서도 시도하려고 생각 ngrok
되는 것을 사용해 보았다.
ngrok로 로컬 환경을 외부에 게시
이 기사 을 참고로 설정한다.
일시적으로 도메인을 얻을 수 있습니까? 느낌의 도구라고 인식하고 있다.
$ brew cask install ngrok
$ ngrok http 3000
ngrok by @inconshreveable (Ctrl+C to quit)
Session Status online
Session Expires 5 hours, 17 minutes
Version 2.3.35
Region United States (us)
Web Interface http://127.0.0.1:4040
Forwarding http://377716c9.ngrok.io -> http://localhost:3000
Forwarding https://377716c9.ngrok.io -> http://localhost:3000
Twitter Developere 업데이트

애플리케이션 콜백 URL도 업데이트

서버 재부팅을 잊지 않고
ctrl + c
$ rails s
http://377716c9.ngrok.io
방문
로그인해 보면・・・성공했다! ! ! ! ! ! ! ! ! ! ! !
왜?
해결
두 가지 차이점을 비교해 보면 콜백 URL이 정확히 일치하는지 여부.http://localhost:3000/
대신 http://127.0.0.1:3000/
에 액세스하여 로그인하면 성공했습니다.
127.0.0.1
는 IP 주소로 그 도메인이 localhost
이므로 같은 의미일 것이라고 고를 묶고 있었던 것이 원인이었습니다.
※ Sorcery의 Github이라면 콜백 URL이 http://0.0.0.0:3000/oauth/callback?provider=facebook
가 되어 있기 때문에, 이 설정으로 http://localhost:3000
에 액세스 하면 에러이기 때문에 조심해.
Reference
이 문제에 관하여(Twitter 로그인 401 Authorization Required), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/niwa1903/items/2d6a3e9c103652d88538
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
$ brew cask install ngrok
$ ngrok http 3000
ngrok by @inconshreveable (Ctrl+C to quit)
Session Status online
Session Expires 5 hours, 17 minutes
Version 2.3.35
Region United States (us)
Web Interface http://127.0.0.1:4040
Forwarding http://377716c9.ngrok.io -> http://localhost:3000
Forwarding https://377716c9.ngrok.io -> http://localhost:3000
ctrl + c
$ rails s
Reference
이 문제에 관하여(Twitter 로그인 401 Authorization Required), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/niwa1903/items/2d6a3e9c103652d88538텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)