public IDictionary <string, string> ToParameters() { IDictionary <string, string> parameters = new Dictionary <string, string>(); #if DESKTOP || NETSTANDARD1_3 if (ClientCredential != null) { if (!string.IsNullOrEmpty(ClientCredential.Secret)) { parameters[OAuth2Parameter.ClientSecret] = ClientCredential.Secret; } else { if (ClientCredential.Assertion == null || ClientCredential.ValidTo != 0) { bool assertionNearExpiry = (ClientCredential.ValidTo <= Jwt.JsonWebToken.ConvertToTimeT(DateTime.UtcNow + TimeSpan.FromMinutes( Constants .ExpirationMarginInMinutes))); if (assertionNearExpiry) { const string msg = "Client Assertion does not exist or near expiry."; RequestContext.Logger.Info(msg); RequestContext.Logger.InfoPii(msg); Jwt.JsonWebToken jwtToken = new Jwt.JsonWebToken(ClientId, Authority.SelfSignedJwtAudience); ClientCredential.Assertion = jwtToken.Sign(ClientCredential.Certificate); ClientCredential.ValidTo = jwtToken.Payload.ValidTo; } else { const string msg = "Reusing the unexpired Client Assertion..."; RequestContext.Logger.Info(msg); RequestContext.Logger.InfoPii(msg); } } parameters[OAuth2Parameter.ClientAssertionType] = OAuth2AssertionType.JwtBearer; parameters[OAuth2Parameter.ClientAssertion] = ClientCredential.Assertion; } } #endif return(parameters); }
public IDictionary <string, string> ToParameters() { IDictionary <string, string> parameters = new Dictionary <string, string>(); #if DESKTOP || NETSTANDARD1_3 || NET_CORE if (ClientCredential != null) { if (!string.IsNullOrEmpty(ClientCredential.Secret)) { parameters[OAuth2Parameter.ClientSecret] = ClientCredential.Secret; } else { if (ClientCredential.Assertion == null || ClientCredential.ValidTo != 0) { if (!RequestValidationHelper.ValidateClientAssertion(this)) { RequestContext.Logger.Info("Client Assertion does not exist or near expiry."); var jwtToken = new Jwt.JsonWebToken(ClientId, Authority.SelfSignedJwtAudience); ClientCredential.Assertion = jwtToken.Sign(ClientCredential.Certificate, SendCertificate); ClientCredential.ValidTo = jwtToken.Payload.ValidTo; ClientCredential.ContainsX5C = SendCertificate; ClientCredential.Audience = Authority.SelfSignedJwtAudience; } else { RequestContext.Logger.Info("Reusing the unexpired Client Assertion..."); } } parameters[OAuth2Parameter.ClientAssertionType] = OAuth2AssertionType.JwtBearer; parameters[OAuth2Parameter.ClientAssertion] = ClientCredential.Assertion; } } #endif return(parameters); }