403 Client Error: Forbidden for url: https://api.twitter.com/oauth/request_token - django

I am trying to add twitter credential to my login system, I keep getting 403 Client Error, I read this but doesn't have an answer. I followed the steps mentioned here no luck.
I tried these patterns with Callback URL no luck:
http://127.0.0.1/
http://127.0.0.1:8000/
http://127.0.0.1/complete/twitter/
http://127.0.0.1/oauth/complete/twitter/
website URL doesn't accept localhost so I put my old website which is not working at the moment. Please help, what's wrong with setting up twitter credential api?

Related

django code 400, message Bad request version ('î\x9el\x00$\x13\x01\x13\x03\x13\x02À+À/̨̩À,À0À')

I was trying to implement 'Securing Django Admin login with OTP', however I can't login into the admin panel now. I removed the app from everywhere but still doesn't work. Any solution for this?
[05/Feb/2021 21:39:49] code 400, message Bad request version ('î\x9el\x00$\x13\x01\x13\x03\x13\x02À+À/̨̩À,À0À')
[05/Feb/2021 21:39:49] You're accessing the development server over HTTPS, but it only supports HTTP.
If you are on development version you cant use https connection on your localhost so just turn your URL to http and error will be disappear.
ex:
https://localhost:8000
or
https://127.0.0.1:8000
just turn it to
http://localhost:8000
or
http://127.0.0.1:8000
also may be at 127.0.0.1:8000

My Django app passes authentication on localhost, but not on heroku

So I created a simple "social media website" where by using API I GET data from a database and I can also POST to create a social media post after I register and log in.
On my localhost it all works well. I can register, login, then write a social media post and it displays on the screen.
However, when I use Heroku, GET API works fine, but after I log in (and I am sure I am logged in as I can log in on admin), I cannot write anything on my website. In my IDE I get: Forbidden: /api/posts/action/
In the network page I can see this:
Request URL: http://localhost:8000/api/posts/action/
Request Method: POST
Status Code: 403 Forbidden
Remote Address: 127.0.0.1:8000
Referrer Policy: no-referrer-when-downgrade
Any idea where should I look for an error? If there is any code I should send, let me know. Thank you!
Your server's domain in Heroku shouldn't be localhost:8000
You need to use the correct domain/IP address, and remember to put the domain/IP address in ALLOWED_HOSTS in the setting file.
If you don't set up a custom domain, then the default domain should be like:
https://<dyno name>.herokuapps.com

Django-allauth URL Returns callback error for github despite correct url

I am trying to implement all-auth using Github in my django project. I have set the callback url as per this tutorial. So far, even if the login page for github shows up, it doesn't call back properly and I get this error in the url
http://127.0.0.1:8000/accounts/github/login/callback/?error=redirect_uri_mismatch&error_description=The+redirect_uri+MUST+match+the+registered+callback+URL+for+this+application.&error_uri=https%3A%2F%2Fdeveloper.github.com%2Fapps%2Fmanaging-oauth-apps%2Ftroubleshooting-authorization-request-errors%2F%23redirect-uri-mismatch&state=exDbVJKNYzUI
This is the github repo of the project.
http://127.0.0.1:8000/accounts/github/login/callback/
is my authorization callback url set as per the tutorial.
Any insight to why the callback url is not working is welcome. Thanks.
For those who are looking for an answer to this,
if you configure the callback url to be from 127.0.0.1, make sure you're requesting the callback from the same url. Although localhost and 127.0.0.1 both point to the same, it is different urls. So you will get url mismatch error.
If you defined authorization callback in the GitHub UI with https protocol than this setting solves the issue:
ACCOUNT_DEFAULT_HTTP_PROTOCOL='https'
This is coming from the answer found here: Django allauth google OAuth redirect_uri_mismatch error

Django, django-allauth and the battlenet provider

First time attempting to use oauth with python django and django-allauth. I can't seem to make logins happen. I can get to the point where you are asked to authorize your site with battlenet, but when you're redirected to the callback url I just get this:
{'code': 'unknown', 'provider': 'battlenet', 'exception': ProxyError(MaxRetryError("HTTPSConnectionPool(host='us.battle.net', port=443): Max retries exceeded with url: /oauth/token (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 403 Forbidden',)))",),)}
I have created my application in dev.battle.net, I've put the client key and the secret key in my django-allauth app, but I get stuck at this point.
Anyone have any experience with this?
I managed to answer my own question.
I'm using pythonanywhere to host this for now and I was using the free service. Seems there's a white list of urls that you can hit if you're a free user and us.battle.net was not on the list. I registered for a month and after a few minutes my oauth calls work fine.
If anyone else happens to be in my situation, here's the list of sites that pythonanywhere can hit for free accounts.
https://www.pythonanywhere.com/whitelist/
What kind of proxy are you running? Nginx + Gunicorn? It's trying to hit '/oauth/token' and failing on that. I've just set up a allauth with Battle.net but I didn't see this along the way.
What does your urls.py and settings.py look like?
You need to have SITE_ID specified in your settings file.
Ensure your reverse proxy is handling https requests.

how to debug facebook app/django setup (url is not valid...)

I'm trying to set up a facebook app using django by following this tutorial: http://www.rkblog.rk.edu.pl/w/p/example-facebook-application-django/ . I get to the point where I start my development server at (manage.py runserver 0.0.0.0:80)
then it says: Now under http://apps.facebook.com/NAME/ you should see a basic Facebook app comming from your server:
I, however, get an error message:
The URL http://my.ip/my_app_name/ is not valid.
I think I've set things up properly:
Canvas Page URL:
http://apps.facebook.com/my_app_name/
Canvas Callback URL
http://my.ip/my_app_name/
Question: how do I go about finding out what's wrong?
Thanks in advance!
Martin
update: when i visit http://my.ip/myappname/, it redirects to http://apps.facebook.com/my_app_name/?auth_token=eac7bf38fb5e591c55ddc458d16dc9b7
where i get the 'url not valid' message... However, when I paste the url with auth_token in it, django serves the requested page as expected... why is facebook saying the url is not valid if in fact it is...?
Is your router set up to forward requests on port 80 to your development machine? If not, you will get an error, as the way Facebook apps work is that Facebook's servers contact your server, get the content, then parse it and re-serve it back to the client.
I actually find with Facebook apps that the easiest thing to do is what you describe in your last sentence - get the auth_token URL, then paste it locally and work from there.