/// <summary> /// Sets a property in the validation transaction using the specified name and value. /// </summary> /// <typeparam name="TProperty">The type of the property.</typeparam> /// <param name="transaction">The validation transaction.</param> /// <param name="name">The property name.</param> /// <param name="value">The property value.</param> /// <returns>The validation transaction, so that calls can be easily chained.</returns> public static OpenIddictValidationTransaction SetProperty <TProperty>( this OpenIddictValidationTransaction transaction, string name, TProperty?value) where TProperty : class { if (transaction is null) { throw new ArgumentNullException(nameof(transaction)); } if (string.IsNullOrEmpty(name)) { throw new ArgumentException(SR.GetResourceString(SR.ID0106), nameof(name)); } if (value is null) { transaction.Properties.Remove(name); } else { transaction.Properties[name] = value; } return(transaction); }
/// <summary> /// Retrieves the <see cref="HttpRequest"/> instance stored in the <see cref="OpenIddictValidationTransaction"/> properties. /// </summary> /// <param name="transaction">The transaction instance.</param> /// <returns>The <see cref="HttpRequest"/> instance or <c>null</c> if it couldn't be found.</returns> public static HttpRequest GetHttpRequest([NotNull] this OpenIddictValidationTransaction transaction) { if (transaction == null) { throw new ArgumentNullException(nameof(transaction)); } if (!transaction.Properties.TryGetValue(typeof(HttpRequest).FullName, out object property)) { return(null); } if (property is WeakReference <HttpRequest> reference && reference.TryGetTarget(out HttpRequest request)) { return(request); } return(null); }
/// <summary> /// Retrieves the <see cref="IOwinRequest"/> instance stored in the <see cref="OpenIddictValidationTransaction"/> properties. /// </summary> /// <param name="transaction">The transaction instance.</param> /// <returns>The <see cref="IOwinRequest"/> instance or <c>null</c> if it couldn't be found.</returns> public static IOwinRequest?GetOwinRequest(this OpenIddictValidationTransaction transaction) { if (transaction is null) { throw new ArgumentNullException(nameof(transaction)); } if (!transaction.Properties.TryGetValue(typeof(IOwinRequest).FullName !, out object?property)) { return(null); } if (property is WeakReference <IOwinRequest> reference && reference.TryGetTarget(out IOwinRequest? request)) { return(request); } return(null); }
/// <summary> /// Retrieves a property value from the validation transaction using the specified name. /// </summary> /// <typeparam name="TProperty">The type of the property.</typeparam> /// <param name="transaction">The validation transaction.</param> /// <param name="name">The property name.</param> /// <returns>The property value or <see langword="null"/> if it couldn't be found.</returns> public static TProperty?GetProperty <TProperty>( this OpenIddictValidationTransaction transaction, string name) where TProperty : class { if (transaction is null) { throw new ArgumentNullException(nameof(transaction)); } if (string.IsNullOrEmpty(name)) { throw new ArgumentException(SR.GetResourceString(SR.ID0106), nameof(name)); } if (transaction.Properties.TryGetValue(name, out var property) && property is TProperty result) { return(result); } return(null); }
/// <summary> /// Creates a new instance of the <see cref="PrepareConfigurationRequestContext"/> class. /// </summary> public PrepareConfigurationRequestContext(OpenIddictValidationTransaction transaction) : base(transaction) { }
/// <summary> /// Creates a new instance of the <see cref="ApplyIntrospectionRequestContext"/> class. /// </summary> public ApplyIntrospectionRequestContext(OpenIddictValidationTransaction transaction) : base(transaction) { }
/// <summary> /// Creates a new instance of the <see cref="ValidateTokenContext"/> class. /// </summary> public ValidateTokenContext(OpenIddictValidationTransaction transaction) : base(transaction) { }
/// <summary> /// Creates a new instance of the <see cref="ProcessAuthenticationContext"/> class. /// </summary> public ProcessAuthenticationContext(OpenIddictValidationTransaction transaction) : base(transaction) { }
/// <summary> /// Creates a new instance of the <see cref="BaseRequestContext"/> class. /// </summary> protected BaseRequestContext(OpenIddictValidationTransaction transaction) : base(transaction) { }
/// <summary> /// Creates a new instance of the <see cref="ProcessErrorContext"/> class. /// </summary> public ProcessErrorContext(OpenIddictValidationTransaction transaction) : base(transaction) { }
/// <summary> /// Creates a new instance of the <see cref="BaseContext"/> class. /// </summary> protected BaseContext(OpenIddictValidationTransaction transaction) => Transaction = transaction ?? throw new ArgumentNullException(nameof(transaction));
/// <summary> /// Creates a new instance of the <see cref="ProcessRequestContext"/> class. /// </summary> public ProcessRequestContext(OpenIddictValidationTransaction transaction) : base(transaction) { }
/// <summary> /// Creates a new instance of the <see cref="BaseValidatingContext"/> class. /// </summary> protected BaseValidatingContext(OpenIddictValidationTransaction transaction) : base(transaction) { }
/// <summary> /// Creates a new instance of the <see cref="BaseRequestContext"/> class. /// </summary> protected BaseExternalContext(OpenIddictValidationTransaction transaction) : base(transaction) { }
/// <summary> /// Gets the <see cref="HttpRequestMessage"/> associated with the current context. /// </summary> /// <param name="transaction">The transaction instance.</param> /// <returns>The <see cref="HttpRequestMessage"/> instance or <c>null</c> if it couldn't be found.</returns> public static HttpRequestMessage?GetHttpRequestMessage(this OpenIddictValidationTransaction transaction) => transaction.GetProperty <HttpRequestMessage>(typeof(HttpRequestMessage).FullName !);
/// <summary> /// Gets the <see cref="HttpResponseMessage"/> associated with the current context. /// </summary> /// <param name="transaction">The transaction instance.</param> /// <returns>The <see cref="HttpResponseMessage"/> instance or <c>null</c> if it couldn't be found.</returns> public static HttpResponseMessage GetHttpResponseMessage([NotNull] this OpenIddictValidationTransaction transaction) => transaction.GetProperty <HttpResponseMessage>(typeof(HttpResponseMessage).FullName);