Class JsonJwt

Namespace
Subsembly.Json
Assembly
Subsembly.Json.dll

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

string

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

string

AuthorizedParty

A case-sensitive string that identifies the party to which the ID Token was issued.

public string AuthorizedParty { get; set; }

Property Value

string

Expiration

The value of the expiration time claim from the Payload.

public DateTime Expiration { get; set; }

Property Value

DateTime

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

string

IssuedAt

The value of the "issued at" time claim from the Payload.

public DateTime IssuedAt { get; set; }

Property Value

DateTime

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

string

NotBefore

The value of the "not before" time claim from the Payload.

public DateTime NotBefore { get; set; }

Property Value

DateTime

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

JsonObject

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

string

Methods

CreateHS256(byte[])

Creates a token with the current Payload with a HS256 signature.

public string CreateHS256(byte[] vbKey)

Parameters

vbKey byte[]

Returns

string

CreateHS256(string)

Creates a token with the current Payload with a HS256 signature.

public string CreateHS256(string sSecret)

Parameters

sSecret string

Returns

string

CreateRS256(CryRSA)

Creates a token with the current Payload with a RS256 signature.

public string CreateRS256(CryRSA aPrivateKey)

Parameters

aPrivateKey CryRSA

Returns

string

CreateUnsecured()

Creates an unsecured token carrying Payload without signature.

public string CreateUnsecured()

Returns

string

GetClaim(string)

public JsonValue GetClaim(string sFieldName)

Parameters

sFieldName string

Returns

JsonValue

IsNowValid()

Indicates whether this JWT is now valid, accoring to its NotBefore and Expiration claims.

public bool IsNowValid()

Returns

bool

ParseToken(string)

Parses the token, but does not validate it's signature, yet.

public static JsonJwt ParseToken(string sToken)

Parameters

sToken string

Returns

JsonJwt

Exceptions

JsonJwtException

Thrown, if the given token is invalid.

ArgumentNullException

The parameter sToken was null.

SetClaim(string, JsonValue)

public void SetClaim(string sFieldName, JsonValue aFieldValue)

Parameters

sFieldName string
aFieldValue JsonValue

VerifyHS256(byte[])

public bool VerifyHS256(byte[] vbKey)

Parameters

vbKey byte[]

Returns

bool

Exceptions

ArgumentNullException

The parameter vbKey was null.

InvalidOperationException

This token was not fully created or parsed, yet.

VerifyHS256(string)

public bool VerifyHS256(string sSecret)

Parameters

sSecret string

Returns

bool

Exceptions

ArgumentNullException

The parameter sSecret was null.

VerifyRS256(CryRSA)

public bool VerifyRS256(CryRSA aPublicKey)

Parameters

aPublicKey CryRSA

Returns

bool