I created a quick proof-of-concept which worked great with my developer token.
Now I'm trying to authenticate with OAuth JWT and I can't get it working.
Currently my script is supposed to get the enterprise token to use for authentication. When I run it, it returns the error
boxtest.rb:17:in `initialize': Neither PUB key nor PRIV key: nested asn1 error (OpenSSL::PKey::RSAError)
The JWT_SECRET_KEY_PATH setting points to the full path of a file that only contains the string for the private key. I've verified that it's being read in correctly. I've tried changing the format of the contents of the file (removing the comments and newlines) but it made no difference.
require 'dotenv'
Dotenv.load(".env")
require 'boxr'
require 'openssl'
private_key = OpenSSL::PKey::RSA.new(File.read(ENV['JWT_SECRET_KEY_PATH']), ENV['JWT_SECRET_KEY_PASSWORD'])
response = Boxr::get_enterprise_token(
private_key: private_key,
private_key_password: ENV['JWT_SECRET_KEY_PASSWORD'],
public_key_id: ENV['JWT_PUBLIC_KEY_ID'],
enterprise_id: ENV['BOX_ENTERPRISE_ID'],
client_id: ENV['BOX_CLIENT_ID'],
client_secret: ENV['BOX_CLIENT_SECRET']
)
puts response
I'm using the ruby SDK with ruby 2.3.1p112
Thanks!