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;
}
}
}