Skip to content

Instantly share code, notes, and snippets.

@peterkappus
Last active June 21, 2016 20:59
Show Gist options
  • Save peterkappus/4888f56f0a3bb832acc1532b3a16a880 to your computer and use it in GitHub Desktop.
Save peterkappus/4888f56f0a3bb832acc1532b3a16a880 to your computer and use it in GitHub Desktop.
A draft OmniAuth strategy for WeekDone.
#A draft OmniAuth Strategy for Weekdone
#TODO: Write some tests
#TODO: Package as a gem and submit for addition to the strategy list https://github.com/intridea/omniauth/wiki/List-of-Strategies
#See the contribution guide: https://github.com/intridea/omniauth/wiki/Strategy-Contribution-Guide
require 'omniauth-oauth2'
require 'omniauth'
module OmniAuth
module Strategies
class WeekDone < OmniAuth::Strategies::OAuth2
# Give your strategy a name.
option :name, "weekdone"
# This is where you pass the options you would pass when
# initializing your consumer from the OAuth gem.
option :client_options, {
:site => "https://weekdone.com/",
:redirect_uri =>"http://localhost:9393/auth/weekdone/callback",
:authorize_url => "https://weekdone.com/oauth_authorize",
:token_url => "https://weekdone.com/oauth_token"}
#strip out any query params
def callback_url
full_host + script_name + callback_path
end
#binding.pry
#uid{access_token.params['uid'] }
# 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
{
:name => raw_info['name'],
:email => raw_info['email']
}
end
extra do
{
'raw_info' => raw_info
}
end
def raw_info
@raw_info ||= access_token.params['user']
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment