Class: Warden::Strategies::Doorkeeper

Inherits:
Base
  • Object
show all
Defined in:
lib/warden/strategies/doorkeeper.rb

Constant Summary collapse

VERSION =
"0.3.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env, scope = nil) ⇒ Doorkeeper



8
9
10
11
12
# File 'lib/warden/strategies/doorkeeper.rb', line 8

def initialize(env, scope=nil)
  super

  @scope = scope
end

Instance Attribute Details

#scopeObject (readonly)

Returns the value of attribute scope.



6
7
8
# File 'lib/warden/strategies/doorkeeper.rb', line 6

def scope
  @scope
end

#tokenObject (readonly)

Returns the value of attribute token.



6
7
8
# File 'lib/warden/strategies/doorkeeper.rb', line 6

def token
  @token
end

Instance Method Details

#authenticate!Object



19
20
21
22
23
24
25
26
# File 'lib/warden/strategies/doorkeeper.rb', line 19

def authenticate!
  user = User.where(id: @token.resource_owner_id).first
  if user
    success!(user)
  else
    fail!("No such user")
  end
end

#configObject

Returns the configuration data for the default user scope.



29
30
31
32
33
34
35
36
# File 'lib/warden/strategies/doorkeeper.rb', line 29

def config
  scopes = env["warden"].config[:scope_defaults]
  if scopes && scopes[:user]
    scopes[:user][:config]
  else
    {}
  end
end

#valid?Boolean



14
15
16
17
# File 'lib/warden/strategies/doorkeeper.rb', line 14

def valid?
  @token = ::Doorkeeper::OAuth::Token.authenticate(request, *Doorkeeper.configuration.access_token_methods)
  @token && @token.accessible? && @token.acceptable?(@scope)
end