Merge branch 'Oauth-userid-config-add' into 'master'

Update cps/admin.py, cps/oauth_bb.py, cps/templates/config_edit.html, cps/ub.py

See merge request Jafner/calibre-web!1
This commit is contained in:
Joey Hafner 2022-07-12 05:41:22 +00:00
commit 32bc911de4
4 changed files with 12 additions and 3 deletions

View File

@ -1120,6 +1120,7 @@ def _configuration_oauth_helper(to_save):
"oauth_base_url": to_save["config_" + str(element['id']) + "_oauth_base_url"],
"oauth_auth_url": to_save["config_" + str(element['id']) + "_oauth_auth_url"],
"oauth_token_url": to_save["config_" + str(element['id']) + "_oauth_token_url"],
"oauth_userinfo_url": to_save["config_" + str(element['id']) + "oauth_userinfo_url"],
"username_mapper": to_save["config_" + str(element['id']) + "_username_mapper"],
"email_mapper": to_save["config_" + str(element['id']) + "_email_mapper"],
"login_button": to_save["config_" + str(element['id']) + "_login_button"],

View File

@ -243,6 +243,7 @@ def generate_oauth_blueprints():
oauth_base_url=oauth_ids[2].oauth_base_url,
oauth_auth_url=oauth_ids[2].oauth_auth_url,
oauth_token_url=oauth_ids[2].oauth_token_url,
oauth_userinfo_url=oauth_ids[2].oauth_userinfo_url,
username_mapper=oauth_ids[2].username_mapper,
email_mapper=oauth_ids[2].email_mapper,
login_button=oauth_ids[2].login_button)
@ -336,8 +337,8 @@ if ub.oauth_support:
flash(_(u"Failed to log in with generic OAuth provider."), category="error")
log.error("Failed to log in with generic OAuth2 provider")
return False
resp = blueprint.session.get(blueprint.base_url + "/application/o/userinfo")
resp = blueprint.session.get(blueprint.base_url + oauth_ids[2].get('oauth_userinfo_url'))
if not resp.ok:
flash(_(u"Failed to fetch user info from generic OAuth2 provider."), category="error")
log.error("Failed to fetch user info from generic OAuth2 provider")
@ -475,7 +476,7 @@ def generic_login():
if not generic.session.authorized:
return redirect(url_for("generic.login"))
try:
resp = generic.session.get(generic.base_url + "/application/o/userinfo/")
resp = generic.session.get(generic.base_url + oauth_ids[2].get('oauth_userinfo_url'))
if resp.ok:
account_info_json = resp.json()

View File

@ -331,6 +331,12 @@
<input type="text" class="form-control" id="config_{{ prov['id'] }}_oauth_token_url" name="config_{{ prov['id'] }}_oauth_token_url" value="{% if prov['oauth_token_url']%}{{ prov['oauth_token_url'] }}{% endif %}" autocomplete="off">
</div>
{% endif %}
{% if 'oauth_userid_url' in prov %}
<div class="form-group">
<label for="config_{{ prov['id'] }}_oauth_userid_url">{{_('%(provider)s OAuth UserID URL (relative)', provider=prov['provider_name'])}}</label>
<input type="text" class="form-control" id="config_{{ prov['id'] }}_oauth_userid_url" name="config_{{ prov['id'] }}_oauth_userid_url" value="{% if prov['oauth_userid_url']%}{{ prov['oauth_userid_url'] }}{% endif %}" autocomplete="off">
</div>
{% endif %}
{% if 'username_mapper' in prov %}
<div class="form-group">
<label for="config_{{ prov['id'] }}_username_mapper">{{_('%(provider)s OAuth Username mapper', provider=prov['provider_name'])}}</label>

View File

@ -263,6 +263,7 @@ class OAuthProvider(Base):
oauth_base_url = Column(String)
oauth_auth_url = Column(String, default="/protocol/openid-connect/auth")
oauth_token_url = Column(String, default="/protocol/openid-connect/token")
oauth_userid_url = Column(String, default="/application/o/userinfo/")
scope = Column(String, default="openid profile email")
username_mapper = Column(String, default="preferred_username")
email_mapper = Column(String, default="email")