Skip to content

Instantly share code, notes, and snippets.

@sethherr
Last active August 29, 2015 14:09
Embed
What would you like to do?
Bike Index strategy for python flask social
"""
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
@sethherr
Copy link
Author

Modeled after Amazon's strategy - you can view the Bike Index ruby strategy here

I put in a default_scope of read_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 be public and you should add read_bikes and read_user when you create the app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment