public override Task ExtractUserinfoRequest([NotNull] ExtractUserinfoRequestContext context)
        {
            // Note: when enabling the userinfo endpoint, OpenIddict users are intended
            // to handle the userinfo requests in their own code (e.g in a MVC controller).
            // To avoid validating the access token twice, the default logic enforced by
            // the OpenID Connect server is bypassed using the ExtractUserinfoRequest event,
            // which is invoked before the access token is extracted from the userinfo request.

            // Invoke the rest of the pipeline to allow
            // the user code to handle the userinfo request.
            context.SkipHandler();

            return(Task.CompletedTask);
        }
                /// <summary>
                /// Processes the event.
                /// </summary>
                /// <param name="context">The context associated with the event to process.</param>
                /// <returns>
                /// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
                /// </returns>
                public async ValueTask HandleAsync([NotNull] ProcessRequestContext context)
                {
                    if (context == null)
                    {
                        throw new ArgumentNullException(nameof(context));
                    }

                    if (context.EndpointType != OpenIddictServerEndpointType.Userinfo)
                    {
                        return;
                    }

                    var notification = new ExtractUserinfoRequestContext(context.Transaction);
                    await _provider.DispatchAsync(notification);

                    if (notification.IsRequestHandled)
                    {
                        context.HandleRequest();
                        return;
                    }

                    else if (notification.IsRequestSkipped)
                    {
                        context.SkipRequest();
                        return;
                    }

                    else if (notification.IsRejected)
                    {
                        context.Reject(
                            error: notification.Error ?? Errors.InvalidRequest,
                            description: notification.ErrorDescription,
                            uri: notification.ErrorUri);
                        return;
                    }

                    if (notification.Request == null)
                    {
                        throw new InvalidOperationException(new StringBuilder()
                                                            .Append("The userinfo request was not correctly extracted. To extract userinfo requests, ")
                                                            .Append("create a class implementing 'IOpenIddictServerHandler<ExtractUserinfoRequestContext>' ")
                                                            .AppendLine("and register it using 'services.AddOpenIddict().AddServer().AddEventHandler()'.")
                                                            .ToString());
                    }

                    context.Logger.LogInformation("The userinfo request was successfully extracted: {Request}.", notification.Request);
                }
Example #3
0
            /// <inheritdoc/>
            public async ValueTask HandleAsync(ProcessRequestContext context)
            {
                if (context is null)
                {
                    throw new ArgumentNullException(nameof(context));
                }

                var notification = new ExtractUserinfoRequestContext(context.Transaction);
                await _dispatcher.DispatchAsync(notification);

                if (notification.IsRequestHandled)
                {
                    context.HandleRequest();
                    return;
                }

                else if (notification.IsRequestSkipped)
                {
                    context.SkipRequest();
                    return;
                }

                else if (notification.IsRejected)
                {
                    context.Reject(
                        error: notification.Error ?? Errors.InvalidRequest,
                        description: notification.ErrorDescription,
                        uri: notification.ErrorUri);
                    return;
                }

                if (notification.Request is null)
                {
                    throw new InvalidOperationException(SR.GetResourceString(SR.ID0053));
                }

                context.Logger.LogInformation(SR.GetResourceString(SR.ID6129), notification.Request);
            }