Highlighted

Can I use C#?

Adobe Employee ,
Feb 27, 2017

Copy link to clipboard

Copied

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

Views

216

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Can I use C#?

Adobe Employee ,
Feb 27, 2017

Copy link to clipboard

Copied

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

Views

217

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Sep 24, 2017

Copy link to clipboard

Copied

I have a self-signed certificate. The code to get the JWT above fails for me with the following error: Is there an alternative method call to get the private key?

RsaUsingSha alg expects key to be of AsymmetricAlgorithm type

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
New Here ,
Aug 17, 2018

Copy link to clipboard

Copied

Here's a more complete example in F# including a sample call to get a user's details:

GitHub - hoetz/AdobeUMAPI.FSharp

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...