Service Accounts - how to create one, and how to use it through .NET SDK
I can successfully create an App User through the .NET SDK but reading up on what I need (server-to server access to all users' files) it looks like I would be better served with a service account.
I've read up on them (https://docs.box.com/docs/service-account) and followed the steps in the setup guide. But at the end of following the steps: I don't have a service account. Nowehere in that setup guide does it actually create an account. Those steps all describe how to set up the app, but don't create an actual account to use. The setup guide ends with "Once you’ve completed the authorization for the new application, you can begin using Box Platform with Service Accounts."
How? Where do I create the Service Account? And how do I then use it through the API.
-
I think the docs are confusing on that too but here's my understanding.
App == ServiceAccount.
So for example, adminClient == ServiceAccount.
static async Task MainAsync() { // rename the private_key.pem.example to private_key.pem and put your JWT private key in the file var privateKey = File.ReadAllText(PRIVATE_KEY_FILE); var boxConfig = new BoxConfig(CLIENT_ID, CLIENT_SECRET, ENTERPRISE_ID, privateKey, JWT_PRIVATE_KEY_PASSWORD, JWT_PUBLIC_KEY_ID); var boxJWT = new BoxJWTAuth(boxConfig); var adminToken = boxJWT.AdminToken(); Console.WriteLine("Admin Token: " + adminToken); Console.WriteLine(); var adminClient = boxJWT.AdminClient(adminToken); // adminClient == serviceAccount var userDetails = await adminClient.UsersManager.GetCurrentUserInformationAsync(); Console.WriteLine("\tAdmin User Details:"); Console.WriteLine("\tId: {0}", userDetails.Id); Console.WriteLine("\tName: {0}", userDetails.Name); Console.WriteLine("\tStatus: {0}", userDetails.Status); Console.WriteLine(); var users = await adminClient.UsersManager.GetEnterpriseUsersAsync(); users.Entries.ForEach(i => { Console.WriteLine("\t{0}", i.Name); Console.WriteLine("\t{0}", i.Status); if (i.Status == "active") { var userToken = boxJWT.UserToken(i.Id); var userClient = boxJWT.UserClient(userToken, i.Id); Task u = getUserItems(userClient, i.Id); u.Wait(); } }); }
https://github.com/kendomen/BoxDotNetGetManagedUsersItems
サインインしてコメントを残してください。
コメント
2件のコメント