Class: Identity::Gateway::Provider

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/identity/gateway/provider.rb

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ Provider

Class initializer.

Parameters

  • request - Current request.

Returns

Assigns arguments to instance variables.



16
17
18
19
20
21
22
# File 'lib/identity/gateway/provider.rb', line 16

def initialize(request)
  @settings = Identity::Gateway.configuration
  @request  = request
  @response = {}
  @subject  = nil
  @model    = Object.const_get(@settings.model)
end

Instance Method Details

#authorize!Object

Get token resource owner.

Returns

  • Object - HTTParty response or identity error.



28
29
30
31
32
33
# File 'lib/identity/gateway/provider.rb', line 28

def authorize!
  token = request_token
  @subject = @model.find_by(token: token)
  return unless (@subject && @subject.token_has_expired?) || @subject.nil?
  authorize_from_provider
end

#current_resourceObject

The current instance object associated to the model define in the configuration.

Returns

  • Object - instance or nil.



40
41
42
# File 'lib/identity/gateway/provider.rb', line 40

def current_resource
  @subject
end

#revoke_access!Object

Revoke access token.

Returns

  • HTTParty::Response.



48
49
50
51
52
53
54
# File 'lib/identity/gateway/provider.rb', line 48

def revoke_access!
  self.class.post(
    "#{@settings.provider_url}/oauth/revoke",
    body: { token: request_token }.to_json,
    headers: api_headers
  )
end