mirror of
https://github.com/omniauth/omniauth.git
synced 2022-11-09 12:31:49 -05:00
Merging a (squashed) doit.im pull request. Closes #222.
This commit is contained in:
parent
a7ac509f4c
commit
a29a5e6d1f
4 changed files with 67 additions and 0 deletions
|
@ -40,6 +40,7 @@ OmniAuth currently supports the following external providers:
|
|||
* Instagram (credit: [kiyoshi](https://github.com/kiyoshi))
|
||||
* Mixi (credit: [kiyoshi](https://github.com/kiyoshi))
|
||||
* Evernote (credit: [szimek](https://github.com/szimek))
|
||||
* Doit.im (credit: [chouti](https://github.com/chouti))
|
||||
* Flickr (credit: [pchilton](https://github.com/pchilton))
|
||||
* OpenID
|
||||
* Google Apps (via OpenID)
|
||||
|
|
|
@ -32,5 +32,6 @@ module OmniAuth
|
|||
autoload :Instagram, 'omniauth/strategies/instagram'
|
||||
autoload :Mixi, 'omniauth/strategies/mixi'
|
||||
autoload :Evernote, 'omniauth/strategies/evernote'
|
||||
autoload :Doit, 'omniauth/strategies/doit'
|
||||
end
|
||||
end
|
||||
|
|
60
oa-oauth/lib/omniauth/strategies/doit.rb
Normal file
60
oa-oauth/lib/omniauth/strategies/doit.rb
Normal file
|
@ -0,0 +1,60 @@
|
|||
require 'omniauth/oauth'
|
||||
require 'multi_json'
|
||||
|
||||
module OmniAuth
|
||||
module Strategies
|
||||
class Doit < OAuth2
|
||||
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
||||
client_options = {
|
||||
:site => 'https://openapi.doit.im',
|
||||
:authorize_url => 'https://openapi.doit.im/oauth/authorize',
|
||||
:access_token_url => 'https://openapi.doit.im/oauth/access_token'
|
||||
}
|
||||
|
||||
super(app, :doit, consumer_key, consumer_secret, client_options, options, &block)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def user_data
|
||||
@data ||= MultiJson.decode(@access_token.get(client.site+"/v1/settings"),{'Authorization'=> 'OAuth'+@access_token.token})
|
||||
end
|
||||
|
||||
def request_phase
|
||||
options[:response_type] ||= "code"
|
||||
super
|
||||
end
|
||||
|
||||
def callback_phase
|
||||
options[:grant_type] ||= 'authorization_code'
|
||||
super
|
||||
end
|
||||
|
||||
def user_info
|
||||
{
|
||||
'account' => user_data['account'],
|
||||
'username'=> user_data['username'],
|
||||
'nickname'=> user_data['nickname'],
|
||||
'gender'=> user_data['gender'],
|
||||
'week_start'=> user_data['week_start'],
|
||||
'birthday_day'=> user_data['birthday_day'],
|
||||
'birthday_month'=> user_data['birthday_month'],
|
||||
'birthday_year'=> user_data['birthday_year'],
|
||||
'language'=> user_data['language'],
|
||||
'user_timezone'=> user_data['user_timezone'],
|
||||
'remind_email'=> user_data['remind_email'],
|
||||
'created'=> user_data['created'],
|
||||
'updated'=> user_data['updated']
|
||||
}
|
||||
end
|
||||
|
||||
def auth_hash
|
||||
OmniAuth::Utils.deep_merge(super, {
|
||||
'uid' => user_data['id'],
|
||||
'user_info' => user_info,
|
||||
'extra' => {'user_hash' => user_data}
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
5
oa-oauth/spec/omniauth/strategies/doit_spec.rb
Normal file
5
oa-oauth/spec/omniauth/strategies/doit_spec.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe OmniAuth::Strategies::Doit do
|
||||
it_should_behave_like "an oauth2 strategy"
|
||||
end
|
Loading…
Reference in a new issue