Remove Flask-OAuthlib and oauth_blender_id from Pillar
We switch completely to a rauth-based approach, allowing multiple providers for authentication.
This commit is contained in:
@@ -6,7 +6,6 @@ import typing
|
||||
|
||||
from flask import session, g
|
||||
import flask_login
|
||||
import flask_oauthlib.client
|
||||
from werkzeug.local import LocalProxy
|
||||
|
||||
from pillar import current_app
|
||||
@@ -222,35 +221,6 @@ def get_blender_id_oauth_token():
|
||||
return None
|
||||
|
||||
|
||||
def config_oauth_login(app):
|
||||
config = app.config
|
||||
if not config.get('SOCIAL_BLENDER_ID'):
|
||||
log.info('OAuth Blender-ID login not set up, no app config SOCIAL_BLENDER_ID.')
|
||||
return None
|
||||
if not config.get('BLENDER_ID_OAUTH_URL'):
|
||||
log.error('Unable to use Blender ID, missing configuration BLENDER_ID_OAUTH_URL.')
|
||||
return None
|
||||
|
||||
oauth = flask_oauthlib.client.OAuth(app)
|
||||
social_blender_id = config.get('SOCIAL_BLENDER_ID')
|
||||
|
||||
oauth_blender_id = oauth.remote_app(
|
||||
'blender_id',
|
||||
consumer_key=social_blender_id['app_id'],
|
||||
consumer_secret=social_blender_id['app_secret'],
|
||||
request_token_params={'scope': 'email'},
|
||||
base_url=config['BLENDER_ID_OAUTH_URL'],
|
||||
request_token_url=None,
|
||||
access_token_url=config['BLENDER_ID_BASE_ACCESS_TOKEN_URL'],
|
||||
authorize_url=config['BLENDER_ID_AUTHORIZE_URL']
|
||||
)
|
||||
|
||||
oauth_blender_id.tokengetter(get_blender_id_oauth_token)
|
||||
log.info('OAuth Blender-ID login setup as %s', social_blender_id['app_id'])
|
||||
|
||||
return oauth_blender_id
|
||||
|
||||
|
||||
def _get_current_user() -> UserClass:
|
||||
"""Returns the current user as a UserClass instance.
|
||||
|
||||
|
@@ -1,10 +1,10 @@
|
||||
import json
|
||||
|
||||
from rauth import OAuth2Service
|
||||
from flask import current_app, url_for, request, redirect
|
||||
from flask import current_app, url_for, request, redirect, session
|
||||
|
||||
|
||||
class OAuthSignIn(object):
|
||||
class OAuthSignIn:
|
||||
providers = None
|
||||
|
||||
def __init__(self, provider_name):
|
||||
@@ -27,6 +27,7 @@ class OAuthSignIn(object):
|
||||
def get_provider(cls, provider_name):
|
||||
if cls.providers is None:
|
||||
cls.providers = {}
|
||||
# TODO convert to the new __init_subclass__
|
||||
for provider_class in cls.__subclasses__():
|
||||
provider = provider_class()
|
||||
cls.providers[provider.provider_name] = provider
|
||||
@@ -35,7 +36,7 @@ class OAuthSignIn(object):
|
||||
|
||||
class BlenderIdSignIn(OAuthSignIn):
|
||||
def __init__(self):
|
||||
super(BlenderIdSignIn, self).__init__('blender-id')
|
||||
super().__init__('blender-id')
|
||||
|
||||
base_url = current_app.config['OAUTH_CREDENTIALS']['blender-id'].get(
|
||||
'base_url', 'https://www.blender.org/id/')
|
||||
@@ -73,6 +74,7 @@ class BlenderIdSignIn(OAuthSignIn):
|
||||
|
||||
me = oauth_session.get('user').json()
|
||||
# TODO handle case when user chooses not to disclose en email
|
||||
session['blender_id_oauth_token'] = oauth_session.access_token
|
||||
return (
|
||||
me['id'],
|
||||
me.get('email'),
|
||||
@@ -82,7 +84,7 @@ class BlenderIdSignIn(OAuthSignIn):
|
||||
|
||||
class FacebookSignIn(OAuthSignIn):
|
||||
def __init__(self):
|
||||
super(FacebookSignIn, self).__init__('facebook')
|
||||
super().__init__('facebook')
|
||||
self.service = OAuth2Service(
|
||||
name='facebook',
|
||||
client_id=self.consumer_id,
|
||||
@@ -122,7 +124,7 @@ class FacebookSignIn(OAuthSignIn):
|
||||
|
||||
class GoogleSignIn(OAuthSignIn):
|
||||
def __init__(self):
|
||||
super(GoogleSignIn, self).__init__('google')
|
||||
super().__init__('google')
|
||||
self.service = OAuth2Service(
|
||||
name='google',
|
||||
client_id=self.consumer_id,
|
||||
|
Reference in New Issue
Block a user