Sha256: ec4a3cc71da2cc901e2614629aeefd73b8e1cce48f6dc54ecf5ee42e7646c3fb

Contents?: true

Size: 1.61 KB

Versions: 10

Compression:

Stored size: 1.61 KB

Contents

require 'omniauth/oauth'
require 'multi_json'

module OmniAuth
  module Strategies
    # OAuth 2.0 based authentication with GitHub. In order to 
    # sign up for an application, you need to [register an application](http://github.com/account/applications/new)
    # and provide the proper credentials to this middleware.
    class GitHub < OAuth2
      # @param [Rack Application] app standard middleware application argument
      # @param [String] client_id the application ID for your client
      # @param [String] client_secret the application secret
      def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
        client_options = {
          :site => 'https://github.com/',
          :authorize_path => '/login/oauth/authorize',
          :access_token_path => '/login/oauth/access_token'
        }
        
        super(app, :github, client_id, client_secret, client_options, options, &block)
      end
      
      protected
      
      def user_data
        @data ||= MultiJson.decode(@access_token.get('/api/v2/json/user/show'))['user']
      end
      
      def user_info
        {
          'nickname' => user_data["login"],
          'email' => user_data['email'],
          'name' => user_data['name'],
          'urls' => {
            'GitHub' => "http://github.com/#{user_data['login']}",
            'Blog' => user_data["blog"],
          }
        }
      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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
oa-oauth-0.2.4 lib/omniauth/strategies/github.rb
oa-oauth-0.2.3 lib/omniauth/strategies/github.rb
oa-oauth-0.2.2 lib/omniauth/strategies/github.rb
oa-oauth-0.2.1 lib/omniauth/strategies/github.rb
oa-oauth-0.2.0 lib/omniauth/strategies/github.rb
oa-oauth-0.2.0.beta5 lib/omniauth/strategies/github.rb
oa-oauth-0.2.0.beta4 lib/omniauth/strategies/github.rb
oa-oauth-0.2.0.beta3 lib/omniauth/strategies/github.rb
oa-oauth-0.2.0.beta2 lib/omniauth/strategies/github.rb
oa-oauth-0.2.0.beta1 lib/omniauth/strategies/github.rb