Class: DistributedPress::V1::Client::Auth
- Inherits:
-
Object
- Object
- DistributedPress::V1::Client::Auth
- Defined in:
- lib/distributed_press/v1/client/auth.rb
Overview
Manage auth
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#exchange(schema) ⇒ DistributedPress::V1::Token
Exchanges a token for another one.
-
#initialize(client) ⇒ Auth
constructor
A new instance of Auth.
-
#revoke(schema) ⇒ Boolean
Revokes a token.
Constructor Details
#initialize(client) ⇒ Auth
Returns a new instance of Auth.
14 15 16 |
# File 'lib/distributed_press/v1/client/auth.rb', line 14 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Object (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
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 |