Ejemplo n.º 1
0
 /// <summary>
 /// Given a JWT, decodes it and return the payload.
 /// </summary>
 /// <param name="decoder">The decoder instance</param>
 /// <param name="token">The JWT</param>
 /// <returns>A string containing the JSON payload</returns>
 /// <exception cref="ArgumentException" />
 /// <exception cref="ArgumentOutOfRangeException" />
 /// <exception cref="InvalidTokenPartsException" />
 public static string Decode(this IJwtDecoder decoder, string token) =>
 decoder.Decode(new JwtParts(token));
Ejemplo n.º 2
0
 /// <summary>
 /// Given a JWT, decodes it and return the payload.
 /// </summary>
 /// <param name="decoder">The decoder instance</param>
 /// <param name="jwt">The JWT</param>
 /// <returns>A string containing the JSON payload</returns>
 public static string Decode(this IJwtDecoder decoder, JwtParts jwt) =>
 decoder.Decode(jwt, (byte[])null, verify: false);
Ejemplo n.º 3
0
 public bool VerifyToken(IJwtDecoder jwtDecoder, string token, JwtOptions options)
 {
     return(jwtDecoder.TryDecode(token, options.SecretBytes, out string result));
 }
Ejemplo n.º 4
0
 public static IDictionary <string, string> DecodeHeaderToDictionary(this IJwtDecoder decoder, string token) =>
 decoder.DecodeHeader <Dictionary <string, string> >(token);
Ejemplo n.º 5
0
 public static IDictionary <string, object> DecodeToObject(this IJwtDecoder decoder, string token, string[] keys, bool verify) =>
 decoder.DecodeToObject(token, GetBytes(keys), verify);
Ejemplo n.º 6
0
 /// <summary>
 /// Sets JWT decoder.
 /// </summary>
 /// <returns>Current builder instance</returns>
 public JwtBuilder WithDecoder(IJwtDecoder decoder)
 {
     _decoder = decoder;
     return(this);
 }
