Merge branch 'oauth-upper-fix-lmao' into 'master'

Fix response url, fix Uppercase usernames breaking(?!?!)

See merge request Jafner/calibre-web!6
This commit is contained in:
Joey Hafner 2022-07-12 23:46:12 +00:00
commit 070b2c30be

View File

@ -338,7 +338,7 @@ if ub.oauth_support:
log.error("Failed to log in with generic OAuth2 provider") log.error("Failed to log in with generic OAuth2 provider")
return False return False
resp = blueprint.session.get(blueprint.base_url + oauth_ids[2].get('oauth_userinfo_url')) resp = blueprint.session.get(blueprint.base_url + oauthblueprints[2].get('oauth_userinfo_url'))
if not resp.ok: if not resp.ok:
flash(_(u"Failed to fetch user info from generic OAuth2 provider."), category="error") flash(_(u"Failed to fetch user info from generic OAuth2 provider."), category="error")
log.error("Failed to fetch user info from generic OAuth2 provider") log.error("Failed to fetch user info from generic OAuth2 provider")
@ -348,8 +348,8 @@ if ub.oauth_support:
email_mapper = oauthblueprints[2].get('email_mapper') or 'email' email_mapper = oauthblueprints[2].get('email_mapper') or 'email'
generic_info = resp.json() generic_info = resp.json()
generic_user_email = str(generic_info[email_mapper]) generic_user_email = str(generic_info[email_mapper]).lower()
generic_user_username = str(generic_info[username_mapper]) generic_user_username = str(generic_info[username_mapper]).lower()
user = ( user = (
ub.session.query(ub.User) ub.session.query(ub.User)
@ -365,10 +365,10 @@ if ub.oauth_support:
ub.session.add(user) ub.session.add(user)
ub.session_commit() ub.session_commit()
result = oauth_update_token(str(oauthblueprints[2]['id']), token, user.id) result = oauth_update_token(str(oauthblueprints[2].get('id')), token, user.id)
query = ub.session.query(ub.OAuth).filter_by( query = ub.session.query(ub.OAuth).filter_by(
provider=str(oauthblueprints[2]['id']), provider=str(oauthblueprints[2].get('id')),
provider_user_id=user.id, provider_user_id=user.id,
) )
oauth_entry = query.first() oauth_entry = query.first()
@ -476,15 +476,15 @@ def generic_login():
if not generic.session.authorized: if not generic.session.authorized:
return redirect(url_for("generic.login")) return redirect(url_for("generic.login"))
try: try:
resp = generic.session.get(generic.base_url + oauth_ids[2].get('oauth_userinfo_url')) resp = generic.session.get(generic.base_url + oauthblueprints[2].get('oauth_userinfo_url'))
if resp.ok: if resp.ok:
account_info_json = resp.json() account_info_json = resp.json()
username_mapper = oauthblueprints[2].get('username_mapper') or 'username' username_mapper = oauthblueprints[2].get('username_mapper') or 'username'
email_mapper = oauthblueprints[2].get('email_mapper') or 'email' email_mapper = oauthblueprints[2].get('email_mapper') or 'email'
email = str(account_info_json[email_mapper]) email = str(account_info_json[email_mapper]).lower()
username = str(account_info_json[username_mapper]) username = str(account_info_json[username_mapper]).lower()
user = ( user = (
ub.session.query(ub.User) ub.session.query(ub.User)
@ -492,7 +492,7 @@ def generic_login():
func.lower(ub.User.email) == email)) func.lower(ub.User.email) == email))
).first() ).first()
return bind_oauth_or_register(oauthblueprints[2]['id'], user.id, 'generic.login', 'generic') return bind_oauth_or_register(oauthblueprints[2].get('id'), user.id, 'generic.login', 'generic')
flash(_(u"generic OAuth2 error, please retry later."), category="error") flash(_(u"generic OAuth2 error, please retry later."), category="error")
log.error("generic OAuth2 error, please retry later") log.error("generic OAuth2 error, please retry later")
except (InvalidGrantError, TokenExpiredError) as e: except (InvalidGrantError, TokenExpiredError) as e:
@ -503,4 +503,4 @@ def generic_login():
@oauth.route('/unlink/generic', methods=["GET"]) @oauth.route('/unlink/generic', methods=["GET"])
@login_required @login_required
def generic_login_unlink(): def generic_login_unlink():
return unlink_oauth(oauthblueprints[2]['id']) return unlink_oauth(oauthblueprints[2].get('id'))