api/v1

REST API v1

The API v1 provides initial implementation of the elDoc REST API.

IMPORTANT: this REST API version is deprecated and will be removed in the next releases. Please follow the Release Notes.

JWT requirements

JWT header must contain the following attributes:

  • alg - supported algorithms: HS256, HS384, HS512

JWT payload must contain the following claims:

  • sub - System ID of the respective API account
  • iat
  • nbf - Allowed time difference with the server time can not be more than 300 sec.
  • exp

JWT has to be signed with the security token of the the respective API Account.

elDoc API JWT generation implementation samples:

C# imlementation
using System;
using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Text;


namespace elDocApiUtils
{
    class JwtUtils
    {
        public enum HMAC_ALGS
        {
            SHA256,
            SHA384,
            SHA512
        }

        public static string GetSignedJWT(string subject, string subjectKey, HMAC_ALGS alg)
        {
            byte[] key = Encoding.UTF8.GetBytes(subjectKey);
            SymmetricSecurityKey securityKey = new SymmetricSecurityKey(key);

            SecurityTokenDescriptor descriptor = new SecurityTokenDescriptor();
            descriptor.Issuer = "elDocApiClient";
            descriptor.Subject = new ClaimsIdentity(new[] { new Claim("sub", subject) });
            descriptor.Expires = DateTime.UtcNow.AddMinutes(5);

            string algorythm = SecurityAlgorithms.HmacSha256Signature;

            switch (alg)
            {
                case HMAC_ALGS.SHA384:
                    algorythm = SecurityAlgorithms.HmacSha384Signature;
                    break;

                case HMAC_ALGS.SHA512:
                    algorythm = SecurityAlgorithms.HmacSha512Signature;
                    break;

                default:
                case HMAC_ALGS.SHA256:
                    algorythm = SecurityAlgorithms.HmacSha256Signature;
                    break;
            }

            descriptor.SigningCredentials = new SigningCredentials(securityKey, algorythm);

            JwtSecurityTokenHandler handler = new JwtSecurityTokenHandler();
            JwtSecurityToken token = handler.CreateJwtSecurityToken(descriptor);
            return handler.WriteToken(token);
        }
    }
}


Last modified: November 23, 2024