Ruby SDK Giving Error: "Neither PUB key nor PRIV key"

新規投稿

コメント

5件のコメント

  • Murtza

     This seems like a string formatting issue, but I'm not sure what specifically is causing the error. An alternative approach would be using the developer console feature that lets you automatically generate JWT authentication credentials for your application. We have a guide within our developer documentation that walks through how to use that feature with the Ruby SDK.

    0
    コメントアクション Permalink
  • cdm_umn

    Thanks for that!

     

    I got my key situation resolved by reading in the .json file from Box and parsing it:

     

     

    file = File.read(ENV['JWT_CREDENTIALS_PATH'])
    credentialsHash = JSON.parse(file)
    
    #Parse credentials
    privateKey = credentialsHash['boxAppSettings']['appAuth']['privateKey'].to_s
    publicKeyId = credentialsHash['boxAppSettings']['appAuth']['publicKeyID'].to_s
    privateKeyPassword = credentialsHash['boxAppSettings']['appAuth']['passphrase'].to_s
    enterpriseId = credentialsHash['enterpriseID'].to_s
    clientId = credentialsHash['boxAppSettings']['clientID'].to_s
    clientSecret = credentialsHash['boxAppSettings']['clientSecret'].to_s
    
    response = Boxr::get_enterprise_token(
      private_key: privateKey,
      private_key_password: privateKeyPassword,
      public_key_id: publicKeyId,
      enterprise_id: enterpriseId,
      client_id: clientId,
      client_secret: clientSecret
    )

     

    Now my problem is that I get a 400 error saying that my app is not authorized.

     

     

    C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/boxr-1.4.0/lib/boxr/auth.rb:90:in `auth_post': 400: {"error":"unauthorized_client","error_description":"This app is not authorized by the enterprise admin"} (Boxr::BoxrError)
            from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/boxr-1.4.0/lib/boxr/auth.rb:24:in `get_tokens'
            from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/boxr-1.4.0/lib/boxr/auth.rb:32:in `get_enterprise_token'
            from boxtest.rb:32:in `'

     

    I checked with the Box admins for my organization and they verified that my client ID has been granted access. Why would I still be getting this error?

     

    My script works if I bypass all of this with the developer token, but I'd like to get the auth working properly.

    0
    コメントアクション Permalink
  • Murtza

     By any chance, did you change your application's permissions after your application was authorized by your Box Admin? If so, you would need to ask your Box Admin to re-authorize your application. 

    0
    コメントアクション Permalink
  • cdm_umn

    I did not. I did change the auth type to use traditional OAuth instead of JWT.

    I can't even get the examples provided with the SDK to work. When I try to run this one to figure out how to use OAuth, ruby just locks up and I don't get any output.

    0
    コメントアクション Permalink
  • cdm_umn

    I got the oauth example working by adding this near to the top of my script:

    STDOUT.sync = true

    I think I'm finally over the initial hurdle to get auth working.

    0
    コメントアクション Permalink

サインインしてコメントを残してください。