Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JsonWebToken"/> class.
 /// </summary>
 /// <param name="header">The first part of the JSON Web Token; the header information.</param>
 /// <param name="payload">The second part of the JSON Web Token; the payload information.</param>
 /// <param name="secret">The optional secret that is used in the last part of the JSON Web Token; the signature.</param>
 public JsonWebToken(JsonWebTokenHeader header, JsonWebTokenPayload payload, byte[] secret)
 {
     Validator.ThrowIfNull(header, nameof(header));
     Validator.ThrowIfNull(payload, nameof(payload));
     if (header.Algorithm != JsonWebTokenHashAlgorithm.None && secret == null)
     {
         throw new ArgumentException("You must specify a secret when JsonWebTokenHashAlgorithm is specified to other than None.", nameof(secret));
     }
     Base64UrlEncodedHeader  = StringConverter.ToUrlEncodedBase64(Encoding.UTF8.GetBytes(header.ToString()));
     Base64UrlEncodedPayload = StringConverter.ToUrlEncodedBase64(Encoding.UTF8.GetBytes(payload.ToString()));
     Algorithm = header.Algorithm;
     Secret    = secret;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JsonWebToken"/> class that is .
 /// </summary>
 /// <param name="header">The first part of the JSON Web Token; the header information.</param>
 /// <param name="payload">The second part of the JSON Web Token; the payload information.</param>
 public JsonWebToken(JsonWebTokenHeader header, JsonWebTokenPayload payload) : this(header, payload, null)
 {
 }