Make josh_id propagate return_to as a GET parameter, and use that GET
[arvados.git] / lib / josh_id.rb
1 require 'omniauth-oauth2'
2 module OmniAuth
3   module Strategies
4     class JoshId < OmniAuth::Strategies::OAuth2
5
6       CUSTOM_PROVIDER_URL = 'http://auth.clinicalfuture.com'
7
8       option :client_options, {
9         :site =>  CUSTOM_PROVIDER_URL,
10         :authorize_url => "#{CUSTOM_PROVIDER_URL}/auth/josh_id/authorize",
11         :access_token_url => "#{CUSTOM_PROVIDER_URL}/auth/josh_id/access_token"
12       }
13
14       uid { raw_info['id'] }
15
16       info do
17         {
18           :first_name => raw_info['info']['first_name'],
19           :last_name => raw_info['info']['last_name'],
20           :email => raw_info['info']['email'],
21           :identity_url => raw_info['info']['identity_url'],
22         }
23       end
24
25       extra do
26         {
27           'raw_info' => raw_info
28         }
29       end
30       
31       def callback_url
32         full_host + script_name + callback_path + query_string
33       end
34
35       def raw_info
36         @raw_info ||= access_token.get("/auth/josh_id/user.json?oauth_token=#{access_token.token}").parsed
37       end
38     end 
39   end
40 end