新しいBoxサポートサイトへようこそ。 変更点の詳細はこちらをご確認ください .

コメント

8件のコメント

  • Murtza

     

    When you are generating a JWT assertion to request an enterprise access token, you pass in your Enteprise ID. You can find the Enterprise ID on this page: https://app.box.com/master/settings

     

    With the enterprise access token, you can create an app user. When you are generating a JWT assertion to request an app user access token, you pass in the id for the App User. 

     

    I would recommend checking out our SDKs, which make the JWT authentication process easier.

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

    When I view the account settings using https://app.box.com/master/settings I don't see an Enterprise id. I do have the login username, but not sure that is the id.

     

    Also, I want to do things on behalf of 1 user and so thought providing a user_id for JWT auth would be more appropriate. I don't want to create a new user. I would much appreciate  your help on how to authenticate with JWT using the user_id.

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

    I've been struggling with this for a week: 

     

    "Also, I want to do things on behalf of 1 user and so thought providing a user_id for JWT auth would be more appropriate. I don't want to create a new user. I would much appreciate  your help on how to authenticate with JWT using the user_id."

     

    I can't believe that the documentation is so poor that something as basic as this is not documented somewhere in the SDK.

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

    Hi , sorry to hear about the troubles! What part are you struggling with and what SDK are you using?

     

    Most SDKs have documentation pieces on using App Users - for example, here is a link to our Node SDK.

    https://github.com/box/box-node-sdk/blob/master/docs/authentication.md#app-user-authentication

     

    The minimum you'll need would be a user_id, which would be returned at the time you created a user. You can store those locally for your application's use if you'd like, so it's easier to refer back.

     

    To  , not sure if you're still around but I'm sorry you didn't get an answer! Best way to understand how to get a user ID is by trying it on your own account first. This API call returns the info for the user associated with an access token. Note you'll get back an enterprise ID (represents your larger "account"), under which you'll have a user ID:

    https://developer.box.com/v2.0/reference#get-the-current-users-information.

     

    You can see example responses on the right hand sidebar.

     

    On the left hand sidebar, there's other API calls you can use that are related to users. Some may not be included in SDKs - we're always working to improve, so if you see anything you'd like added, please put an enhancement request (issues thread) on the github page for the respective SDK you're using!

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

    I'm using the .NET SDK.  Can you point me to the specific example of using Authentication with JWT and accessing files for a company? 

     

    My app is working great when I using the developer token because it's tied to my box account.  I have permissions to search through all of my companies files. But when I connect with the Admin Token, my search returns no results.  I assume it's because the Admin Client is not impersonating me as a user.   Instead the user does not have permissions to access files.   I think by default, the Admin Token should have access to all files for my company since I've given in permissions through the developer console. 

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

    Hi Mike,

     

    Thanks for your reply! You're on the right path. If your code works with the developer token, that means you're set up correctly! 

     

    The difference comes from what it means to use an "Admin Client". That "Admin Client" refers to the Service Account for your app, which is created when you authorize a Server Authentication (OAuth 2 with JWT) app in your enterprise. You should be able to see it from the Content Manager, if your enterprise has access to it. 

     

    What you'll want to do instead is get an access token for yourself, like what is shown in the 2nd half of this example:

    https://github.com/box/box-windows-sdk-v2#create-an-app-user

     

    Note how there's a place to enter in the user ID that you wish to obtain a token for. Then, you should be good to go! Try that and see what happens / if that works for you?

     

    Thanks,

    Jason

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

    I was finally able to get it to work.  The solution was pretty simple once I figured it out.  I just needed to use: 

           var client = session.UserClient(userToken, userId);

    to establish a User Client session as a specific user. Then I was able to search for folders with a specific string.  Our use case was pretty specific, we were trying to use the API to search for specific folders that start with a job number on box.  We use this job number as a unique identifier within another application.  I'm just trying to provide an easy way for our users to link from another application directly to the job folder.

     

    here's a sample of my code. Perhaps someone else may benefit from this:

     

    static void SearchBoxFolders(string SearchString )
     {

      using (FileStream fs = new FileStream($"./config.json", FileMode.Open))
        {
           // Initialize the SDK with the Box configuration file
           var session = new BoxJWTAuth(BoxConfig.CreateFromJsonFile(fs));
           // use the User ID for your user  on box.com.  I was able to use Inspect on the Admin Console to determine 

          // this user id.  Its an integer about 10 digits long.
           var userId = "XXXXXXXXXX";
           var userToken = session.UserToken(userId);
           var client = session.UserClient(userToken, userId);
           try
           {
           Task.Run(async () =>
           {
           var items = await client.SearchManager.SearchAsync(SearchString, 10, 0);
           List itemsList = items.Entries;
           foreach (BoxItem item in itemsList)
           {
           if (item.Type == "folder")
           {

           // search for box folders that start with a specific string such as a job number

           if (item.Name.IndexOf(SearchString) == 0)
           {
                  Console.WriteLine("Item Type: {0}.", item.Type);
                  Console.WriteLine("Path: {0}.", item.PathCollection.Entries[1].Name);
                  Console.WriteLine("Found Here in Position: {0} ", item.Name.IndexOf(SearchString));
                  Console.WriteLine("Item Name: {0}. Item Id: {1}", item.Name, item.Id);
                  string BoxURL = " https://sangereby.app.box.com/folder/" + item.Id;
                  Console.WriteLine("URL: {0}", BoxURL);
           }
           }

           }
    }

    }).GetAwaiter().GetResult();
    }
           catch (Exception ex)
    {
           var myException = new Exception("", ex);
           throw myException;
    }
    }

    }

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

    Thank you! This was incredibly helpful.

    Getting the user Id was the missing piece in order to connect my App with JWT access, to the Box content that the user has access to.

    0
    コメントアクション Permalink

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