Class: OmniAuth::Strategies::CodeSchool

Inherits:
OAuth2
  • Object
show all
Defined in:
lib/oa-codeschool.rb

Overview

Authenticate to Code School with OAuth 2.0 and retrieve basic user information.

Examples:

Basic Usage

use OmniAuth::Strategies::CodeSchool, 'client_id', 'client_secret'

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of CodeSchool.

Parameters:

  • app (Rack Application)

    standard middleware application parameter

  • client_id (String) (defaults to: nil)

    the application id as [registered on Facebook](www.facebook.com/developers/)

  • client_secret (String) (defaults to: nil)

    the application secret as registered on Facebook

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :scope (String) — default: 'email,offline_access'

    comma-separated extended permissions such as ‘email` and `manage_pages`



21
22
23
24
25
26
27
# File 'lib/oa-codeschool.rb', line 21

def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
  super(app, :code_school, client_id, client_secret, {
    :site => self.class.base_uri.presence || "http://localhost:3000",
    :authorize_url => "/oauth2/authorize",
    :token_url => "/oauth2/token"
  }, options, &block)
end

Instance Method Details

#auth_hashObject



57
58
59
60
61
62
63
# File 'lib/oa-codeschool.rb', line 57

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

#callback_phaseObject



34
35
36
37
# File 'lib/oa-codeschool.rb', line 34

def callback_phase
  options[:grant_type] ||= 'authorization_code'
  super
end

#clientObject

memoize the client or else setting up Faraday stubs does not work



44
45
46
# File 'lib/oa-codeschool.rb', line 44

def client
  @_client ||= super
end

#request_phaseObject



29
30
31
32
# File 'lib/oa-codeschool.rb', line 29

def request_phase
  options[:response_type] ||= "code"
  super
end

#user_dataObject



39
40
41
# File 'lib/oa-codeschool.rb', line 39

def user_data
  @data ||= @access_token.get('/api/v2/user.json').parsed['user']
end

#user_infoObject



48
49
50
51
52
53
54
55
# File 'lib/oa-codeschool.rb', line 48

def 
  {
    'nickname' => user_data["username"],
    'email' => user_data["email"],
    'name' => user_data['name'],
    'image' => user_data['avatar']
  }
end