TokenScope
TokenScope
TokenScope holds one scope entry of a token: the module it covers, the branches in it, and the permissions on it. ManagementTokenModel.Scope takes a list of them, and DeliveryTokenScope extends it.
When to Use This Class: Use this class to set what a management token can access.
Conceptual Role: Acts as the item type of ManagementTokenModel.Scope and the base class of DeliveryTokenScope.
Returns: TokenScope. One scope entry of a token.
Properties
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| Module | string | No | null | Module the entry covers, for example content_type or branch. Serialized as module. |
| ACL | Dictionary<string, string> | No | null | Permissions, for example read and write set to "true". Serialized as acl. |
| Branches | List<string> | No | null | UIDs of the branches the entry covers, for the branch module. Serialized as branches. |
Class-Level Notes
Nullability.
- The SDK declares the string and List properties without ? and gives them no initial value, so each one holds null until you set it. The SDK leaves null properties out of the request body.
- ACL takes string values, so the SDK sends "true" as a JSON string, not as a boolean.
Method Index
TokenScope has no methods. Add it to ManagementTokenModel.Scope, or use DeliveryTokenScope for a delivery token.
Class-Level Snippet
This snippet builds two scope entries and adds them to a management token model.
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models.Token;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
List<TokenScope> scope = new List<TokenScope>
{
new TokenScope()
{
Module = "content_type",
ACL = new Dictionary<string, string> { ["read"] = "true", ["write"] = "true" }
},
new TokenScope()
{
Module = "branch",
Branches = new List<string> { "main" },
ACL = new Dictionary<string, string> { ["read"] = "true" }
}
};
ManagementTokenModel model = new ManagementTokenModel() { Name = "Content Migration", Scope = scope };
try
{
// In version 1.2.0 this request goes to /delivery_tokens. See the ManagementToken class page.
ContentstackResponse response = client.Stack("<API_KEY>").ManagementTokens().Create(model);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}