Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Okta auth method #206

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions lib/vault/api/auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,28 @@ def gcp(role, jwt, path = 'gcp')
return secret
end

# Authenticate via the okta authentication method. If authentication
# is successful, the resulting token will be stored on the client and used
# for future requests.
#
# @example
# Vault.auth.okta("sethvargo", "s3kr3t") #=> #<Vault::Secret lease_id="">
#
# @param [String] username
# @param [String] password
# @param [Hash] options
# additional options to pass to the authentication call, such as a custom
# mount point
#
# @return [Secret]
def okta(username, password, options = {})
payload = { password: password }.merge(options)
json = client.post("/v1/auth/okta/login/#{encode_path(username)}", JSON.fast_generate(payload))
secret = Secret.decode(json)
client.token = secret.auth.client_token
return secret
end

# Authenticate via a TLS authentication method. If authentication is
# successful, the resulting token will be stored on the client and used
# for future requests.
Expand Down
12 changes: 11 additions & 1 deletion spec/unit/auth_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@

module Vault
describe Authenticate do
let(:auth) { Authenticate.new(client: nil) }
let(:client) { double('client') }
let(:auth) { Authenticate.new(client) }

describe '#okta' do
it 'authenticates with Okta auth method' do
allow(client).to receive(:post).with('/v1/auth/okta/login/user1', {password: 'secure'}.to_json) { {auth: {client_token: 'abcd-1234'}} }
allow(client).to receive(:token=)
expect(auth.okta('user1', 'secure').auth.client_token).to eq('abcd-1234')
end
end

describe "#region_from_sts_endpoint" do
subject { auth.send(:region_from_sts_endpoint, sts_endpoint) }

Expand Down