Class: Vault::Authenticate
Instance Attribute Summary
Attributes inherited from Request
Instance Method Summary collapse
-
#app_id(app_id, user_id, options = {}) ⇒ Secret
Authenticate via the “app-id” authentication method.
-
#token(new_token) ⇒ Secret
Authenticate via the “token” authentication method.
-
#userpass(username, password, options = {}) ⇒ Secret
Authenticate via the “userpass” authentication method.
Methods inherited from Request
Constructor Details
This class inherits a constructor from Vault::Request
Instance Method Details
#app_id(app_id, user_id, options = {}) ⇒ Secret
Authenticate via the “app-id” authentication method. If authentication is successful, the resulting token will be stored on the client and used for future requests.
69 70 71 72 73 74 75 |
# File 'lib/vault/api/auth.rb', line 69 def app_id(app_id, user_id, = {}) payload = { app_id: app_id, user_id: user_id }.merge() json = client.post("/v1/auth/app-id/login", JSON.fast_generate(payload)) secret = Secret.decode(json) client.token = secret.auth.client_token return secret end |
#token(new_token) ⇒ Secret
Authenticate via the “token” authentication method. This authentication method is a bit bizarre because you already have a token, but hey, whatever floats your boat.
This method hits the ‘/v1/auth/token/lookup-self` endpoint after setting the Vault client’s token to the given token parameter. If the self lookup succeeds, the token is persisted onto the client for future requests. If the lookup fails, the old token (which could be unset) is restored on the client.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/vault/api/auth.rb', line 34 def token(new_token) old_token = client.token client.token = new_token json = client.get("/v1/auth/token/lookup-self") secret = Secret.decode(json) return secret rescue client.token = old_token raise end |
#userpass(username, password, options = {}) ⇒ Secret
Authenticate via the “userpass” authentication method. If authentication is successful, the resulting token will be stored on the client and used for future requests.
94 95 96 97 98 99 100 |
# File 'lib/vault/api/auth.rb', line 94 def userpass(username, password, = {}) payload = { password: password }.merge() json = client.post("/v1/auth/userpass/login/#{username}", JSON.fast_generate(payload)) secret = Secret.decode(json) client.token = secret.auth.client_token return secret end |