I use python-social-auth for my django site, let's say: example.io. It was working. But, after redeploy, and try to log in via Twitter, it redirect to wrong URL, example only, without the .io
I also tried to use another url, staging.example.io, it still redirects to example, without staging and io
I try to deploy it in local, so the URL is localhost:12345, and it's redirecting to the right url (to localhost:12345 or 127.0.0.1:12345), and sign in successfully.
Anyone knows something about it?
Update:
I have tried to use another url, for example, abc.def.com but stil redirect to example (withouth .io). It also happened for LinkedIn social auth.
Related
I started recently working on API's and few API providers are not requesting redirect URL while some others are requesting. I have written an algorithmic strategy for trading using python. When I requested for API to Fyers(stockbroker), the team said me to provide a redirect URL. what is a redirect URL? and how to create it?
I have attached image for reference. In the above image, there is a text box for Redirect URL. Can you please explain what exactly is Redirect URL and how to create one for calling API for authentication if my code is on heroku?
The Redirect URL is required by the oAuth workflow: basically the authorisation server will redirect the user back to the URL registered as "Redirect URL" including an authorization code or a token.
If you register a URL like https://myapp.herokuapp.com you will be redirected to
https://myapp.herokuapp.com?access_code=XXX&app_id=YYY
The Redirect URL needs to be a valid accessible page: if the process is manual you just copy the access_code from the browser and use it accordingly.
If it is an application you need to receive the redirect above (the URL is basically your app), fetch the required information (parameters) and implement your logic.
Default Fyers Redirect URL for Testing
Use the default url from fyers
https://trade.fyers.in/api-login/redirect-uri/index.html
Copy the auth key value
Use it in your python app in the second run
You can also use google collab, to run part of code only (authentication) without restarting the whole project
This question is in the reference of this. As suggested I am using simpleauth to login via linkedin. Now I am having trouble with the redirect_uri. I have successfully deployed dev_appserver.py example/ but when I click on LinkedIn Oauth2, I get this error.
invalid redirect_uri. This value must match a URL registered with the API Key.
My redirect uri from url:
redirect_uri= http%3A%2F%2Flocalhost%3A8080%2Fauth%2Flinkedin2%2Fcallback
And I have entered same redirect url(http://localhost:8080/auth/linkedin/callback) in https://www.linkedin.com/developer/ page.
I was already stuck with previous library, and even this doesn't seems to work for me now.
Request url should be http://localhost:8080/auth/linkedin2/callback. Now it's working.
I want to use facebook api for which I will be needing oauth token, so when the program starts the python program will open the the authentication url by webbrowser.open() method after this the user will will give permission and then facebook will generate access token and redirect to a different link. I need to grab this redirected link and retrieve the access token. How do I grab this redirected url.
Afaik there is no simple way to do this (see Python - Getting url a browser was redirected to)
If you have a WebServer set the redirect page to your server and the get Tokens from there.
Otherwise use the python oauth module.
If you have a fb-app (with id and token) you can do it locally, althrough its not a very good/safe way..
This script succeeds at getting a 200 response object, getting a cookie, and returning reddit's stock homepage source. However, it is supposed to get the source of the "recent activity" subpage which can only be accessed after logging in. This makes me think it's failing to log in appropriately but the username and password are accurate, I've double checked that.
#!/usr/bin/python
import requests
import urllib2
auth = ('username', 'password')
with requests.session(auth=auth) as s:
c = s.get('http://www.reddit.com')
cookies = c.cookies
for k, v in cookies.items():
opener = urllib2.build_opener()
opener.addheaders.append(('cookie', '{}={}'.format(k, v)))
f = opener.open('http://www.reddit.com/account-activity')
print f.read()
It looks like you're using the standard "HTTP Basic" authentication, which is not what Reddit uses to log in to its web site. (Almost no web sites use HTTP Basic (which pops up a modal dialog box requesting authentication), but implement their own username/password form).
What you'll need to do is get the home page, read the login form fields, fill in the user name and password, POST the response back to the web site, get the resulting cookie, then use the cookie in future requests. There may be quite a number of other details for you to work out too, but you'll have to experiment.
I just think maybe we're having the same problem. I get status code 200 ok. But the script never logged me in. I'm getting some suggestions and help. Hopefully you'll let me know what works for you too. Seems reddit is using the same system too.
Check out this page where my problem is being discussed.
Authentication issue using requests on aspx site
I am trying to automate files download via a webserver. I plan on using wget or curl or python urllib / urllib2.
Most solutions use wget and urllib and urllib2. They all talk of HHTP based authentication and cookie based authentication. My problem is I dont know which one is used in the website that stores my data.
Here is the interaction with the site:
Normally I login to site http://www.anysite.com/index.cgi?
I get a form with a login and password. I type in both and hit return.
The url stays as http://www.anysite.com/index.cgi? during the entire interaction. But now I have a list of folders and files
If I click on a folder or file the URL changes to http://shamrockstructures.com/cgi-bin/index.cgi?page=download&file=%2Fhome%2Fjanysite%2Fpublic_html%2Fuser_data%2Fuserareas%2Ffile.tar.bz2
And the browser offers me a chance to save the file
I want to know how to figure out whether the site is using HTTP or cookie based authentication. After which I am assuming I can use cookielib or urllib2 in python to connect to it, get the list of files and folders and recursively download everything while staying connected.
p.S: I have tried the cookie cutter ways to connect via wget and wget --http-user "uname" --http-password "passwd" http://www.anysite.com/index.cgi? , but they only return the web form back to me.
If you log in using a Web page, the site is probably using cookie-based authentication. (It could technically use HTTP basic auth, by embedding your credentials in the URI, but this would be a dumb thing to do in most cases.) If you get a separate, smallish dialog with a user name and password field (like this one), it is using HTTP basic authentication.
If you try to log in using HTTP basic auth, and get back the login page, as is happening to you, this is a certain indication that the site is not using HTTP basic auth.
Most sites use cookie-based authentication these days. To do this with an HTTP cilent such as urllib2, you will need to do an HTTP POST of the fields in the login form. (You may need to actually request the login form first, as a site could include a cookie that you need to even log in, but usually this is not necessary.) This should return a "successfully logged in" page that you can test for. Save the cookies you get back from this request. When making the next request, include these cookies. Each request you make may respond with cookies, and you need to save those and send them again with the next request.
urllib2 has a function called a "cookie jar" which will automatically handle the cookies for you as you send requests and receive Web pages. That's what you want.
You can use pycurl like this:
import pycurl
COOKIE_JAR = 'cookiejar' # file to store the cookies
LOGIN_URL = 'http://www.yoursite.com/login.cgi'
USER_FIELD = 'user' # Name of the element in the HTML form
USER = 'joe'
PASSWD_FIELD = 'passwd' # Name of the element in the HTML form
PASSWD = 'MySecretPassword'
def read(html):
"""Read the body of the response, with posible
future html parsing and re-requesting"""
print html
com = pycurl.Curl()
com.setopt(pycurl.WRITEFUNCTION, read)
com.setopt(pycurl.COOKIEJAR, COOKIE_JAR)
com.setopt(pycurl.FOLLOWLOCATION, 1) # follow redirects
com.setopt(pycurl.POST, 1)
com.setopt(pycurl.POSTFIELDS, '%s=%s;%s=%s'%(USER_FIELD, USER,
PASSWD_FIELD, PASSWD))
com.setopt(pycurl.URL, LOGIN_URL )
com.perform()
Plain pycurl it may seam very "primitive" (with the limited setopt approach),
but it gets the job done, and handle pretty well the cookies with the cookie jar option.
AFAIK cookie based authentication is only used once you have logged in successfully atleast ONCE. You can try disabling storing cookies from that domain by changing your browser settings, if you are still able to download files that it should be a HTTP based authentication.
Try doing a equivalent GET request for the (possibly POST) login request that is probably happening right now for login. Use firebug or fiddler to see the login request that is sent.
Also note if there is some javascript code which is returning you a different output, based on your useragent string or some other parameter.
See if httplib, mechanize helps.