Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.0 gem release #4

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
2 changes: 1 addition & 1 deletion lib/omniauth-surveymonkey/omniauth-surveymonkey/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module OmniAuth
module SurveyMonkey
VERSION = '2.0.1'
VERSION = '3.0.0'
end
end
40 changes: 26 additions & 14 deletions lib/omniauth-surveymonkey/omniauth/strategies/surveymonkey.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -28,22 +28,28 @@ 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
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.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.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']
options.surveymonkey_id = json['id'].to_i
options.language = json['language']
options.last_name = json['last_name']
options.username = json['username']
options.scopes = json['scopes']
options.sso_connections = json['sso_connections']
end

super
Expand All @@ -55,12 +61,18 @@ def callback_phase

info do
{
account_type: options.account_type,
first_name: options.first_name,
last_name: options.last_name,
username: options.username,
language: options.language,
email: options.email
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,
language: options.language,
sso_connections: options.sso_connections,
username: options.username
}
end

Expand Down