Пример #1
0
 /// <summary>
 /// Generates a new Token for some <see cref="subject"/>
 /// </summary>
 /// <param name="subject">The subject to generate the token for</param>
 /// <param name="issuer">As who to create the token (the owner of the <see cref="signingPair"/>)</param>
 /// <param name="signingPair">The <see cref="SigningKeyPair"/> of the <see cref="issuer"/></param>
 /// <param name="expirationTime">The unix time when this token expires</param>
 /// <param name="claims">Optional additional claims to add to the token, may not be one of [iss,sub,id,iat] as these are already set</param>
 /// <returns>The newly created and signed token</returns>
 public Token GenerateNewToken(
     EntityId subject,
     EntityId issuer,
     SigningKeyPair signingPair,
     long expirationTime,
     params KeyValuePair <string, string>[] claims)
 {
     return(ConstructToken(subject, issuer, expirationTime)
            .AddClaims(claims)
            .Sign(signingPair));
 }
Пример #2
0
 /// <summary>
 /// Generates a new Token for some <see cref="subject"/>
 /// </summary>
 /// <param name="subject">The subject to generate the token for</param>
 /// <param name="issuer">As who to create the token</param>
 /// <param name="signingPair">The <see cref="SigningKeyPair"/> of the <see cref="issuer"/></param>
 /// <param name="claims">Optional additional claims to add to the token, may not be one of [iss,sub,id,iat] as these are already set</param>
 /// <returns>The newly created and signed token</returns>
 public Token GenerateNewToken(
     EntityId subject,
     EntityId issuer,
     SigningKeyPair signingPair,
     params KeyValuePair <string, string>[] claims)
 {
     return(new Token()
            .AddClaim("iss", issuer.ToString())
            .AddClaim("sub", subject.ToString())
            .AddClaim("id", ThreadSaveIdGenerator.NextId.ToString())
            .AddClaim("iat", DateTime.UtcNow.ToFileTimeUtc().ToString())
            .AddClaims(claims)
            .Sign(signingPair));
 }
Пример #3
0
 /// <summary>
 /// Signs the Token with a KeyPair
 /// </summary>
 /// <param name="keyPair">The keypair to use to sign the token</param>
 public Token Sign(SigningKeyPair keyPair)
 {
     signature.algorythm = keyPair.algorythm;
     signature.GenerateSignature(SignableContent, keyPair);
     return(this);
 }
Пример #4
0
 public SecureReference(SigningKeyPair keyPair)
 {
     KeyPair = keyPair;
 }
Пример #5
0
 /// <summary>
 /// Adds a new Signing KeyPair and persists it
 /// </summary>
 /// <param name="owner">The owner of the keyPair</param>
 /// <param name="keyPair"></param>
 public void AddSigningKeyPair(EntityId owner, SigningKeyPair keyPair)
 {
     signingKeyPairs.Add(owner, keyPair);
 }