Skip to content

Instantly share code, notes, and snippets.

@aaronchi
Created July 15, 2014 20:36
Show Gist options
  • Save aaronchi/ff90c2376a7ae614c6be to your computer and use it in GitHub Desktop.
Save aaronchi/ff90c2376a7ae614c6be to your computer and use it in GitHub Desktop.
require 'omniauth-oauth2'
module OmniAuth
module Strategies
class Smartsheet < OmniAuth::Strategies::OAuth2
# Give your strategy a name.
option :name, "smartsheet"
# This is where you pass the options you would pass when
# initializing your consumer from the OAuth gem.
option :client_options, {
:site => "https://api.smartsheet.com/1.1",
:authorize_url => "https://www.smartsheet.com/b/authorize",
:token_url => "https://api.smartsheet.com/1.1/token"
}
# These are called after authentication has succeeded. If
# possible, you should try to set the UID without making
# additional calls (if the user id is returned with the token
# or as a URI parameter). This may not be possible with all
# providers.
uid{ raw_info['id'] }
info do
{
:first_name => raw_info['firstName'],
:last_name => raw_info['lastName'],
:email => raw_info['email']
}
end
extra do
{
'raw_info' => raw_info
}
end
def raw_info
@raw_info ||= access_token.get('user/me').parsed
end
protected
def build_access_token
verifier = request.params['code']
params = token_params.to_hash(:symbolize_keys => true).merge(:hash => Digest::SHA256.hexdigest(options.client_secret+'|'+verifier))
client.auth_code.get_token(verifier, {:redirect_uri => callback_url}.merge(params), deep_symbolize(options.auth_token_params))
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment