Esempio n. 1
0
    /// <summary>
    /// Sets a property in the client transaction using the specified name and value.
    /// </summary>
    /// <typeparam name="TProperty">The type of the property.</typeparam>
    /// <param name="transaction">The client transaction.</param>
    /// <param name="name">The property name.</param>
    /// <param name="value">The property value.</param>
    /// <returns>The client transaction, so that calls can be easily chained.</returns>
    public static OpenIddictClientTransaction SetProperty <TProperty>(
        this OpenIddictClientTransaction 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="IOwinRequest"/> instance stored in the <see cref="OpenIddictClientTransaction"/> properties.
    /// </summary>
    /// <param name="transaction">The transaction instance.</param>
    /// <returns>The <see cref="IOwinRequest"/> instance or <see langword="null"/> if it couldn't be found.</returns>
    public static IOwinRequest?GetOwinRequest(this OpenIddictClientTransaction 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);
    }
Esempio n. 3
0
    /// <summary>
    /// Retrieves a property value from the client transaction using the specified name.
    /// </summary>
    /// <typeparam name="TProperty">The type of the property.</typeparam>
    /// <param name="transaction">The client 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 OpenIddictClientTransaction 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);
    }
Esempio n. 4
0
 /// <summary>
 /// Creates a new instance of the <see cref="ProcessErrorContext"/> class.
 /// </summary>
 public ProcessErrorContext(OpenIddictClientTransaction transaction)
     : base(transaction)
 {
 }
Esempio n. 5
0
 /// <summary>
 /// Creates a new instance of the <see cref="ProcessRequestContext"/> class.
 /// </summary>
 public ProcessRequestContext(OpenIddictClientTransaction transaction)
     : base(transaction)
 {
 }
Esempio n. 6
0
 /// <summary>
 /// Creates a new instance of the <see cref="BaseContext"/> class.
 /// </summary>
 protected BaseContext(OpenIddictClientTransaction transaction)
 => Transaction = transaction ?? throw new ArgumentNullException(nameof(transaction));
Esempio n. 7
0
 /// <summary>
 /// Creates a new instance of the <see cref="BaseValidatingTicketContext"/> class.
 /// </summary>
 protected BaseValidatingTicketContext(OpenIddictClientTransaction transaction)
     : base(transaction)
 {
 }
Esempio n. 8
0
 /// <summary>
 /// Creates a new instance of the <see cref="BaseRequestContext"/> class.
 /// </summary>
 protected BaseExternalContext(OpenIddictClientTransaction transaction)
     : base(transaction)
 {
 }
Esempio n. 9
0
 /// <summary>
 /// Creates a new instance of the <see cref="ApplyTokenRequestContext"/> class.
 /// </summary>
 public ApplyTokenRequestContext(OpenIddictClientTransaction 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 <see langword="null"/> if it couldn't be found.</returns>
 public static HttpRequestMessage?GetHttpRequestMessage(this OpenIddictClientTransaction transaction)
 => transaction.GetProperty <HttpRequestMessage>(typeof(HttpRequestMessage).FullName !);
 /// <summary>
 /// Creates a new instance of the <see cref="PrepareUserinfoRequestContext"/> class.
 /// </summary>
 public PrepareUserinfoRequestContext(OpenIddictClientTransaction transaction)
     : base(transaction)
 {
 }
Esempio n. 12
0
 /// <summary>
 /// Creates a new instance of the <see cref="PrepareAuthorizationRequestContext"/> class.
 /// </summary>
 public ApplyAuthorizationRequestContext(OpenIddictClientTransaction transaction)
     : base(transaction)
 {
 }
 /// <summary>
 /// Creates a new instance of the <see cref="PrepareConfigurationRequestContext"/> class.
 /// </summary>
 public PrepareConfigurationRequestContext(OpenIddictClientTransaction transaction)
     : base(transaction)
 {
 }
Esempio n. 14
0
 /// <summary>
 /// Creates a new instance of the <see cref="ProcessAuthenticationContext"/> class.
 /// </summary>
 public ProcessAuthenticationContext(OpenIddictClientTransaction transaction)
     : base(transaction)
 {
 }
 /// <summary>
 /// Creates a new instance of the <see cref="GenerateTokenContext"/> class.
 /// </summary>
 public GenerateTokenContext(OpenIddictClientTransaction transaction)
     : base(transaction)
 {
 }
Esempio n. 16
0
 /// <summary>
 /// Creates a new instance of the <see cref="BaseRequestContext"/> class.
 /// </summary>
 protected BaseRequestContext(OpenIddictClientTransaction transaction)
     : base(transaction)
 {
 }
Esempio n. 17
0
 /// <summary>
 /// Creates a new instance of the <see cref="PrepareTokenRequestContext"/> class.
 /// </summary>
 public PrepareTokenRequestContext(OpenIddictClientTransaction transaction)
     : base(transaction)
 {
 }