Class: OmniAuth::Strategies::KhanAcademy
- Inherits:
-
Object
- Object
- OmniAuth::Strategies::KhanAcademy
- Includes:
- OmniAuth::Strategy
- Defined in:
- lib/omniauth/strategies/khan_academy.rb
Constant Summary collapse
- DEFAULT_CLIENT_OPTIONS =
{ "http_method" => :get, "site" => "http://www.khanacademy.org", "request_token_path" => "/api/auth/request_token", "access_token_path" => "/api/auth/access_token" }
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
Instance Method Summary collapse
- #callback_phase ⇒ Object
- #callback_url ⇒ Object
- #client_options ⇒ Object
- #consumer ⇒ Object
- #login_url ⇒ Object
- #raw_info ⇒ Object
-
#request_phase ⇒ Object
this will redirect to the KhanAcademy login page where you can login using google, facebook or khan“s login Khan returns the required credentials for the request token after authentication.
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
29 30 31 |
# File 'lib/omniauth/strategies/khan_academy.rb', line 29 def access_token @access_token end |
Instance Method Details
#callback_phase ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/omniauth/strategies/khan_academy.rb', line 39 def callback_phase raise OmniAuth::NoSessionError.new("Session Expired") if session["oauth"].nil? # Create a request token from the token and secret provided in the response request_token = ::OAuth::AccessToken.new(consumer, request["oauth_token"], request["oauth_token_secret"]) # Request access_token from the created request_token @access_token = consumer.get_access_token(request_token, {oauth_callback: callback_url, oauth_verifier: request["oauth_verifier"]}) super rescue ::Timeout::Error => e fail!(:timeout, e) rescue ::Net::HTTPFatalError, ::OpenSSL::SSL::SSLError => e fail!(:service_unavailable, e) rescue ::OAuth::Unauthorized => e fail!(:invalid_credentials, e) rescue ::MultiJson::DecodeError => e fail!(:invalid_response, e) rescue ::OmniAuth::NoSessionError => e fail!(:session_expired, e) end |
#callback_url ⇒ Object
86 87 88 |
# File 'lib/omniauth/strategies/khan_academy.rb', line 86 def callback_url .callback_url || super end |
#client_options ⇒ Object
82 83 84 |
# File 'lib/omniauth/strategies/khan_academy.rb', line 82 def DEFAULT_CLIENT_OPTIONS.merge(. || {}) end |
#consumer ⇒ Object
91 92 93 |
# File 'lib/omniauth/strategies/khan_academy.rb', line 91 def consumer @consumer ||= ::OAuth::Consumer.new(.consumer_key, .consumer_secret, ) end |
#login_url ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'lib/omniauth/strategies/khan_academy.rb', line 96 def login_url req = consumer.create_signed_request(:get, consumer.request_token_url, nil, {oauth_callback: callback_url}) oauth_params_string = req.instance_variable_get("@header")["authorization"].first oauth_params_hash = req.parse_header(oauth_params_string) "#{consumer.request_token_url}?#{oauth_params_hash.to_query}" end |
#raw_info ⇒ Object
59 60 61 |
# File 'lib/omniauth/strategies/khan_academy.rb', line 59 def raw_info @raw_info ||= MultiJson.decode(access_token.get("/api/v1/user").body) end |
#request_phase ⇒ Object
this will redirect to the KhanAcademy login page where you can login using google, facebook or khan“s login Khan returns the required credentials for the request token after authentication
33 34 35 36 |
# File 'lib/omniauth/strategies/khan_academy.rb', line 33 def request_phase session["oauth"] ||= {} redirect login_url end |