Bike Index strategy for python flask social
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
""" | |
Some information about OAuth on the Bike Index available, srys, still under development | |
https://github.com/bikeindex/omniauth-bike-index | |
""" | |
from social.backends.oauth import BaseOAuth2 | |
class BikeIndexOAuth2(BaseOAuth2): | |
name = 'bikeindex' | |
ID_KEY = 'id' | |
AUTHORIZATION_URL = 'https://bikeindex.org/oauth/authorize' | |
ACCESS_TOKEN_URL = 'https://bikeindex.org/oauth/authorize' | |
DEFAULT_SCOPE = ['read_bikes'] | |
REDIRECT_STATE = False | |
ACCESS_TOKEN_METHOD = 'POST' | |
EXTRA_DATA = [ | |
('refresh_token', 'refresh_token', True), | |
('id', 'id'), | |
('bike_ids', 'bike_id') | |
] | |
def get_user_details(self, response): | |
"""Return user details from Bike Index account""" | |
name = response.get('name') or '' | |
return {'bike_ids': response.get('bike_ids')} | |
def user_data(self, access_token, *args, **kwargs): | |
"""Grab user profile information from Bike Index.""" | |
response = self.get_json('https://bikeindex.org/api/v2/users/current', | |
params={'access_token': access_token}) | |
if 'bike_ids' in response: | |
response = { | |
'bike_id': response['bike_ids'] | |
} | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Modeled after Amazon's strategy - you can view the Bike Index ruby strategy here
I put in a
default_scope
ofread_bikes
, even though that isn't the default scope because it's the scope that is going to be the most useful. But really, it should bepublic
and you should addread_bikes
andread_user
when you create the app.