Devise Oauth Twitter: OAuth::Unauthorized Forbidden 403

自古美人都是妖i 提交于 2019-12-10 16:14:21

问题


I am trying to implement Oauth Twitter using Devise.
I have created app on twitter
I have set callback url to: http://localhost:3000
I have added this to config\initializers\devise.rb

  config.omniauth :twitter, "key", "key secret"

Sign in with Twitter automatically appears at this route: /users/sign_up/ But on clicking it I get this error

key and key secret are correct

I also tried deleting and creating new app.

I cannot get it fixed

Help would be greatly appreciated

Here it says that https needs to be setup. So I followed This to set it up. But getting the same error


回答1:


Turns out that in twitter app settings Callback URL Lock was set to Yes by default. Switching it to No fixed the error.

Thanks to kubido for helping me out to close the issue on github




回答2:


You can try to add these in the Callback URLs in https://apps.twitter.com/

  • http://localhost:3000/auth/twitter/callback
  • http://127.0.0.1:3000/
  • http://127.0.0.1:3000/auth/twitter/callback

Worked for me after almost an hour!

I got these URLs after failing the log-in. I checked the request_options. One way to do it is using BetterErrors gem.




回答3:


I had been facing the same issue, eventually i fixed it by adding the following callbacks,

http://127.0.0.1:3000/auth/twitter/callback
http://127.0.0.1/
http://127.0.0.1/auth/twitter/callback
http://localhost:3000/auth/twitter/callback

and it worked like a charm,




回答4:


Seems like Twitter has problems with the localhost/127.0.0.1 callback, but using ngrok to create a public URL to expose my local server solves the issue.

Start ngrok:

ngrok http 3000

Update the Twitter app callback URL with the HTTPS URL created by ngrok.

Example:

https://4e1ab946.ngrok.io/auth/twitter/callback

Start the rails server on port 3000 and point your browser to:

https://4e1ab946.ngrok.io/auth/twitter

Should work now.



来源:https://stackoverflow.com/questions/50560813/devise-oauth-twitter-oauthunauthorized-forbidden-403

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!