Ejemplo n.º 1
0
        /// <summary>
        /// Writes a JWT in its compact serialization format.
        /// </summary>
        /// <param name="descriptor">The descriptor of the JWT.</param>
        /// <param name="output">The <see cref="IBufferWriter{T}"/> used for writing the output.</param>
        /// <returns>The array of <see cref="byte"/> representation of the JWT.</returns>
        public void WriteToken(JwtDescriptor descriptor, IBufferWriter <byte> output)
        {
            if (descriptor is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.descriptor);
            }

            if (!IgnoreTokenValidation)
            {
                descriptor.Validate();
            }

            var encodingContext = new EncodingContext(EnableHeaderCaching ? _headerCache : null, TokenLifetimeInSeconds, GenerateIssuedTime);

            descriptor.Encode(encodingContext, output);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Writes a JWT in its compact serialization format.
 /// </summary>
 /// <param name="descriptor">The descriptor of the JWT.</param>
 /// <returns>The array of <see cref="byte"/> representation of the JWT.</returns>
 public byte[] WriteToken(JwtDescriptor descriptor)
 {
     using var bufferWriter = new PooledByteBufferWriter();
     WriteToken(descriptor, bufferWriter);
     return(bufferWriter.WrittenSpan.ToArray());
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Writes a JWT in its compact serialization format and returns it a string.
 /// </summary>
 /// <param name="descriptor">The descriptor of the JWT.</param>
 /// <returns>The <see cref="string"/> retpresention of the JWT.</returns>
 public string WriteTokenString(JwtDescriptor descriptor)
 {
     using var bufferWriter = new PooledByteBufferWriter();
     WriteToken(descriptor, bufferWriter);
     return(Utf8.GetString(bufferWriter.WrittenSpan));
 }