Class: OmniAuth::Strategies::GitHub

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

Instance Method Summary collapse

Instance Method Details

#authorize_paramsObject



16
17
18
19
20
21
22
23
24
# File 'lib/omniauth/strategies/github.rb', line 16

def authorize_params
  super.tap do |params|
    %w[scope client_options].each do |v|
      if request.params[v]
        params[v.to_sym] = request.params[v]
      end
    end
  end
end

#callback_urlObject



77
78
79
# File 'lib/omniauth/strategies/github.rb', line 77

def callback_url
  full_host + callback_path
end

#emailObject



50
51
52
# File 'lib/omniauth/strategies/github.rb', line 50

def email
  (email_access_allowed?) ? primary_email : raw_info['email']
end

#email_access_allowed?Boolean

Returns:

  • (Boolean)


70
71
72
73
74
75
# File 'lib/omniauth/strategies/github.rb', line 70

def email_access_allowed?
  return false unless options['scope']
  email_scopes = ['user', 'user:email']
  scopes = options['scope'].split(',')
  (scopes & email_scopes).any?
end

#emailsObject



64
65
66
67
68
# File 'lib/omniauth/strategies/github.rb', line 64

def emails
  return [] unless email_access_allowed?
  access_token.options[:mode] = :header
  @emails ||= access_token.get('user/emails', :headers => { 'Accept' => 'application/vnd.github.v3' }).parsed
end

#primary_emailObject



58
59
60
61
# File 'lib/omniauth/strategies/github.rb', line 58

def primary_email
  primary = emails.find{ |i| i['primary'] && i['verified'] }
  primary && primary['email'] || nil
end

#raw_infoObject



45
46
47
48
# File 'lib/omniauth/strategies/github.rb', line 45

def raw_info
  access_token.options[:mode] = :header
  @raw_info ||= access_token.get('user').parsed
end

#request_phaseObject



12
13
14
# File 'lib/omniauth/strategies/github.rb', line 12

def request_phase
  super
end

#scopeObject



54
55
56
# File 'lib/omniauth/strategies/github.rb', line 54

def scope
  access_token['scope']
end