· 7 years ago · Aug 15, 2018, 05:56 AM
1require 'omniauth/oauth'
2require 'multi_json'
3
4module OmniAuth
5 module Strategies
6 class IdNet < OmniAuth::Strategies::OAuth2
7
8 def initialize(app, api_key = nil, secret_key = nil, options = {}, &block)
9 client_options = {
10 :site => IDNET_PROVIDER_URL,
11 :authorize_url => "#{IDNET_PROVIDER_URL}/oauth/authorize",
12 :access_token_url => "#{IDNET_PROVIDER_URL}/oauth/token"
13 }
14 super(app, :id_net, api_key, secret_key, client_options, &block)
15 end
16
17protected
18
19 def user_data
20 @data ||= MultiJson.decode(@access_token.get("/api/profile").body)
21 end
22
23 def request_phase
24 options[:response_type] ||= 'code'
25 super
26 end
27
28 def callback_phase
29 options[:grant_type] ||= 'authorization_code'
30 super
31 end
32
33 def user_hash
34 user_data
35 end
36
37 def auth_hash
38 user_data
39 OmniAuth::Utils.deep_merge(super, {
40 'pid' => user_data['pid'],
41 'userpic_full' => user_data['userpic_full'],
42 'userpic_thumb_150' => user_data['userpic_thumb_150'],
43 'first_name' => user_data['first_name'],
44 'last_name' => user_data['last_name'],
45 'email' => user_data['email'],
46 'language' => user_data['language'],
47 'nickname' => user_data['nickname'],
48 'gender' => user_data['gender'],
49 'street_address' => user_data['street_address'],
50 'city' => user_data['city'],
51 'country' => user_data['country'],
52 'state_or_province' => user_data['state_or_province'],
53 'zip' => user_data['zip']
54 })
55 end
56 end
57 end
58end