Ejemplo n.º 7
0
 public JWTService(IJWTSettings jwtSettings, IJwtDecoder jwtDecoder, IJwtEncoder jwtEncoder)
 {
     _key     = jwtSettings.Key;
     _decoder = jwtDecoder;
     _encoder = jwtEncoder;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Given a JWT, decodes it and return the payload as an object.
 /// </summary>
 /// <typeparam name="T">The type to return</typeparam>
 /// <param name="decoder">The decoder instance</param>
 /// <param name="token">The JWT</param>
 /// <returns>An object representing the payload</returns>
 public static T DecodeToObject <T>(this IJwtDecoder decoder, string token) =>
 decoder.DecodeToObject <T>(new JwtParts(token));
Ejemplo n.º 9
0
 /// <summary>
 /// Given a JWT, decodes it and return the payload as an object.
 /// </summary>
 /// <typeparam name="T">The type to return</typeparam>
 /// <param name="decoder">The decoder instance</param>
 /// <param name="token">The JWT</param>
 /// <param name="keys">The keys provided which one of them was used to sign the JWT</param>
 /// <param name="verify">Whether to verify the signature (default is true)</param>
 /// <returns>An object representing the payload</returns>
 public static T DecodeToObject <T>(this IJwtDecoder decoder, string token, string[] keys, bool verify) =>
 decoder.DecodeToObject <T>(token, keys is object?GetBytes(keys) : null, verify);
Ejemplo n.º 10
0
 public JwtController(IJwtEncoder jwtEncoder, IJwtDecoder jwtDecoder)
 {
     _jwtEncoder = jwtEncoder;
     _jwtDecoder = jwtDecoder;
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Given a JWT, decodes it and return the payload as an object.
 /// </summary>
 /// <typeparam name="T">The type to return</typeparam>
 /// <param name="decoder">The decoder instance</param>
 /// <param name="token">The JWT</param>
 /// <param name="key">The key that was used to sign the JWT</param>
 /// <param name="verify">Whether to verify the signature (default is true)</param>
 /// <returns>An object representing the payload</returns>
 public static T DecodeToObject <T>(this IJwtDecoder decoder, string token, byte[] key, bool verify) =>
 decoder.DecodeToObject <T>(new JwtParts(token), key, verify);
Ejemplo n.º 12
0
 /// <summary>
 /// Given a JWT, decodes it and return the payload as an object.
 /// </summary>
 /// <typeparam name="T">The type to return</typeparam>
 /// <param name="decoder">The decoder instance</param>
 /// <param name="token">The JWT</param>
 /// <param name="key">The key that was used to sign the JWT</param>
 /// <param name="verify">Whether to verify the signature (default is true)</param>
 /// <returns>An object representing the payload</returns>
 public static T DecodeToObject <T>(this IJwtDecoder decoder, string token, string key, bool verify) =>
 decoder.DecodeToObject <T>(token, GetBytes(key), verify);
Ejemplo n.º 13
0
 /// <summary>
 /// Given a JWT, decodes it and return the payload as a dictionary.
 /// </summary>
 /// <param name="decoder">The decoder instance</param>
 /// <param name="token">The JWT</param>
 /// <param name="keys">The keys that were used to sign the JWT</param>
 /// <param name="verify">Whether to verify the signature (default is true)</param>
 /// <returns>A string containing the JSON payload</returns>
 /// <exception cref="ArgumentException" />
 /// <exception cref="ArgumentOutOfRangeException" />
 /// <exception cref="InvalidTokenPartsException" />
 public static IDictionary <string, object> DecodeToObject(this IJwtDecoder decoder, string token, byte[][] keys, bool verify) =>
 decoder.DecodeToObject <Dictionary <string, object> >(new JwtParts(token), keys, verify);
Ejemplo n.º 14
0
 /// <summary>
 /// Given a JWT, decodes it and return the payload.
 /// </summary>
 /// <param name="decoder">The decoder instance</param>
 /// <param name="token">The JWT</param>
 /// <param name="keys">The keys that were used to sign the JWT</param>
 /// <param name="verify">Whether to verify the signature (default is true)</param>
 /// <returns>A string containing the JSON payload</returns>
 /// <exception cref="ArgumentException" />
 /// <exception cref="ArgumentOutOfRangeException" />
 /// <exception cref="InvalidTokenPartsException" />
 public static string Decode(this IJwtDecoder decoder, string token, byte[][] keys, bool verify) =>
 decoder.Decode(new JwtParts(token), keys, verify);
Ejemplo n.º 15
0
 public TokenFactory(IJwtEncoder encoder, IJwtDecoder decoder)
 {
     _encoder = encoder;
     _decoder = decoder;
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Given a JWT, decodes it and return the payload as an dictionary.
 /// </summary>
 /// <param name="decoder">The decoder instance</param>
 /// <param name="token">The JWT</param>
 /// <param name="keys">The key which one of them was used to sign the JWT</param>
 /// <param name="verify">Whether to verify the signature (default is true)</param>
 /// <returns>An object representing the payload</returns>
 /// <exception cref="ArgumentException" />
 /// <exception cref="ArgumentOutOfRangeException" />
 public static string Decode(this IJwtDecoder decoder, string token, string[] keys, bool verify) =>
 decoder.Decode(token, GetBytes(keys), verify);
Ejemplo n.º 17
0
 public LoggedInHelper(IHttpContextAccessor httpContextAccessor, CurrentEnvironment environment, IJwtDecoder decoder, ILogger <LoggedInHelper> logger)
 {
     _httpContextAccessor = httpContextAccessor;
     _environment         = environment;
     _decoder             = decoder;
     _logger = logger;
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Given a JWT, decodes it and return the payload as a dictionary.
 /// </summary>
 /// <param name="decoder">The decoder instance</param>
 /// <param name="token">The JWT</param>
 /// <returns>An object representing the payload</returns>
 public static IDictionary <string, object> DecodeToObject(this IJwtDecoder decoder, string token) =>
 decoder.DecodeToObject <Dictionary <string, object> >(token);
Ejemplo n.º 19
0
 public TokenJwtBinder(string secret)
 {
     validator = new JwtValidator(serializer, provider);
     decoder   = new JwtDecoder(serializer, validator, urlEncoder);
     _secret   = secret;
 }