Class: OmniAuth::Strategies::GitHub

Inherits:
OAuth2
  • Object
show all
Defined in:
lib/omniauth/strategies/oauth2/github.rb

Overview

OAuth 2.0 based authentication with GitHub. In order to sign up for an application, you need to register an application and provide the proper credentials to this middleware.

Instance Attribute Summary

Attributes inherited from OAuth2

#client_id, #client_options, #client_secret, #options

Instance Method Summary collapse

Methods inherited from OAuth2

#callback_url, #client

Constructor Details

#initialize(app, client_id = nil, client_secret = nil, options = {}, &block) ⇒ GitHub

Returns a new instance of GitHub.

Parameters:

  • app (Rack Application)

    standard middleware application argument

  • client_id (String) (defaults to: nil)

    the application ID for your client

  • client_secret (String) (defaults to: nil)

    the application secret



13
14
15
16
17
18
19
20
# File 'lib/omniauth/strategies/oauth2/github.rb', line 13

def initialize(app, client_id=nil, client_secret=nil, options={}, &block)
  client_options = {
    :site => 'https://api.github.com',
    :authorize_url => 'https://github.com/login/oauth/authorize',
    :token_url => 'https://github.com/login/oauth/access_token'
  }
  super(app, :github, client_id, client_secret, client_options, options, &block)
end

Instance Method Details

#auth_hashObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/omniauth/strategies/oauth2/github.rb', line 22

def auth_hash
  OmniAuth::Utils.deep_merge(
    super, {
      'uid' => user_data['id'],
      'user_info' => ,
      'extra' => {
        'user_hash' => user_data,
      },
    }
  )
end

#user_dataObject



34
35
36
37
# File 'lib/omniauth/strategies/oauth2/github.rb', line 34

def user_data
  @access_token.options[:mode] = :query
  @data ||= @access_token.get('/user').parsed
end

#user_infoObject



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/omniauth/strategies/oauth2/github.rb', line 39

def 
  {
    '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