Can I use C#?
The documentation details connecting with UMAPI using Python (Samples) however here is a C# sample for reference...
Generating a JSON Web Token (JWT):
using System;
using System.Collections.Generic;
using Jose;
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography;
// the namespace would be the name of your project, mine is "aaa"
namespace aaa
{
class MainClass
{
public static void Main (string[] args)
{DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
TimeSpan diff = DateTime.Now.ToUniversalTime() - origin;
var span = Math.Floor(diff.TotalSeconds) + 60*60*24;
var payload = new Dictionary<string, object>()
{
{"iss", “enter-yours"},
{"aud" , "enter-yours"},
{"exp", span},
{"sub", "enter-yours"},
{"https://ims-na1.adobelogin.com/s/ent_user_sdk", true}
};
var privateKey=new X509Certificate2("my-key.p12", “xxxxxx", X509KeyStorageFlags.Exportable | X509KeyStorageFlags.MachineKeySet).PrivateKey as RSACryptoServiceProvider;
string token=Jose.JWT.Encode(payload, privateKey, JwsAlgorithm.RS256);
Console.WriteLine (token);
}
}
}
Using the JWT to retrieve an Access Token:
using System;
using RestSharp;
namespace project2
{
class MainClass
{
public static void Main(string[] args)
{
var client = new RestClient("https://ims-na1.adobelogin.com/ims/exchange/jwt"); // replace with production if necessary
var request = new RestRequest(Method.POST);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("content-type", "application/x-www-form-urlencoded");
request.AddParameter("client_id", "your client id");
request.AddParameter("client_secret", "your client secret");
request.AddParameter("jwt_token", "your jwt token");
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
}
}
}
