use Flask Dance instead of deprecated flask-oauthlib

This commit is contained in:
Henning Jacobs
2019-03-22 22:12:13 +01:00
parent 2dd4f437b8
commit a897aa7494
4 changed files with 198 additions and 259 deletions

View File

@@ -1,32 +1,20 @@
import os
from flask_oauthlib.client import OAuthRemoteApp
from flask_dance.consumer import OAuth2ConsumerBlueprint
CREDENTIALS_DIR = os.getenv('CREDENTIALS_DIR', '')
class OAuthRemoteAppWithRefresh(OAuthRemoteApp):
'''Same as flask_oauthlib.client.OAuthRemoteApp, but always loads client credentials from file.'''
def __init__(self, oauth, name, **kwargs):
# constructor expects some values, so make it happy..
kwargs['consumer_key'] = 'not-needed-here'
kwargs['consumer_secret'] = 'not-needed-here'
OAuthRemoteApp.__init__(self, oauth, name, **kwargs)
class OAuth2ConsumerBlueprintWithClientRefresh(OAuth2ConsumerBlueprint):
'''Same as flask_dance.consumer.OAuth2ConsumerBlueprint, but loads client credentials from file'''
def refresh_credentials(self):
with open(os.path.join(CREDENTIALS_DIR, 'authcode-client-id')) as fd:
self._consumer_key = fd.read().strip()
self.client_id = fd.read().strip()
with open(os.path.join(CREDENTIALS_DIR, 'authcode-client-secret')) as fd:
self._consumer_secret = fd.read().strip()
self.client_secret = fd.read().strip()
@property
def consumer_key(self):
def login(self):
self.refresh_credentials()
return self._consumer_key
@property
def consumer_secrect(self):
self.refresh_credentials()
return self._consumer_secret
return super()