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

#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)


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

def email_access_allowed?
  options['scope'] =~ /user/
end

#emailsObject



60
61
62
63
64
# File 'lib/omniauth/strategies/github.rb', line 60

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

#primary_emailObject



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

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

#raw_infoObject



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

def raw_info
  access_token.options[:mode] = :query
  @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