Created
          October 11, 2011 16:58 
        
      - 
      
 - 
        
Save vshvedov/1278675 to your computer and use it in GitHub Desktop.  
    ID.NET OmniAuth Strategy
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | require 'omniauth/oauth' | |
| require 'multi_json' | |
| module OmniAuth | |
| module Strategies | |
| class IdNet < OmniAuth::Strategies::OAuth2 | |
| def initialize(app, api_key = nil, secret_key = nil, options = {}, &block) | |
| client_options = { | |
| :site => IDNET_PROVIDER_URL, | |
| :authorize_url => "#{IDNET_PROVIDER_URL}/oauth/authorize", | |
| :access_token_url => "#{IDNET_PROVIDER_URL}/oauth/token" | |
| } | |
| super(app, :id_net, api_key, secret_key, client_options, &block) | |
| end | |
| protected | |
| def user_data | |
| @data ||= MultiJson.decode(@access_token.get("/api/profile").body) | |
| end | |
| def request_phase | |
| options[:response_type] ||= 'code' | |
| super | |
| end | |
| def callback_phase | |
| options[:grant_type] ||= 'authorization_code' | |
| super | |
| end | |
| def user_hash | |
| user_data | |
| end | |
| def auth_hash | |
| user_data | |
| OmniAuth::Utils.deep_merge(super, { | |
| 'pid' => user_data['pid'], | |
| 'userpic_full' => user_data['userpic_full'], | |
| 'userpic_thumb_150' => user_data['userpic_thumb_150'], | |
| 'first_name' => user_data['first_name'], | |
| 'last_name' => user_data['last_name'], | |
| 'email' => user_data['email'], | |
| 'language' => user_data['language'], | |
| 'nickname' => user_data['nickname'], | |
| 'gender' => user_data['gender'], | |
| 'street_address' => user_data['street_address'], | |
| 'city' => user_data['city'], | |
| 'country' => user_data['country'], | |
| 'state_or_province' => user_data['state_or_province'], | |
| 'zip' => user_data['zip'] | |
| }) | |
| end | |
| end | |
| end | |
| end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment