Class: RubyApp::Elements::Mobile::Documents::Authentication::OAuth::AuthenticationDocument

Inherits:
AuthenticationDocument show all
Defined in:
lib/ruby_app/elements/mobile/documents/authentication/o_auth/authentication_document.rb

Direct Known Subclasses

EmailAuthenticationDocument

Instance Attribute Summary

Attributes inherited from RubyApp::Elements::Mobile::Document

#links, #metadata, #pages, #scripts, #stylesheets

Attributes inherited from RubyApp::Element

#attributes

Instance Method Summary collapse

Methods inherited from RubyApp::Elements::Mobile::Document

#hide, #page, #show

Methods inherited from RubyApp::Element

#element_id, get_element

Methods included from Mixins::ConfigurationMixin

#configuration

Methods included from Mixins::TranslateMixin

#localize, #translate

Methods included from Mixins::TemplateMixin

#exclude_parent_template, #exclude_parent_template?, #get_cache, #get_default_template, #get_template, #get_template_name, #get_templates, #template_path

Methods included from Mixins::RenderMixin

#content_for, #get_cache, #get_default_template, #get_templates, #render

Constructor Details

#initialize(access_key, secret_key, scopes, options) ⇒ AuthenticationDocument

Returns a new instance of AuthenticationDocument.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ruby_app/elements/mobile/documents/authentication/o_auth/authentication_document.rb', line 24

def initialize(access_key, secret_key, scopes, options)
  super()

  self.page.loaded do |element, event|
    unless @client
      # RubyApp::Log.debug("OAUTH     scopes=#{scopes.inspect}")
      # RubyApp::Log.debug("OAUTH     options=#{options.inspect}")
      @client = ::OAuth2::Client.new(access_key, secret_key, options)
      url = @client.auth_code.authorize_url(:redirect_uri => RubyApp::Request.environment[RubyApp::Elements::Mobile::Documents::Authentication::AuthenticationDocument.configuration.return_to],
                                            :scope        => scopes.is_a?(Array) ? scopes.join(',') : scopes)
      RubyApp::Log.info("OAUTH     --> #{url.inspect}")
      event.go(url)
    else
      RubyApp::Log.info("OAUTH     <-- #{RubyApp::Request.url.inspect}")
      code = RubyApp::Request.query['code']
      access_token = @client.auth_code.get_token(code, :redirect_uri => RubyApp::Request.environment[RubyApp::Elements::Mobile::Documents::Authentication::AuthenticationDocument.configuration.return_to])
      # RubyApp::Log.debug("OAUTH     token=#{access_token.token.inspect}")
      self.process_token(access_token)
      self.hide(event)
    end
  end

end

Instance Method Details

#process_token(token) ⇒ Object



48
49
50
# File 'lib/ruby_app/elements/mobile/documents/authentication/o_auth/authentication_document.rb', line 48

def process_token(token)
  RubyApp::Session.identity = self.create_identity_from_token(token)
end