1

We are migrating our old WCF to REST API. We want to make requests to the Content Manager. I've seen a lot of examples of retrieving tokens to make the API requests but I really need to understand this:

  • Should I query the token to Access Management Service (in that case, what's the token svc address?)
  • What ClientId and ClientSecret should I use and where to define them?
  • Is any additional Role I have to request to have full access to CM?
  • Is there any c# sample code to start with?

Thank you in advance.

2 Answers 2

1

Please go through this link to get more details on Tridion Sites Content Manager REST API. Please let us know if you need more detail. Happy to share the same.

3
  • You made my day. Thank you Feb 7 at 18:23
  • Anand, is the authentication different between Tridion Sites 10 and earlier version of Access Management? Feb 7 at 19:07
  • 1
    The Tridion Experience Space BFF API shown in that article was introduced in Tridion Sites 10.0 and is officially not a public API. The API it exposes is (almost) the same as the Core Service REST API, but using its Swagger UI is easier than the Core Service REST Swagger UI if you are (only) using Access Management. For normal Core Service REST API use, you will have to provide a Bearer Token (an Access Token obtained from Access Management) in an HTTP Authorization header. That applies both to 9.6 and 10.0. Feb 21 at 11:25
1

Ok, based on that postman example, I've built this simple example in c#. It could be useful.

Remember to include RestSharp package.

namespace Tridion
{
    internal class Token
    {
        [JsonProperty("access_token")]
        public string AccessToken { get; set; } = string.Empty;
        [JsonProperty("token_type")]
        public string TokenType { get; set; } = string.Empty;
        [JsonProperty("expires_in")]
        public int ExpiresIn { get; set; }
        [JsonProperty("refresh_token")]
        public string RefreshToken { get; set; } = string.Empty;
    }
    public class TridionRestApiTokenResolutionService : ITridionRestApiTokenResolutionService
    {
        public TridionRestApiTokenResolutionService()
        {
        }
        public async Task<string> GetBearerToken()
        {
            var client_id = "78ffaefc-cxxxxxxxxxxxxxxxxxxxxcd7a10";
            var client_secret = "cWm63RppxxxxxxxxxxxxxxxxxxxxxNA9sYS2D6uSGtg==";
            var client = new RestClient("http://localhost/access-management/connect/token");
            var request = new RestRequest("", Method.Post);
            request.AddHeader("cache-control", "no-cache");
            request.AddHeader("content-type", "application/x-www-form-urlencoded");
            request.AddParameter("application/x-www-form-urlencoded", $"grant_type=client_credentials&client_id={client_id}&client_secret={client_secret}", ParameterType.RequestBody);
            RestResponse response = await client.ExecuteAsync(request);
            var jsonContent = response.Content;
            Token token = JsonConvert.DeserializeObject<Token>(jsonContent);
            return token.AccessToken;
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.