From 04ef6494de4f1e0d7f34680c1ddf9bfe4cef8f0a Mon Sep 17 00:00:00 2001 From: Blake Erickson Date: Fri, 25 May 2018 15:35:52 -0600 Subject: [PATCH] Add support for scope and add some missing translations See this post on meta about the need for the ability to request a custom scope: https://meta.discourse.org/t/oauth2-basic-support/33879/116?u=blake --- config/locales/server.en.yml | 3 +++ config/settings.yml | 1 + plugin.rb | 3 +++ 3 files changed, 7 insertions(+) diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index d6fd81b..1d9a88a 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -12,8 +12,11 @@ en: oauth2_json_username_path: 'Path in the OAuth2 User JSON to the username. eg: user.username' oauth2_json_name_path: "Path in the OAuth2 User JSON to the user's full: user.name.full" oauth2_json_email_path: "Path in the OAuth2 User JSON to the user's email: user.email.primary" + oauth2_json_avatar_path: "Path in the Oauth2 User JSON to the user's avatar: user.avatar_url" oauth2_email_verified: "Check this if the OAuth2 site has verified the email" oauth2_send_auth_header: "Send the token as an HTTP Authorization header" oauth2_debug_auth: "Include rich debugging information in your logs" oauth2_authorize_options: "When authorizing request these options" + oauth2_scope: "When authorizing request this scope" + oauth2_button_title: "The text for the OAuth2 button" diff --git a/config/settings.yml b/config/settings.yml index c83e826..29f27d8 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -30,6 +30,7 @@ login: oauth2_authorize_options: default: 'scope' type: list + oauth2_scope: '' oauth2_button_title: default: 'with OAuth2' client: true diff --git a/plugin.rb b/plugin.rb index 10b3d4b..e7dfe70 100644 --- a/plugin.rb +++ b/plugin.rb @@ -40,6 +40,9 @@ class OAuth2BasicAuthenticator < ::Auth::OAuth2Authenticator if SiteSetting.oauth2_send_auth_header? opts[:token_params] = { headers: { 'Authorization' => basic_auth_header } } end + unless SiteSetting.oauth2_scope.blank? + opts[:scope] = SiteSetting.oauth2_scope + end } end