From 6ac0381bffcb468968c9d7c06bd3db89012fb917 Mon Sep 17 00:00:00 2001 From: Michael Deering Date: Sat, 12 May 2018 10:26:45 -0600 Subject: [PATCH 1/6] Update required arguments for v3 and make url dynamic based on options --- .../omniauth-surveymonkey/version.rb | 2 +- .../omniauth/strategies/surveymonkey.rb | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/omniauth-surveymonkey/omniauth-surveymonkey/version.rb b/lib/omniauth-surveymonkey/omniauth-surveymonkey/version.rb index e64db7f..ebf55ea 100644 --- a/lib/omniauth-surveymonkey/omniauth-surveymonkey/version.rb +++ b/lib/omniauth-surveymonkey/omniauth-surveymonkey/version.rb @@ -1,5 +1,5 @@ module OmniAuth module SurveyMonkey - VERSION = '2.0.1' + VERSION = '3.0.0' end end diff --git a/lib/omniauth-surveymonkey/omniauth/strategies/surveymonkey.rb b/lib/omniauth-surveymonkey/omniauth/strategies/surveymonkey.rb index 47db1cc..0d45e37 100644 --- a/lib/omniauth-surveymonkey/omniauth/strategies/surveymonkey.rb +++ b/lib/omniauth-surveymonkey/omniauth/strategies/surveymonkey.rb @@ -6,10 +6,10 @@ class SurveyMonkey configure url: 'https://www.surveymonkey.com/oauth/authorize' - args [:client_id, :api_key, :client_secret] + args [:client_id, :client_secret] def request_phase - hash = { client_id: options.client_id, api_key: options.api_key, redirect_uri: callback_url, response_type: 'code' } + hash = { client_id: options.client_id, api_key: options.api_key, redirect_uri: callback_url, response_type: 'code' }.compact redirect "#{options.url}?#{hash.to_query}" end @@ -28,8 +28,9 @@ def callback_phase grant_type: 'authorization_code' } - response = connection.post "/oauth/token?api_key=#{options.api_key}", form_fields + response = connection.post "/oauth/token#{"?api_key=#{options.api_key}" if options.api_key}", form_fields json = ::MultiJson.load response.body + options.access_token = json['access_token'] if options.access_token @@ -37,13 +38,14 @@ def callback_phase info = connection.get "/v3/users/me?api_key=#{options.api_key}" json = ::MultiJson.load info.body - options.username = json['username'] - options.first_name = json['first_name'] - options.last_name = json['last_name'] options.account_type = json['account_type'] - options.language = json['language'] options.email = json['email'] + options.email_verified = json['email_verified'] + options.first_name = json['first_name'] options.surveymonkey_id = json['id'].to_i + options.language = json['language'] + options.last_name = json['last_name'] + options.username = json['username'] end super @@ -56,11 +58,12 @@ def callback_phase info do { account_type: options.account_type, + email: options.email + email_verified: options.email_verified first_name: options.first_name, last_name: options.last_name, username: options.username, language: options.language, - email: options.email } end From 527e6ce68dd28367cb82edb802f40a8f3d193e43 Mon Sep 17 00:00:00 2001 From: Michael Deering Date: Sat, 12 May 2018 10:36:19 -0600 Subject: [PATCH 2/6] Missing commas after cleanup. --- .../omniauth/strategies/surveymonkey.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/omniauth-surveymonkey/omniauth/strategies/surveymonkey.rb b/lib/omniauth-surveymonkey/omniauth/strategies/surveymonkey.rb index 0d45e37..b257ba1 100644 --- a/lib/omniauth-surveymonkey/omniauth/strategies/surveymonkey.rb +++ b/lib/omniauth-surveymonkey/omniauth/strategies/surveymonkey.rb @@ -58,12 +58,12 @@ def callback_phase info do { account_type: options.account_type, - email: options.email - email_verified: options.email_verified + email: options.email, + email_verified: options.email_verified, first_name: options.first_name, last_name: options.last_name, username: options.username, - language: options.language, + language: options.language } end From a58ac9dc9e808e501bbbab1cc6405058b441602c Mon Sep 17 00:00:00 2001 From: Michael Deering Date: Sat, 12 May 2018 10:54:41 -0600 Subject: [PATCH 3/6] Update readme for argument changes. --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a40391b..277f6c0 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,9 @@ This is the official OmniAuth strategy for authenticating to SurveyMonkey's v3 A ## Basic Usage ``` Rails.application.config.middleware.use OmniAuth::Builder do - provider :surveymonkey, ENV['SURVEYMONKEY_CLIENT_ID'], ENV['SURVEYMONKEY_API_KEY'], ENV['SURVEYMONKEY_SECRET'] + provider :surveymonkey, ENV['SURVEYMONKEY_CLIENT_ID'], ENV['SURVEYMONKEY_SECRET'] + # If you have an older application that supplies an API_KEY it can still be used with this version of the gem + # provider :surveymonkey, ENV['SURVEYMONKEY_CLIENT_ID'], ENV['SURVEYMONKEY_SECRET'], api_key: ENV['SURVEYMONKEY_API_KEY'] end ``` From 8771640692e4e6fe26ee53c9ba05bfaa3444592c Mon Sep 17 00:00:00 2001 From: Michael Deering Date: Tue, 17 Jul 2018 16:06:49 -0600 Subject: [PATCH 4/6] Add scopes to info hash. --- .../omniauth/strategies/surveymonkey.rb | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/omniauth-surveymonkey/omniauth/strategies/surveymonkey.rb b/lib/omniauth-surveymonkey/omniauth/strategies/surveymonkey.rb index b257ba1..1c81bda 100644 --- a/lib/omniauth-surveymonkey/omniauth/strategies/surveymonkey.rb +++ b/lib/omniauth-surveymonkey/omniauth/strategies/surveymonkey.rb @@ -35,7 +35,7 @@ def callback_phase if options.access_token connection.authorization :Bearer, options.access_token - info = connection.get "/v3/users/me?api_key=#{options.api_key}" + info = connection.get "/v3/users/me#{"?api_key=#{options.api_key}" if options.api_key}" json = ::MultiJson.load info.body options.account_type = json['account_type'] @@ -46,6 +46,7 @@ def callback_phase options.language = json['language'] options.last_name = json['last_name'] options.username = json['username'] + options.scopes = json['scopes'] end super @@ -57,13 +58,15 @@ def callback_phase info do { - account_type: options.account_type, - email: options.email, - email_verified: options.email_verified, - first_name: options.first_name, - last_name: options.last_name, - username: options.username, - language: options.language + account_type: options.account_type, + available_scopes: options.scopes['available'], + email: options.email, + email_verified: options.email_verified, + first_name: options.first_name, + granted_scopes: options.scopes['granted'], + last_name: options.last_name, + username: options.username, + language: options.language } end From 466d0720eec0ab2a285837be908accef0a26c120 Mon Sep 17 00:00:00 2001 From: Michael Deering Date: Thu, 19 Jul 2018 14:46:40 -0600 Subject: [PATCH 5/6] Fixes cases where a user denies access to the OAuth application --- lib/omniauth-surveymonkey/omniauth/strategies/surveymonkey.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/omniauth-surveymonkey/omniauth/strategies/surveymonkey.rb b/lib/omniauth-surveymonkey/omniauth/strategies/surveymonkey.rb index 1c81bda..acde74b 100644 --- a/lib/omniauth-surveymonkey/omniauth/strategies/surveymonkey.rb +++ b/lib/omniauth-surveymonkey/omniauth/strategies/surveymonkey.rb @@ -59,11 +59,11 @@ def callback_phase info do { account_type: options.account_type, - available_scopes: options.scopes['available'], + available_scopes: options.scopes&.available, email: options.email, email_verified: options.email_verified, first_name: options.first_name, - granted_scopes: options.scopes['granted'], + granted_scopes: options.scopes&.granted, last_name: options.last_name, username: options.username, language: options.language From bcd0d98cf483e5cd06e42e65d83149599a89dcfe Mon Sep 17 00:00:00 2001 From: Michael Deering Date: Wed, 12 Aug 2020 14:11:09 -0600 Subject: [PATCH 6/6] Pass all previously droped information at the time this update --- .../omniauth/strategies/surveymonkey.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/omniauth-surveymonkey/omniauth/strategies/surveymonkey.rb b/lib/omniauth-surveymonkey/omniauth/strategies/surveymonkey.rb index acde74b..fa8c3da 100644 --- a/lib/omniauth-surveymonkey/omniauth/strategies/surveymonkey.rb +++ b/lib/omniauth-surveymonkey/omniauth/strategies/surveymonkey.rb @@ -39,6 +39,8 @@ def callback_phase json = ::MultiJson.load info.body options.account_type = json['account_type'] + options.date_created = json['date_created'] + options.date_last_login = json['date_last_login'] options.email = json['email'] options.email_verified = json['email_verified'] options.first_name = json['first_name'] @@ -47,6 +49,7 @@ def callback_phase options.last_name = json['last_name'] options.username = json['username'] options.scopes = json['scopes'] + options.sso_connections = json['sso_connections'] end super @@ -60,13 +63,16 @@ def callback_phase { account_type: options.account_type, available_scopes: options.scopes&.available, + date_created: options.date_created, + date_last_login: options.date_last_login, email: options.email, email_verified: options.email_verified, first_name: options.first_name, granted_scopes: options.scopes&.granted, last_name: options.last_name, - username: options.username, - language: options.language + language: options.language, + sso_connections: options.sso_connections, + username: options.username } end