Join BoxWorks in San Francisco Nov 12-13! Keynotes, product demos, and Box Master Classes. Reserve your spot!

Getting a user

Answered
New post

Comments

3 comments

  • Murtza

     I just tested this, but I was not able to reproduce the error you are getting. I requested tokens for a user and an admin using JWT authentication and the Ruby SDK. I shared the code I used to test with below.

     

    I think the issue you are seeing might be related to your application access and application scopes settings.

     

    Can you please confirm if the following settings are enabled for your application?

    • Application Access set to "Enterprise".
    • "Manage Users", "Manage Groups", and "Manage Enterprise Properties" enabled within the Application Scopes section.
    • "Generate User Access Tokens" enabled within the Advanced Features section.

     

    require 'boxr' #Box Ruby SDK
    require 'json'
    
    def getAccessToken
      #Read JWT credentials
      #You can generate JWT credentials within the developer console on the app configuration page
      file = File.read('credentials.json')
      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
      userId = "REPLACE_WITH_USER_TOKEN"
      adminId = "REPLACE_WIHT_ADMIN_TOKEN"
    
      #Request enterprise token
      responseEnterpriseToken = Boxr::get_enterprise_token(private_key: privateKey, private_key_password: privateKeyPassword, public_key_id: publicKeyId, enterprise_id: enterpriseId, client_id: clientId, client_secret: clientSecret)
      puts responseEnterpriseToken.access_token.to_s
      
      #Request user token
      responseUserToken = Boxr::get_user_token(userId, private_key: privateKey, private_key_password: privateKeyPassword, public_key_id: publicKeyId, client_id: clientId, client_secret: clientSecret)
      puts responseUserToken.access_token.to_s
      
      #Request admin user token
      responseAdminToken = Boxr::get_user_token(adminId, private_key: privateKey, private_key_password: privateKeyPassword, public_key_id: publicKeyId, client_id: clientId, client_secret: clientSecret)
      puts responseAdminToken.access_token.to_s
    end
    
    getAccessToken

     

    0
    Comment actions Permalink
  • dan77

    I assumed that this is due to my settings in the service. I did everything that you said, but I'm still getting this error.

    In section "Authentication Method" i set - OAuth 2.0 with JWT (Server Authentication).

    Section "Developer Token" and  "OAuth 2.0 Credentials" i I didnt change.

    In section "Application Access" i set - "Enterprise" (instead "Application")

    In section "Application Scopes" - "Manage Users", "Manage Groups", and "Manage Enterprise Properties" i set enabled

    And finally in section "Advanced Features" I turned on "Generate User Access Tokens"

    So, I saved the changes and still get this error

     
    0
    Comment actions Permalink
  • Murtza

     After updating these settings, did you reauthorize your application on this page in the Admin console?

     

    Screen Shot 2017-08-02 at 2.18.19 PM.png

    0
    Comment actions Permalink

Please sign in to leave a comment.