Class JsonJwt
Represents a JSON Web Token (JWT).
public class JsonJwt
- Inheritance
-
JsonJwt
- Inherited Members
Remarks
Supports creating, parsing and validating JWT tokens.
Constructors
JsonJwt()
public JsonJwt()
JsonJwt(JsonObject)
public JsonJwt(JsonObject jsPayload)
Parameters
jsPayload
JsonObject
Properties
Algorithm
public string Algorithm { get; }
Property Value
Audience
Either a single case-sensitive string or URI or an array of such values that uniquely identify the intended recipients of this JWT.In other words, when this claim is present, the party reading the data in this JWT must find itself in the aud claim or disregard the data contained in the JWT. As in the case of the iss and sub claims, this claim is application specific.
public string Audience { get; set; }
Property Value
AuthorizedParty
A case-sensitive string that identifies the party to which the ID Token was issued.
public string AuthorizedParty { get; set; }
Property Value
Expiration
The value of the expiration time claim from the Payload.
public DateTime Expiration { get; set; }
Property Value
Remarks
If there is no Payload, or it does not contain an exp
field,
then this property returns DateTime.MaxValue.
Identifier
A string representing a unique identifier for this JWT. This claim may be used to differentiate JWTs with other similar content(preventing replays, for instance). It is up to the implementation to guarantee uniqueness.
public string Identifier { get; set; }
Property Value
IssuedAt
The value of the "issued at" time claim from the Payload.
public DateTime IssuedAt { get; set; }
Property Value
Remarks
If there is no Payload, or it does not contain an iat
field,
then this property returns DateTime.MinValue.
Issuer
A case-sensitive string or URI that uniquely identifies the party that issued the JWT.Its interpretation is application specific (there is no central authority managing issuers).
public string Issuer { get; set; }
Property Value
NotBefore
The value of the "not before" time claim from the Payload.
public DateTime NotBefore { get; set; }
Property Value
Remarks
If there is no Payload, or it does not contain an nbf
field,
then this property returns DateTime.MinValue.
Payload
public JsonObject Payload { get; set; }
Property Value
Subject
A case-sensitive string or URI that uniquely identifies the party that this JWT carries information about. In other words, the claims contained in this JWT are statements about this party.The JWT spec specifies that this claim must be unique in the context of the issuer or, in cases where that is not possible, globally unique. Handling of this claim is application specific.
public string Subject { get; set; }
Property Value
Methods
CreateHS256(byte[])
Creates a token with the current Payload with a HS256 signature.
public string CreateHS256(byte[] vbKey)
Parameters
vbKey
byte[]
Returns
CreateHS256(string)
Creates a token with the current Payload with a HS256 signature.
public string CreateHS256(string sSecret)
Parameters
sSecret
string
Returns
CreateRS256(CryRSA)
Creates a token with the current Payload with a RS256 signature.
public string CreateRS256(CryRSA aPrivateKey)
Parameters
aPrivateKey
CryRSA
Returns
CreateUnsecured()
Creates an unsecured token carrying Payload without signature.
public string CreateUnsecured()
Returns
GetClaim(string)
public JsonValue GetClaim(string sFieldName)
Parameters
sFieldName
string
Returns
IsNowValid()
Indicates whether this JWT is now valid, accoring to its NotBefore and Expiration claims.
public bool IsNowValid()
Returns
ParseToken(string)
Parses the token, but does not validate it's signature, yet.
public static JsonJwt ParseToken(string sToken)
Parameters
sToken
string
Returns
Exceptions
- JsonJwtException
Thrown, if the given token is invalid.
- ArgumentNullException
The parameter
sToken
wasnull
.
SetClaim(string, JsonValue)
public void SetClaim(string sFieldName, JsonValue aFieldValue)
Parameters
VerifyHS256(byte[])
public bool VerifyHS256(byte[] vbKey)
Parameters
vbKey
byte[]
Returns
Exceptions
- ArgumentNullException
The parameter
vbKey
wasnull
.- InvalidOperationException
This token was not fully created or parsed, yet.
VerifyHS256(string)
public bool VerifyHS256(string sSecret)
Parameters
sSecret
string
Returns
Exceptions
- ArgumentNullException
The parameter
sSecret
wasnull
.
VerifyRS256(CryRSA)
public bool VerifyRS256(CryRSA aPublicKey)
Parameters
aPublicKey
CryRSA