public void AddToParameters(IDictionary<string, string> parameters) { if (this.ClientId != null) { parameters[OAuthParameter.ClientId] = this.ClientId; } if (this.Credential != null) { if (!string.IsNullOrEmpty(this.Credential.Secret)) { parameters[OAuthParameter.ClientSecret] = this.Credential.Secret; } else { ClientAssertion clientAssertion = this.Credential.ClientAssertion; if (clientAssertion == null || this.Credential.ValidTo != 0) { bool assertionNearExpiry = (this.Credential.ValidTo <= JsonWebToken.ConvertToTimeT(DateTime.UtcNow + TimeSpan.FromMinutes( Constant.ExpirationMarginInMinutes))); if (assertionNearExpiry) { JsonWebToken jwtToken = new JsonWebToken(this.ClientId, this.Authenticator.SelfSignedJwtAudience); clientAssertion = jwtToken.Sign(this.Credential.Certificate); this.Credential.ValidTo = jwtToken.Payload.ValidTo; this.Credential.ClientAssertion = clientAssertion; } } parameters[OAuthParameter.ClientAssertionType] = clientAssertion.AssertionType; parameters[OAuthParameter.ClientAssertion] = clientAssertion.Assertion; } } else if (this.Assertion != null) { parameters[OAuthParameter.ClientAssertionType] = this.Assertion.AssertionType; parameters[OAuthParameter.ClientAssertion] = this.Assertion.Assertion; } }