private string GenerateTokenSegmentFromEnvelope(JsonWebTokenEnvelope envelope) { //zumo takes the kid is a string var header = new { alg = envelope.Algorithm, typ = envelope.Type, kid = envelope.KeyId.ToString() }; byte[] headerBytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(header, Formatting.None)); return(this.Base64UrlEncode(headerBytes)); }
public JsonWebToken(JsonWebTokenClaims claims, dynamic credentials, JsonWebTokenEnvelope envelope, string key) { this.Envelope = envelope; this.envelopeTokenSegment = GenerateTokenSegmentFromEnvelope(Envelope); this.Claims = claims; this.Claims.Credentials = credentials; this.Claims.CryptedCredentials = EncryptCredentials(credentials, key); this.claimsTokenSegment = GenerateTokenSegmentFromClaims(Claims); this.Signature = BuildSignature(key); }
private void ValidateEnvelope(JsonWebTokenEnvelope envelope) { if (envelope.Type != "JWT") { throw new Exception("Unsupported token type"); } if (envelope.Algorithm != "HS256") { throw new Exception("Unsupported crypto algorithm"); } }
private string GenerateTokenSegmentFromEnvelope(JsonWebTokenEnvelope envelope) { //zumo takes the kid is a string var header = new { alg = envelope.Algorithm, typ = envelope.Type, kid = envelope.KeyId.ToString()}; byte[] headerBytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(header, Formatting.None)); return this.Base64UrlEncode(headerBytes); }