Update libraries

Update for Python 3.8
Migrate from Flask-OAuthlib to Authlib
This commit is contained in:
RunasSudo 2020-07-11 17:59:05 +10:00
parent da24cc4f63
commit 2c15f443f8
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
2 changed files with 20 additions and 23 deletions

View File

@ -14,7 +14,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from flask_oauthlib.client import OAuth
from authlib.integrations.flask_client import OAuth
import flask
@ -27,51 +27,48 @@ blueprint = flask.Blueprint('eosweb.redditauth', __name__)
app = None
oauth = None
reddit = None
@blueprint.record
def reddit_register(setup_state):
global app, oauth, reddit
global app, oauth
app = setup_state.app
oauth = OAuth()
reddit = oauth.remote_app('Reddit',
request_token_url=None,
oauth = OAuth(app)
oauth.register('reddit',
#request_token_url=None,
authorize_url='https://www.reddit.com/api/v1/authorize.compact',
request_token_params={'duration': 'temporary', 'scope': 'identity'},
authorize_params={'duration': 'temporary', 'scope': 'identity'},
access_token_url='https://www.reddit.com/api/v1/access_token',
access_token_method='POST',
access_token_headers={
'Authorization': 'Basic ' + base64.b64encode('{}:{}'.format(app.config['REDDIT_OAUTH_CLIENT_ID'], app.config['REDDIT_OAUTH_CLIENT_SECRET']).encode('ascii')).decode('ascii'),
'User-Agent': app.config['REDDIT_USER_AGENT']
},
consumer_key=app.config['REDDIT_OAUTH_CLIENT_ID'],
consumer_secret=app.config['REDDIT_OAUTH_CLIENT_SECRET']
client_id=app.config['REDDIT_OAUTH_CLIENT_ID'],
client_secret=app.config['REDDIT_OAUTH_CLIENT_SECRET'],
fetch_token=lambda: flask.session.get('user').oauth_token
)
@reddit.tokengetter
def get_reddit_oauth_token():
return (flask.session.get('user').oauth_token, '')
@blueprint.route('/auth/reddit/login')
def reddit_login():
return reddit.authorize(callback=app.config['BASE_URI'] + flask.url_for('eosweb.redditauth.reddit_oauth_authorized'), state=uuid.uuid4())
return oauth.reddit.authorize_redirect(redirect_uri=app.config['BASE_URI'] + flask.url_for('eosweb.redditauth.reddit_oauth_authorized'), state=str(uuid.uuid4()))
@blueprint.route('/auth/reddit/oauth_callback')
def reddit_oauth_authorized():
resp = reddit.authorized_response()
if resp is None:
try:
token = oauth.reddit.authorize_access_token()
except:
# Request denied
return flask.redirect(flask.url_for('login_cancelled'))
user = RedditUser()
user.oauth_token = resp['access_token']
user.oauth_token = token
flask.session['user'] = user
me = reddit.get('https://oauth.reddit.com/api/v1/me', headers={
me = oauth.reddit.get('https://oauth.reddit.com/api/v1/me', headers={
'User-Agent': app.config['REDDIT_USER_AGENT']
})
user.username = me.data['name']
user.username = me.json()['name']
return flask.redirect(flask.url_for('login_complete'))

View File

@ -1,16 +1,16 @@
Authlib==0.14.3
coverage==4.4.1
Flask==0.12.2
Flask-Mail==0.9.1
Flask-OAuthlib==0.9.4
flask-paginate==0.7.0
Flask-Session==0.3.1
Flask-SQLAlchemy==2.3.2
gunicorn==19.7.1
libsass==0.13.4
oauthlib==2.1.0
premailer==3.1.1
psycopg2==2.7.3.2
psycopg2==2.8.5
PyExecJS==1.4.1
pymongo==3.5.1
pymongo[srv]==3.10.1
pyRCV==0.3
pytz==2017.3
timeago==1.0.8