GithubHelp home page GithubHelp logo

Foursquare support about django-social-auth HOT 23 CLOSED

omab avatar omab commented on June 25, 2024
Foursquare support

from django-social-auth.

Comments (23)

omab avatar omab commented on June 25, 2024

Looks quite similar to Google OAuth2 implementation, take a look to it, it should be easy to mimic.

from django-social-auth.

m-misseri avatar m-misseri commented on June 25, 2024

For OAuth2 is important the callback url and the domain from I testing the code?
Because in local I'm using 127.0.0.1 but in callback and in server name settings I have used another domains.....

Must i use the same domain like in facebook login testing?

Now i receive in the query string:
?error=invalid_client

and this:

HTTPError: HTTP Error 400: Bad Request

Thanks in advance omab

from django-social-auth.

omab avatar omab commented on June 25, 2024

Depends on the site. Some providers enforce that the domain from where the request is made must be the same as the one defined in the app configuration, others don't, but seems that foursquare is checking it.

An easy workaround is to serve the same domain from localhost, for example, let's suppose that the domain used in the Foursquare app configuration was example.com

  1. Add example.com to /etc/hosts

    127.0.0.1 example.com

  2. Define Django SITE_URL to use the desired domain

    SITE_URL = 'http://example.com'

  3. Run the server, and open it in your browser using http://example.com:8000/. The redirect from Foursquare might lack the port number and that will pop a 404 error on your browser, just add :8000 to the URL and it should work.

from django-social-auth.

m-misseri avatar m-misseri commented on June 25, 2024

Yes, i know that workaround, thanks. :-)

Can you take a look on this: http://dpaste.com/hold/543641/ ?

The authentication work:
/accounts/login/foursquare/ redirect to:

https://it.foursquare.com/oauth2/authenticate?redirect_uri=http%3A%2F%2Fmyapp.com%2Faccounts%2Fcomplete%2Ffoursquare%2F&response_type=code&client_id=**

for asking the permission, then after accepting permission the foursquare server redirect to:

http://myapp.com/accounts/complete/foursquare/?code=K**FBN34A

But now, i don't know how i can complete the authorization and why access_token is Null.

Can you help me?
Thanks!

from django-social-auth.

bremac avatar bremac commented on June 25, 2024

cgi.parse_qs parses query strings. Foursquare responds with a JSON-formatted response, so it should be parsed with simplejson.

from django-social-auth.

omab avatar omab commented on June 25, 2024

Looking at your code, seems that you are inheriting from BaseOAuth instead of BaseOAuth2 (https://github.com/omab/django-social-auth/blob/master/social_auth/backends/__init__.py#L628), that should simplify and fix your issues, OAuth2 standard defines responses as JSon strings and they are decoded properly (https://github.com/omab/django-social-auth/blob/master/social_auth/backends/__init__.py#L663)

from django-social-auth.

m-misseri avatar m-misseri commented on June 25, 2024

Ok, i have fixed.
Now i receive these error:
http://dpaste.com/543811/plain/
The code updated is:
http://dpaste.com/hold/543812/

Thanks for the support guys.

from django-social-auth.

omab avatar omab commented on June 25, 2024

Could you share the JSON server response?

from django-social-auth.

m-misseri avatar m-misseri commented on June 25, 2024

Yes, it's this:

{'access_token': 'R0SMPBGO2OGYY0DZPVGM*******O'}

from django-social-auth.

omab avatar omab commented on June 25, 2024

Only access_token? The code that raises the KeyError is trying to get an 'id' entry from the server response, that ID is used to identify the current user with the provider. But you can override the method to suit the foursquare case, in google I needed to override it to use the email address https://github.com/omab/django-social-auth/blob/master/social_auth/backends/google.py#L50, check the details and response data, it might have some value that's unique for current user.

from django-social-auth.

m-misseri avatar m-misseri commented on June 25, 2024

Now seems to work, but there is another problem.

After authorization..
if i disconnect my account (logout) /accounts/logout/ and i want to re-login with foursquare, it ask to me every time the window for asking the permission..

Now i'm using:
https://foursquare.com/oauth2/authorize
?client_id=YOUR_CLIENT_ID
&response_type=code
&redirect_uri=YOUR_REGISTERED_REDIRECT_URI

If i use:
https://foursquare.com/oauth2/authenticate
?client_id=YOUR_CLIENT_ID
&response_type=code
&redirect_uri=YOUR_REGISTERED_REDIRECT_URI

After the login the foursquare server don't reply any, 'error when loading the page'.. but the first auth work correctly.

The code is this:
http://dpaste.com/hold/544013/

Who can help me? :-)

