管理员帐户没有足够的权限来创建应用用户

时间:2017-10-23 20:41:26

标签: c# box

我正在尝试创建一个Windows应用程序(.Net,C#),它将获取传入的Box.com文件夹中的文件列表。显然,使用JWT授权配置新Box应用程序的一个步骤是创建带有SDK的应用程序用户(Box.V2)。我从SDK文档中的一些示例中获取了以下代码。 CreateEnterpriseUserAsync()调用失败,并显示错误消息:

  

BoxException:Bearer realm =“Service”,error =“insufficient_scope”,error_description =“请求需要的权限高于访问令牌提供的权限。”

我是帐户管理员,所以我应该拥有所有权利。但是,我只使用一个席位的开发者帐户。 。 。不确定这是否是限制。我会感激任何帮助!

错误发生在样本的大约3/4处,如图所示。

namespace Trial5
{
  class Program
  {
    static void Main(string[] args)
    {
        var t = Configure();
        t.Wait();
    }

    private static async Task Configure()
    {
            // Open a stream to read the Box configuration file.
            using (System.IO.FileStream fs = new FileStream($"./BoxConfig.json", FileMode.Open))
            {

            //configure  -----------------------------------------------------------------
            var boxConfig = BoxConfig.CreateFromJsonFile(fs);
            var boxJWT = new BoxJWTAuth(boxConfig); 

            //authenticate   -----------------------------------------------------------------
            var adminToken = boxJWT.AdminToken(); //valid for 60 minutes so should be cached and re-used
            var adminClient = boxJWT.AdminClient(adminToken);

            // Use the GetCurrentUserInformationAsync method to retrieve current user's information.
            // Since this client uses the Service Account, this will return the Service Account's information.
            var adminClientInfo = await adminClient.UsersManager.GetCurrentUserInformationAsync();
            //See the login
            Console.WriteLine(adminClientInfo.Login);

            //create app user  -----------------------------------------------------------------
            //NOTE: you must set IsPlatformAccessOnly=true for an App User
            var userRequest = new BoxUserRequest() { Name = "test appuser1", IsPlatformAccessOnly = true };
            var appUser = await adminClient.UsersManager.CreateEnterpriseUserAsync(userRequest);  // <---------------ERROR HERE

            //get a user client  -----------------------------------------------------------------
            var userToken = boxJWT.UserToken(appUser.Id); //valid for 60 minutes so should be cached and re-used
            var userClient = boxJWT.UserClient(userToken, appUser.Id);

            //for example, look up the app user's details
            var userClientInfo = await userClient.UsersManager.GetCurrentUserInformationAsync();

            //Get folder info
            var items = await userClient.FoldersManager.GetFolderItemsAsync("0", 500);

        }
      }
    }
  }

1 个答案:

答案 0 :(得分:1)

如果您在应用控制台上选中“管理员用户”范围,然后在“应用”下的企业管理控制台中重新授权您的应用,则应该可以使用。

enter image description here