Class: OAuth::Controllers::ApplicationControllerMethods::Authenticator

Inherits:
Object
  • Object
show all
Defined in:
lib/oauth/controllers/application_controller_methods.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller, strategies) ⇒ Authenticator

Returns a new instance of Authenticator.



38
39
40
41
# File 'lib/oauth/controllers/application_controller_methods.rb', line 38

def initialize(controller,strategies)
  @controller = controller
  @strategies = strategies
end

Instance Attribute Details

#controllerObject

Returns the value of attribute controller.



37
38
39
# File 'lib/oauth/controllers/application_controller_methods.rb', line 37

def controller
  @controller
end

#strategiesObject

Returns the value of attribute strategies.



37
38
39
# File 'lib/oauth/controllers/application_controller_methods.rb', line 37

def strategies
  @strategies
end

#strategyObject

Returns the value of attribute strategy.



37
38
39
# File 'lib/oauth/controllers/application_controller_methods.rb', line 37

def strategy
  @strategy
end

Instance Method Details

#allow?Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/oauth/controllers/application_controller_methods.rb', line 43

def allow?
  if @strategies.include?(:interactive) && interactive
    true
  elsif !(@strategies & env["oauth.strategies"].to_a).empty?
    @controller.send :current_user=, token.user if token
    true
  else
    if @strategies.include?(:interactive)
      controller.send :access_denied
    else
      controller.send :invalid_oauth_response
    end
  end
end

#client_applicationObject



78
79
80
# File 'lib/oauth/controllers/application_controller_methods.rb', line 78

def client_application
  env["oauth.version"]==1 && env["oauth.client_application"] || oauth20_token.try(:client_application)
end

#envObject



90
91
92
# File 'lib/oauth/controllers/application_controller_methods.rb', line 90

def env
  request.env
end

#interactiveObject



86
87
88
# File 'lib/oauth/controllers/application_controller_methods.rb', line 86

def interactive
  @controller.send :logged_in?
end

#oauth10_access_tokenObject



70
71
72
# File 'lib/oauth/controllers/application_controller_methods.rb', line 70

def oauth10_access_token
  oauth10_token && oauth10_token.is_a?(::AccessToken) ? oauth10_token : nil
end

#oauth10_request_tokenObject



66
67
68
# File 'lib/oauth/controllers/application_controller_methods.rb', line 66

def oauth10_request_token
  oauth10_token && oauth10_token.is_a?(::RequestToken) ? oauth10_token : nil
end

#oauth10_tokenObject



62
63
64
# File 'lib/oauth/controllers/application_controller_methods.rb', line 62

def oauth10_token
  env["oauth.version"]==1 && env["oauth.token"]
end

#oauth20_tokenObject



58
59
60
# File 'lib/oauth/controllers/application_controller_methods.rb', line 58

def oauth20_token
   env["oauth.version"]==2 && env["oauth.token"]
end

#requestObject



94
95
96
# File 'lib/oauth/controllers/application_controller_methods.rb', line 94

def request
  controller.send :request
end

#tokenObject



74
75
76
# File 'lib/oauth/controllers/application_controller_methods.rb', line 74

def token
  oauth20_token || oauth10_access_token || nil
end

#two_leggedObject



82
83
84
# File 'lib/oauth/controllers/application_controller_methods.rb', line 82

def two_legged
   env["oauth.version"]==1 && client_application
end