The first step for using the Admin feature is to create a context of KiiAppAdminContext as shown in the following sample code. If you already have the app administrator token by executing the context.getAppAdminContext() in the server code, you do not need to create the context.
Here, we are putting the ClientID and ClientSecret that are assigned to your application when you create the application on the developer portal. See Checking and Resetting Access Keys to learn how to check your ClientID and ClientSecret.
Note: Your ClientID and ClientSecret are confidential information.
You should never disclose them to others, meaning that you should never use the feature when your code is open to the public. The feature is intended to be used in the situation where the code is hidden (e.g. the code is running on your server).
Please read Risk of Leaking Admin Credentials to learn about the risk of leaking your ClientID and ClientSecret.
Executing with app administrator privileges
You can manipulate objects with app administrator privileges by using methods of a KiiAppAdminContext instance. Create target instances such as KiiObject and KiiUser directly or indirectly, with a KiiAppAdminContext instance.
As shown in the left side of the figure below, if you create instances such as KiiObject and KiiUser in the app administrator context and access Kii Cloud with a method of the created instances, the method is executed with privileges of the app administrator.
As shown in the right side of the figure below, if you directly create target instances with a method such as Kii.bucketWithName() and access Kii Cloud with a method of the created instances, the method is executed with privileges of the logged-in user or the anonymous user if the user is not logged in.
App administrator privileges are granted not because the authenticateAsAppAdmin() method is executed but because a KiiAppAdminContext instance creates target instances.
Manipulating a KiiUser as an app administrator
Create a KiiUser instance by calling the userWithID method like the following example:
You will now have full access to the user.
Manipulating a KiiGroup as an app administrator
Creating a new KiiGroup
To create a new KiiGroup, create a KiiGroup instance by executing the groupWithName method first and then save the instance by executing the saveWithOwner method with the group owner's user ID. Please do not use the save method, or you will end up with creating a KiiGroup with no owner.
Creating a new KiiGroup with ID
By using the registerGroupWithOwnerAndID method, you can create a new KiiGroup with the specified group ID.
Using an existing KiiGroup
To use an existing KiiGroup, execute the groupWithURI method and create a KiiGroup instance like the following sample code:
You can also create a KiiGroup instance by calling groupWithID method as shown in the following sample code.
In both cases, you will now have full access to the group.
Manipulating a KiiBucket as an app administrator
Create aKiiBucket instance in an application scope by calling the bucketWithName method like the following example:
If you create a new bucket, it will have an application scope.
If you instantiate an existing bucket, you will be able to access to this bucket as an app admin.
Manipulating a KiiObject as an app administrator
Create a KiiObject instance by calling the objectWithURI method like the following example:
If you create a new object, it will have an application scope.
If you instantiate an existing object, you will be able to access to this object as an app admin.
Querying KiiUsers as an app administrator
Execute the findUserByUsername method to query KiiUsers like the following example:
You will now have full access to the user.
Please note that all user attributes will be returned regardless of the setting made on the "Expose Full User Data to Others" option.
The above example queries KiiUsers based on their username. You can also query based on their email addresses and phone numbers by executing the findUserByEmail and findUserByPhone methods, respectively.
Manipulating a KiiTopic as an app administrator
Create an application scope KiiTopic instance by calling the topicWithName method like the following example:
Here are a couple of documents that will help you:
See this page to check an example of creating an applcation scope topic.
See this page to check an example of sending push messages to an application scope topic.
Manipulating a KiiThing as an app administrator
Create a KiiThing instance by calling the loadThingWithThingID method like the following example:
This sample code is getting a KiiThing with the thingID. You can also get a KiiThing with the vendorThingID by executing the loadThingWithVendorThingID method. Also, you can register a new thing with the registerThing method. Please read the JSDoc for more details.