Class: DistributedPress::V1::Client::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/distributed_press/v1/client/auth.rb

Overview

Manage auth

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Auth

Returns a new instance of Auth.

Parameters:



14
15
16
# File 'lib/distributed_press/v1/client/auth.rb', line 14

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



11
12
13
# File 'lib/distributed_press/v1/client/auth.rb', line 11

def client
  @client
end

Instance Method Details

#exchange(schema) ⇒ DistributedPress::V1::Token

Exchanges a token for another one



22
23
24
25
26
27
# File 'lib/distributed_press/v1/client/auth.rb', line 22

def exchange(schema)
  validate_schema! schema
  validate_capabilities! schema

  Token.new(token: client.post(endpoint: '/v1/auth/exchange', schema: schema).body)
end

#revoke(schema) ⇒ Boolean

Revokes a token

Parameters:

Returns:

  • (Boolean)

Raises:



33
34
35
36
37
38
39
# File 'lib/distributed_press/v1/client/auth.rb', line 33

def revoke(schema)
  validate_schema! schema

  raise TokenCapabilityMissingError, 'Only admins can revoke tokens' unless client.token.admin?

  client.delete(endpoint: "/v1/auth/revoke/#{schema[:tokenId]}")
end