Example #1
0
        /// <summary>
        /// Gets an authentication response from a Provider.
        /// </summary>
        /// <param name="httpRequestInfo">The HTTP request that may be carrying an authentication response from the Provider.</param>
        /// <returns>The processed authentication response if there is any; <c>null</c> otherwise.</returns>
        public IAuthenticationResponse GetResponse(HttpRequestInfo httpRequestInfo)
        {
            Contract.Requires <ArgumentNullException>(httpRequestInfo != null);
            try {
                var message = this.Channel.ReadFromRequest(httpRequestInfo);
                PositiveAssertionResponse positiveAssertion;
                NegativeAssertionResponse negativeAssertion;
                IndirectSignedResponse    positiveExtensionOnly;
                if ((positiveAssertion = message as PositiveAssertionResponse) != null)
                {
                    if (this.EndpointFilter != null)
                    {
                        // We need to make sure that this assertion is coming from an endpoint
                        // that the host deems acceptable.
                        var providerEndpoint = new SimpleXrdsProviderEndpoint(positiveAssertion);
                        ErrorUtilities.VerifyProtocol(
                            this.EndpointFilter(providerEndpoint),
                            OpenIdStrings.PositiveAssertionFromNonWhitelistedProvider,
                            providerEndpoint.Uri);
                    }

                    var response = new PositiveAuthenticationResponse(positiveAssertion, this);
                    foreach (var behavior in this.Behaviors)
                    {
                        behavior.OnIncomingPositiveAssertion(response);
                    }

                    return(response);
                }
                else if ((positiveExtensionOnly = message as IndirectSignedResponse) != null)
                {
                    return(new PositiveAnonymousResponse(positiveExtensionOnly));
                }
                else if ((negativeAssertion = message as NegativeAssertionResponse) != null)
                {
                    return(new NegativeAuthenticationResponse(negativeAssertion));
                }
                else if (message != null)
                {
                    Logger.OpenId.WarnFormat("Received unexpected message type {0} when expecting an assertion message.", message.GetType().Name);
                }

                return(null);
            } catch (ProtocolException ex) {
                return(new FailedAuthenticationResponse(ex));
            }
        }
Example #2
0
        /// <summary>
        /// Gets an authentication response from a Provider.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// The processed authentication response if there is any; <c>null</c> otherwise.
        /// </returns>
        /// <remarks>
        /// Requires an <see cref="HttpContext.Current">HttpContext.Current</see> context.
        /// </remarks>
        public async Task <IAuthenticationResponse> GetResponseAsync_ccp(IProtocolMessage msg, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var message = await this.Channel.ReadFromRequestAsync_ccp(msg, cancellationToken);

                PositiveAssertionResponse positiveAssertion;
                NegativeAssertionResponse negativeAssertion;
                IndirectSignedResponse    positiveExtensionOnly;
                if ((positiveAssertion = message as PositiveAssertionResponse) != null)
                {
                    // We need to make sure that this assertion is coming from an endpoint
                    // that the host deems acceptable.
                    var providerEndpoint = new SimpleXrdsProviderEndpoint(positiveAssertion);
                    ErrorUtilities.VerifyProtocol(
                        this.FilterEndpoint(providerEndpoint),
                        OpenIdStrings.PositiveAssertionFromNonQualifiedProvider,
                        providerEndpoint.Uri);

                    var response = await PositiveAuthenticationResponse.CreateAsync_ccp(positiveAssertion, this, cancellationToken);

                    foreach (var behavior in this.Behaviors)
                    {
                        behavior.OnIncomingPositiveAssertion(response);
                    }

                    var sreg = ExtensionsInteropHelper.UnifyExtensionsAsSreg(response, true);
                    Debug.Assert(sreg.Email != null, "No email field!");

                    return(response);
                }
                else if ((positiveExtensionOnly = message as IndirectSignedResponse) != null)
                {
                    return(new PositiveAnonymousResponse(positiveExtensionOnly));
                }
                else if ((negativeAssertion = message as NegativeAssertionResponse) != null)
                {
                    return(new NegativeAuthenticationResponse(negativeAssertion));
                }

                return(null);
            }
            catch (ProtocolException ex)
            {
                return(new FailedAuthenticationResponse(ex));
            }
        }
Example #3
0
        /// <summary>
        /// Gets an authentication response from a Provider.
        /// </summary>
        /// <param name="request">The HTTP request that may be carrying an authentication response from the Provider.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// The processed authentication response if there is any; <c>null</c> otherwise.
        /// </returns>
        public async Task <IAuthenticationResponse> GetResponseAsync(HttpRequestMessage request, CancellationToken cancellationToken = default(CancellationToken))
        {
            Requires.NotNull(request, "httpRequestInfo");
            try {
                var message = await this.Channel.ReadFromRequestAsync(request, cancellationToken);

                PositiveAssertionResponse positiveAssertion;
                NegativeAssertionResponse negativeAssertion;
                IndirectSignedResponse    positiveExtensionOnly;
                if ((positiveAssertion = message as PositiveAssertionResponse) != null)
                {
                    // We need to make sure that this assertion is coming from an endpoint
                    // that the host deems acceptable.
                    var providerEndpoint = new SimpleXrdsProviderEndpoint(positiveAssertion);
                    ErrorUtilities.VerifyProtocol(
                        this.FilterEndpoint(providerEndpoint),
                        OpenIdStrings.PositiveAssertionFromNonQualifiedProvider,
                        providerEndpoint.Uri);

                    var response = await PositiveAuthenticationResponse.CreateAsync(positiveAssertion, this, cancellationToken);

                    foreach (var behavior in this.Behaviors)
                    {
                        behavior.OnIncomingPositiveAssertion(response);
                    }

                    return(response);
                }
                else if ((positiveExtensionOnly = message as IndirectSignedResponse) != null)
                {
                    return(new PositiveAnonymousResponse(positiveExtensionOnly));
                }
                else if ((negativeAssertion = message as NegativeAssertionResponse) != null)
                {
                    return(new NegativeAuthenticationResponse(negativeAssertion));
                }
                else if (message != null)
                {
                    Logger.OpenId.WarnFormat("Received unexpected message type {0} when expecting an assertion message.", message.GetType().Name);
                }

                return(null);
            } catch (ProtocolException ex) {
                return(new FailedAuthenticationResponse(ex));
            }
        }