예제 #1
0
    /// <summary>
    /// Sets a property in the server transaction using the specified name and value.
    /// </summary>
    /// <typeparam name="TProperty">The type of the property.</typeparam>
    /// <param name="transaction">The server transaction.</param>
    /// <param name="name">The property name.</param>
    /// <param name="value">The property value.</param>
    /// <returns>The server transaction, so that calls can be easily chained.</returns>
    public static OpenIddictServerTransaction SetProperty <TProperty>(
        this OpenIddictServerTransaction 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);
    }
예제 #2
0
        /// <summary>
        /// Retrieves the <see cref="IOwinRequest"/> instance stored in the <see cref="OpenIddictServerTransaction"/> 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 OpenIddictServerTransaction 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);
        }
예제 #3
0
        /// <summary>
        /// Retrieves the <see cref="HttpRequest"/> instance stored in the <see cref="OpenIddictServerTransaction"/> 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 OpenIddictServerTransaction 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);
        }
예제 #4
0
    /// <summary>
    /// Retrieves a property value from the server transaction using the specified name.
    /// </summary>
    /// <typeparam name="TProperty">The type of the property.</typeparam>
    /// <param name="transaction">The server transaction.</param>
    /// <param name="name">The property name.</param>
    /// <returns>The property value or <c>null</c> if it couldn't be found.</returns>
    public static TProperty?GetProperty <TProperty>(
        this OpenIddictServerTransaction 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);
    }
예제 #5
0
    public string GenerateAccessToken(IServiceProvider sp)
    {
        try
        {
            var claims = new List <Claim>
            {
                new Claim(Claims.Role, Roles.Administrator)
            };
            var identity = new ClaimsIdentity(claims);

            var options = (IOptions <OpenIddictServerOptions>)sp
                          .GetService(typeof(IOptions <OpenIddictServerOptions>));
            var logger = (ILogger <OpenIddictServerDispatcher>)sp
                         .GetService(typeof(ILogger <OpenIddictServerDispatcher>));

            var transaction = new OpenIddictServerTransaction
            {
                Options = options.Value,
                Logger  = logger
            };

            var context = new ProcessSignInContext(transaction)
            {
                Issuer = new Uri("https://localhost:5001/"),
                AccessTokenPrincipal = new ClaimsPrincipal(identity)
            };

            var generator = new GenerateIdentityModelAccessToken();
#pragma warning disable CA2012
            generator.HandleAsync(context).GetAwaiter().GetResult();
#pragma warning restore CA2012

            return(context.AccessToken);
        }
        catch (Exception)
        {
            throw;
        }
    }
예제 #6
0
 /// <summary>
 /// Creates a new instance of the <see cref="BaseRequestContext"/> class.
 /// </summary>
 protected BaseRequestContext(OpenIddictServerTransaction transaction)
     : base(transaction)
 {
 }
예제 #7
0
 /// <summary>
 /// Creates a new instance of the <see cref="ProcessAuthenticationContext"/> class.
 /// </summary>
 public ProcessAuthenticationContext(OpenIddictServerTransaction transaction)
     : base(transaction)
 {
 }
예제 #8
0
 /// <summary>
 /// Creates a new instance of the <see cref="BaseContext"/> class.
 /// </summary>
 protected BaseContext(OpenIddictServerTransaction transaction)
 => Transaction = transaction ?? throw new ArgumentNullException(nameof(transaction));
예제 #9
0
 /// <summary>
 /// Creates a new instance of the <see cref="ProcessErrorContext"/> class.
 /// </summary>
 public ProcessErrorContext(OpenIddictServerTransaction transaction)
     : base(transaction)
 {
 }
 /// <summary>
 /// Creates a new instance of the <see cref="ExtractRevocationRequestContext"/> class.
 /// </summary>
 public ExtractRevocationRequestContext(OpenIddictServerTransaction transaction)
     : base(transaction)
 {
 }
 /// <summary>
 /// Creates a new instance of the <see cref="ExtractDeviceRequestContext"/> class.
 /// </summary>
 public ExtractDeviceRequestContext(OpenIddictServerTransaction transaction)
     : base(transaction)
 {
 }
예제 #12
0
 /// <summary>
 /// Creates a new instance of the <see cref="ExtractUserinfoRequestContext"/> class.
 /// </summary>
 public ExtractUserinfoRequestContext(OpenIddictServerTransaction transaction)
     : base(transaction)
 {
 }
