From 655f5271c9a3c6e79956b0ba56ba1a1a110fdae7 Mon Sep 17 00:00:00 2001 From: Joe Pickert Date: Thu, 15 Dec 2022 16:33:38 -0600 Subject: [PATCH 1/2] Issue-394: Add disable_provider_selection kwarg to Api.authentication_url We need the option to disable the "Select different provider" button in Nylas' hosted auth when we are trying to authenticate against a specific provider. This is necessary to prevent our users from escaping the intended auth flow and selecting a provider that we do not support. This commit addresses this need by adding and optional keyword argument to the Api.authentication_url method and, if it is provided, including it in the params payload appended on the call to the /oauth/authorize endpoint. Tests have been added to account for this change and I tested it locally to confirm that the "Select different provider" button was no longer visible when I included disable_provider_selection: true in my call to the authentication_url method. --- lib/nylas/api.rb | 3 ++- spec/nylas/api_spec.rb | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/nylas/api.rb b/lib/nylas/api.rb index 3ee5df84..f726cf1a 100644 --- a/lib/nylas/api.rb +++ b/lib/nylas/api.rb @@ -36,7 +36,7 @@ def authenticate(name:, email_address:, provider:, settings:, reauth_account_id: end def authentication_url(redirect_uri:, scopes:, response_type: "code", login_hint: nil, state: nil, - provider: nil, redirect_on_error: nil) + provider: nil, redirect_on_error: nil, disable_provider_selection: nil) params = { client_id: app_id, redirect_uri: redirect_uri, @@ -48,6 +48,7 @@ def authentication_url(redirect_uri:, scopes:, response_type: "code", login_hint params[:scopes] = scopes.join(",") if scopes params[:provider] = provider if provider params[:redirect_on_error] = redirect_on_error if redirect_on_error + params[:disable_provider_selection] = disable_provider_selection if disable_provider_selection "#{api_server}/oauth/authorize?#{URI.encode_www_form(params)}" end diff --git a/spec/nylas/api_spec.rb b/spec/nylas/api_spec.rb index e57e8d2b..ee96885f 100644 --- a/spec/nylas/api_spec.rb +++ b/spec/nylas/api_spec.rb @@ -82,7 +82,8 @@ login_hint: "email@example.com", state: "some-state", provider: "gmail", - redirect_on_error: true + redirect_on_error: true, + disable_provider_selection: true ) expected_url = "https://api.nylas.com/oauth/authorize"\ @@ -93,7 +94,8 @@ "&state=some-state"\ "&scopes=email%2Ccalendar"\ "&provider=gmail"\ - "&redirect_on_error=true" + "&redirect_on_error=true"\ + "&disable_provider_selection=true" expect(hosted_auth_url).to eq expected_url end end From 3226339c6ae3ca2a9e0c221c7839aa917855c95b Mon Sep 17 00:00:00 2001 From: Mostafa Rashed <17770919+mrashed-dev@users.noreply.github.com> Date: Fri, 16 Dec 2022 09:27:25 -0500 Subject: [PATCH 2/2] Fix Rubocop linter complaint MethodTooLong --- lib/nylas/api.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/nylas/api.rb b/lib/nylas/api.rb index f726cf1a..be2d4bcc 100644 --- a/lib/nylas/api.rb +++ b/lib/nylas/api.rb @@ -37,12 +37,8 @@ def authenticate(name:, email_address:, provider:, settings:, reauth_account_id: def authentication_url(redirect_uri:, scopes:, response_type: "code", login_hint: nil, state: nil, provider: nil, redirect_on_error: nil, disable_provider_selection: nil) - params = { - client_id: app_id, - redirect_uri: redirect_uri, - response_type: response_type, - login_hint: login_hint - } + params = { client_id: app_id, redirect_uri: redirect_uri, response_type: response_type, + login_hint: login_hint } params[:state] = state if state params[:scopes] = scopes.join(",") if scopes