-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from akshar-raaj/add_more_providers
Add more providers
- Loading branch information
Showing
9 changed files
with
213 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from oauth import oauth | ||
from django.conf import settings | ||
import httplib | ||
|
||
FOURSQUARE_AUTHENTICATION_URL = 'https://foursquare.com/oauth2/authenticate' | ||
FOURSQUARE_ACCESS_TOKEN_URL = 'https://foursquare.com/oauth2/access_token' | ||
FOURSQUARE_CONSUMER_KEY = getattr(settings, 'FOURSQUARE_CONSUMER_KEY') | ||
FOURSQUARE_CONSUMER_SECRET = getattr(settings, 'FOURSQUARE_CONSUMER_SECRET') | ||
REGISTERED_REDIRECT_URI = getattr(settings, 'FOURSQUARE_REGISTERED_REDIRECT_URI') | ||
|
||
def get_http_connection(): | ||
return httplib.HTTPSConnection('foursquare.com') | ||
|
||
def get_response_body(oauth_request): | ||
http_conn = get_http_connection() | ||
http_conn.request('GET', oauth_request.to_url()) | ||
response = http_conn.getresponse().read() | ||
return response | ||
|
||
|
||
class FourSquareClient(object): | ||
def __init__(self): | ||
self.consumer = oauth.OAuthConsumer(FOURSQUARE_CONSUMER_KEY, FOURSQUARE_CONSUMER_SECRET) | ||
|
||
def get_authentication_url(self): | ||
parameters = {} | ||
parameters['client_id'] = FOURSQUARE_CONSUMER_KEY | ||
parameters['response_type'] = 'code' | ||
parameters['redirect_uri'] = REGISTERED_REDIRECT_URI | ||
oauth_request = oauth.OAuthRequest.from_consumer_and_token(self.consumer, http_url=FOURSQUARE_AUTHENTICATION_URL, parameters=parameters) | ||
return oauth_request.to_url() | ||
|
||
def get_access_token(self, foursquare_code): | ||
parameters = {} | ||
parameters['client_id'] = FOURSQUARE_CONSUMER_KEY | ||
parameters['client_secret'] = FOURSQUARE_CONSUMER_SECRET | ||
parameters['grant_type'] = 'authorization_code' | ||
parameters['redirect_uri'] = REGISTERED_REDIRECT_URI | ||
parameters['code'] = foursquare_code | ||
oauth_request = oauth.OAuthRequest.from_consumer_and_token(self.consumer, http_url=FOURSQUARE_ACCESS_TOKEN_URL, parameters=parameters) | ||
access_token_response = get_response_body(oauth_request) | ||
return access_token_response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from django.conf import settings | ||
from oauth.oauth import OAuthConsumer, OAuthRequest | ||
import httplib | ||
|
||
GITHUB_CLIENT_ID = getattr(settings, 'GITHUB_CLIENT_ID') | ||
GITHUB_CLIENT_SECRET = getattr(settings, 'GITHUB_CLIENT_SECRET') | ||
GITHUB_AUTHORIZE_URL = 'https://github.com/login/oauth/authorize' | ||
GITHUB_ACCESS_TOKEN_URL = 'https://github.com/login/oauth/access_token' | ||
|
||
def get_response_from_url(to_url): | ||
conn = httplib.HTTPSConnection('github.com') | ||
conn.request('GET', to_url) | ||
return conn.getresponse().read() | ||
|
||
class GithubClient(object): | ||
def __init__(self): | ||
self.consumer = OAuthConsumer(GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET) | ||
|
||
def get_authorize_url(self): | ||
parameters = {'client_id':GITHUB_CLIENT_ID} | ||
oauth_request = OAuthRequest.from_consumer_and_token(self.consumer, http_url=GITHUB_AUTHORIZE_URL, parameters=parameters) | ||
return oauth_request.to_url() | ||
|
||
def get_access_token(self, code): | ||
parameters = {} | ||
parameters['client_id'] = GITHUB_CLIENT_ID | ||
parameters['client_secret'] = GITHUB_CLIENT_SECRET | ||
parameters['code'] = code | ||
oauth_request = OAuthRequest.from_consumer_and_token(self.consumer, http_url=GITHUB_ACCESS_TOKEN_URL, parameters=parameters) | ||
access_token = get_response_from_url(oauth_request.to_url()) | ||
return access_token |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters