-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made Decoder, Serializer to accept Type. Added PayloadType to JwtAuth…
…enticationOptions. (#375) * Bumped version of JWT to 10.0.0-beta1 * Bumped version of JWT.Extensions.AspNetCore to 9.0.0-beta1 * Made methods on Decoder, Serializer non-generic, to accept Type rather than <T> * Added PayloadType to JwtAuthenticationOptions * Made DefaultIdentityFactory to use PayloadType rather than always Dictionary<string, string>
- Loading branch information
1 parent
d4dee86
commit d7d76fb
Showing
11 changed files
with
227 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 14 additions & 2 deletions
16
src/JWT.Extensions.AspNetCore/Factories/IIdentityFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,22 @@ | ||
using System.Collections.Generic; | ||
using System; | ||
using System.Security.Principal; | ||
|
||
namespace JWT.Extensions.AspNetCore.Factories | ||
{ | ||
public interface IIdentityFactory | ||
{ | ||
IIdentity CreateIdentity(IDictionary<string, string> payload); | ||
/// <summary> | ||
/// Creates <see cref="IIdentity" /> from the payload of the specified type. | ||
/// </summary> | ||
IIdentity CreateIdentity(Type type, object payload); | ||
} | ||
|
||
/// <summary> | ||
/// Extension methods for <seealso cref="IIdentityFactory" /> | ||
///</summary> | ||
public static class IdentityFactoryExtensions | ||
{ | ||
public static IIdentity CreateIdentity<T>(this IIdentityFactory factory, T payload) => | ||
factory.CreateIdentity(typeof(T), payload); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,41 @@ | ||
namespace JWT | ||
using System; | ||
|
||
namespace JWT | ||
{ | ||
/// <summary> | ||
/// Provides JSON Serialize and Deserialize. Allows custom serializers used. | ||
/// Provides JSON Serialize and Deserialize. Allows custom serializers used. | ||
/// </summary> | ||
public interface IJsonSerializer | ||
{ | ||
/// <summary> | ||
/// Serialize an object to JSON string | ||
/// Serializes an object to a JSON string. | ||
/// </summary> | ||
/// <param name="obj">object</param> | ||
/// <param name="obj">The object to serialize.</param> | ||
/// <returns>JSON string</returns> | ||
string Serialize(object obj); | ||
|
||
/// <summary> | ||
/// Deserialize a JSON string to typed object. | ||
/// Deserializes a JSON string to an object of specified type. | ||
/// </summary> | ||
/// <param name="type">The type of the object to deserialize to.</param> | ||
/// <param name="json">The JSON string deserialize.</param> | ||
/// <returns>Strongly-typed object.</returns> | ||
object Deserialize(Type type, string json); | ||
} | ||
|
||
/// <summary> | ||
/// Extension methods for <seealso cref="IJsonSerializer" /> | ||
///</summary> | ||
public static class JsonSerializerExtensions | ||
{ | ||
/// <summary> | ||
/// Deserializes a JSON string to an object of specified type. | ||
/// </summary> | ||
/// <typeparam name="T">type of object</typeparam> | ||
/// <typeparam name="T">The type of the object to deserialize to.</typeparam> | ||
/// <param name="jsonSerializer">The JSON serializer instance.</param> | ||
/// <param name="json">JSON string</param> | ||
/// <returns>Strongly-typed object</returns> | ||
T Deserialize<T>(string json); | ||
/// <returns>Strongly-typed object.</returns> | ||
public static T Deserialize<T>(this IJsonSerializer jsonSerializer, string json) => | ||
(T)jsonSerializer.Deserialize(typeof(T), json); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.