Пример #1
0
        public static EncodableResponse CreateAssertion(CheckIdRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }
            if (!request.IsAuthenticated.HasValue)
            {
                throw new InvalidOperationException();
            }
            EncodableResponse response = EncodableResponse.PrepareIndirectMessage(
                request.Protocol, request.ReturnTo, request.AssociationHandle);

            if (request.IsAuthenticated.Value)
            {
                AssertionMessage.CreatePositiveAssertion(response, request.Provider,
                                                         request.LocalIdentifier, request.ClaimedIdentifier);
                Logger.InfoFormat("Created positive assertion for {0}.", request.ClaimedIdentifier);
            }
            else
            {
                AssertionMessage.CreateNegativeAssertion(response, request);
                Logger.InfoFormat("Created negative assertion for {0}.", request.ClaimedIdentifier);
            }
            return(response);
        }
Пример #2
0
        public static void CreateNegativeAssertion(EncodableResponse message, CheckIdRequest request)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            Protocol protocol = message.Protocol;

            if (request.Immediate)
            {
                if (protocol.Version.Major >= 2)
                {
                    message.Fields[protocol.openidnp.mode] = protocol.Args.Mode.setup_needed;
                }
                else
                {
                    message.Fields[protocol.openidnp.mode]           = protocol.Args.Mode.id_res;
                    message.Fields[protocol.openidnp.user_setup_url] = request.SetupUrl.AbsoluteUri;
                }
            }
            else
            {
                message.Fields[protocol.openidnp.mode] = protocol.Args.Mode.cancel;
            }
        }
Пример #3
0
 public static EncodableResponse CreateAssertion(CheckIdRequest request)
 {
     if (request == null) throw new ArgumentNullException("request");
     if (!request.IsAuthenticated.HasValue) throw new InvalidOperationException();
     EncodableResponse response = EncodableResponse.PrepareIndirectMessage(
         request.Protocol, request.ReturnTo, request.AssociationHandle);
     if (request.IsAuthenticated.Value) {
         AssertionMessage.CreatePositiveAssertion(response, request.Provider,
             request.LocalIdentifier, request.ClaimedIdentifier);
         Logger.InfoFormat("Created positive assertion for {0}.", request.ClaimedIdentifier);
     } else {
         AssertionMessage.CreateNegativeAssertion(response, request);
         Logger.InfoFormat("Created negative assertion for {0}.", request.ClaimedIdentifier);
     }
     return response;
 }
Пример #4
0
        public static void CreateNegativeAssertion(EncodableResponse message, CheckIdRequest request)
        {
            if (message == null) throw new ArgumentNullException("message");
            if (request == null) throw new ArgumentNullException("request");

            Protocol protocol = message.Protocol;
            if (request.Immediate) {
                if (protocol.Version.Major >= 2) {
                    message.Fields[protocol.openidnp.mode] = protocol.Args.Mode.setup_needed;
                } else {
                    message.Fields[protocol.openidnp.mode] = protocol.Args.Mode.id_res;
                    message.Fields[protocol.openidnp.user_setup_url] = request.SetupUrl.AbsoluteUri;
                }
            } else {
                message.Fields[protocol.openidnp.mode] = protocol.Args.Mode.cancel;
            }
        }
Пример #5
0
        /// <summary>
        /// Creates the appropriate Request-derived type based on the request dictionary.
        /// </summary>
        /// <param name="provider">The Provider instance that called this method.</param>
        /// <returns>A Request-derived type appropriate for this stage in authentication.</returns>
        internal static Request CreateRequest(OpenIdProvider provider)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            Debug.Assert(provider.Protocol != null, "This should have been set already.");
            string mode = Util.GetRequiredArg(provider.Query, provider.Protocol.openid.mode);

            Request request;

            try {
                if (mode == provider.Protocol.Args.Mode.checkid_setup ||
                    mode == provider.Protocol.Args.Mode.checkid_immediate)
                {
                    request = new CheckIdRequest(provider);
                }
                else if (mode == provider.Protocol.Args.Mode.check_authentication)
                {
                    request = new CheckAuthRequest(provider);
                }
                else if (mode == provider.Protocol.Args.Mode.associate)
                {
                    request = new AssociateRequest(provider);
                }
                else
                {
                    throw new OpenIdException(string.Format(CultureInfo.CurrentCulture,
                                                            Strings.InvalidOpenIdQueryParameterValue, provider.Protocol.openid.mode,
                                                            mode), provider.Query);
                }
            } catch (OpenIdException ex) {
                request = new FaultyRequest(provider, ex);
            }
            return(request);
        }