Class: OmniAuth::Strategies::CodeSchool

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

Overview

Authenticate to Code School utilizing 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`



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

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

Instance Method Details

#auth_hashObject



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

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

#callback_phaseObject



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

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

#clientObject

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



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

def client
  @_client ||= super
end

#request_phaseObject



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

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

#user_dataObject



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

def user_data
  @data ||= MultiJson.decode(@access_token.get('/api/v1/user.json', {}, {}))['user']
end

#user_infoObject



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

def 
  {
    'nickname' => user_data["twitter_name"],
    'email' => (user_data["email"] if user_data["email"]),
    'first_name' => user_data["name"].split(" ").first,
    'last_name' => user_data["name"].split(" ").last,
    'name' => user_data['name']
  }
end