Thanks!

from django-social-auth.

omab avatar omab commented on June 25, 2024

Mmm... I didn't understood you, are you getting an error or not? Which is the error?

from django-social-auth.

m-misseri avatar m-misseri commented on June 25, 2024

Sorry for my bad english.

The problem is this:
The foursquare server asks me the permissions for the login every time, instead that only the first time.

Understand?
There are no errors..

from django-social-auth.

omab avatar omab commented on June 25, 2024

No prob at all, it's not my main language, so that makes things worse :D

What happens when you change the service to "/oauth2/authenticate"? Twitter does the same, /authorize/ asks user permission every time, while /authenticate/ only asks once.

from django-social-auth.

m-misseri avatar m-misseri commented on June 25, 2024

If I change to /authenticate/ the system redirect here:

https://foursquare.com/oauth2/authenticate?redirect_uri=http%3A%2F%2Fmyapp.com%2Faccounts%2Fcomplete%2Ffoursquare%2F&response_type=code&client_id=GIA4VU1ZHJIYT05325FYXS1FZGKVKRSNHOJYWYSXF0***

but the link not work :(
Error connection.

from django-social-auth.

omab avatar omab commented on June 25, 2024

This code http://dpaste.com/hold/544082/ worked properly for me, it's a simplification from your last code, I've removed the overridden functions because they weren't needed at all. It worked with /authorize/ and /authenticate/ properly.

You need to add this two settings to your local_settings or what ever place you keep them::

FOURSQUARE_CONSUMER_KEY = 'YOUR_CONSUMER_KEY'
FOURSQUARE_CONSUMER_SECRET = 'YOUR_CONSUMER_SECRET_KEY'

I'll merge your work if you create a fork of the project and add this backend.

from django-social-auth.

m-misseri avatar m-misseri commented on June 25, 2024

Thanks, but now return to me: ?error=redirect_uri_mismatch
whit this error:
http://dpaste.com/hold/544089/

Must I set it?

Thanks..another ;)

from django-social-auth.

omab avatar omab commented on June 25, 2024

That's because Foursquare is checking the referer url with the one you defined on their app. I've defined http://myapp.com:8000/complete/foursquare/ as redirect on foursquare site, and check the site locally opening http://myapp.com:8000/ (previous /etc/hosts workaround).

from django-social-auth.

m-misseri avatar m-misseri commented on June 25, 2024

Oh yeah!
My error was
Callback URL http://myapp.com:8000/complete/foursquare/
instead of
Callback URL http://myapp.com:8000/accounts/complete/foursquare/

In the foursquare settings :)

Thanks Thousands omab! Seems to work all correctly!

I'll create the fork soon

from django-social-auth.

m-misseri avatar m-misseri commented on June 25, 2024

Ok, created :)
This is my first fork.. i must exercise with git because this is the first time that i use it :)
https://github.com/bedspax/django-social-auth
I'v mistake?
Let me know.

from django-social-auth.

omab avatar omab commented on June 25, 2024

The fork is OK, but contrib backends should be on backends/contrib directory, could you move it?

from django-social-auth.

m-misseri avatar m-misseri commented on June 25, 2024

Moved! :-)

from django-social-auth.

omab avatar omab commented on June 25, 2024

Merged https://github.com/omab/django-social-auth/tree/4f53065e1b42da98fc3f241407e68ada0b1922c5

Thanks

from django-social-auth.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.