예제 #13
0
 /// <summary>
 /// Creates a new instance of the <see cref="ProcessChallengeResponseContext"/> class.
 /// </summary>
 public ProcessChallengeResponseContext([NotNull] OpenIddictServerTransaction transaction)
     : base(transaction)
 {
 }
예제 #14
0
 /// <summary>
 /// Creates a new instance of the <see cref="ValidateIntrospectionRequestContext"/> class.
 /// </summary>
 public ValidateIntrospectionRequestContext(OpenIddictServerTransaction transaction)
     : base(transaction)
 {
 }
예제 #15
0
 /// <summary>
 /// Creates a new instance of the <see cref="ExtractIntrospectionRequestContext"/> class.
 /// </summary>
 public ExtractIntrospectionRequestContext(OpenIddictServerTransaction transaction)
     : base(transaction)
 {
 }
 /// <summary>
 /// Creates a new instance of the <see cref="ValidateAuthorizationRequestContext"/> class.
 /// </summary>
 public ValidateAuthorizationRequestContext(OpenIddictServerTransaction transaction)
     : base(transaction)
     // Infer the redirect_uri from the value specified by the client application.
     => RedirectUri = Request?.RedirectUri;
 /// <summary>
 /// Creates a new instance of the <see cref="ExtractAuthorizationRequestContext"/> class.
 /// </summary>
 public ExtractAuthorizationRequestContext(OpenIddictServerTransaction transaction)
     : base(transaction)
 {
 }
예제 #18
0
 /// <summary>
 /// Creates a new instance of the <see cref="ExtractLogoutRequestContext"/> class.
 /// </summary>
 public ExtractLogoutRequestContext(OpenIddictServerTransaction transaction)
     : base(transaction)
 {
 }
예제 #19
0
 /// <summary>
 /// Creates a new instance of the <see cref="GenerateTokenContext"/> class.
 /// </summary>
 public GenerateTokenContext(OpenIddictServerTransaction transaction)
     : base(transaction)
 {
 }
예제 #20
0
 /// <summary>
 /// Creates a new instance of the <see cref="ValidateLogoutRequestContext"/> class.
 /// </summary>
 public ValidateLogoutRequestContext(OpenIddictServerTransaction transaction)
     : base(transaction)
     // Infer the post_logout_redirect_uri from the value specified by the client application.
     => PostLogoutRedirectUri = Request?.PostLogoutRedirectUri;
예제 #21
0
 /// <summary>
 /// Creates a new instance of the <see cref="BaseValidatingContext"/> class.
 /// </summary>
 protected BaseValidatingContext([NotNull] OpenIddictServerTransaction transaction)
     : base(transaction)
 {
 }
 /// <summary>
 /// Creates a new instance of the <see cref="ValidateDeviceRequestContext"/> class.
 /// </summary>
 public ValidateDeviceRequestContext(OpenIddictServerTransaction transaction)
     : base(transaction)
 {
 }
예제 #23
0
 /// <summary>
 /// Creates a new instance of the <see cref="ProcessSignoutResponseContext"/> class.
 /// </summary>
 public ProcessSignoutResponseContext([NotNull] OpenIddictServerTransaction transaction)
     : base(transaction)
 {
 }
예제 #24
0
 /// <summary>
 /// Creates a new instance of the <see cref="ValidateUserinfoRequestContext"/> class.
 /// </summary>
 public ValidateUserinfoRequestContext(OpenIddictServerTransaction transaction)
     : base(transaction)
 {
 }
예제 #25
0
 /// <summary>
 /// Creates a new instance of the <see cref="BaseValidatingTicketContext"/> class.
 /// </summary>
 protected BaseValidatingTicketContext(OpenIddictServerTransaction transaction)
     : base(transaction)
 {
 }
예제 #26
0
 /// <summary>
 /// Creates a new instance of the <see cref="ValidateConfigurationRequestContext"/> class.
 /// </summary>
 public ValidateConfigurationRequestContext(OpenIddictServerTransaction transaction)
     : base(transaction)
 {
 }
예제 #27
0
 /// <summary>
 /// Creates a new instance of the <see cref="ProcessRequestContext"/> class.
 /// </summary>
 public ProcessRequestContext(OpenIddictServerTransaction transaction)
     : base(transaction)
 {
 }