begin require 'active_support/core_ext/class/attribute_accessors' rescue require 'active_support' end require 'omniauth/oauth' module OmniAuth module Strategies # Authenticate to Code School with OAuth 2.0 and retrieve basic user information. # # @example Basic Usage # use OmniAuth::Strategies::CodeSchool, 'client_id', 'client_secret' class CodeSchool < OAuth2 cattr_accessor :base_uri # @param [Rack Application] app standard middleware application parameter # @param [String] client_id the application id as [registered on Facebook](http://www.facebook.com/developers/) # @param [String] client_secret the application secret as registered on Facebook # @option options [String] :scope ('email,offline_access') comma-separated extended permissions such as `email` and `manage_pages` 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 def request_phase options[:response_type] ||= "code" super end def callback_phase options[:grant_type] ||= 'authorization_code' super end def user_data @data ||= @access_token.get('/api/v2/user.json').parsed['user'] end # memoize the client or else setting up Faraday stubs does not work def client @_client ||= super end def user_info { 'nickname' => user_data["username"], 'email' => user_data["email"], 'name' => user_data['name'], 'image' => user_data['avatar'] } end def auth_hash OmniAuth::Utils.deep_merge(super, { 'uid' => user_data['id'], 'user_info' => user_info, 'extra' => {'user_hash' => user_data} }) end end CodePath = CodeSchool # for backward compatiblity end end