Beispiel #1
0
        /// <summary>
        /// Generates the authentication requests that can satisfy the requirements of some OpenID Identifier.
        /// </summary>
        /// <param name="userSuppliedIdentifier">
        /// The Identifier supplied by the user.  This may be a URL, an XRI or i-name.
        /// </param>
        /// <param name="realm">
        /// The shorest URL that describes this relying party web site's address.
        /// For example, if your login page is found at https://www.example.com/login.aspx,
        /// your realm would typically be https://www.example.com/.
        /// </param>
        /// <returns>
        /// An authentication request object that describes the HTTP response to
        /// send to the user agent to initiate the authentication.
        /// </returns>
        /// <remarks>
        /// <para>Any individual generated request can satisfy the authentication.
        /// The generated requests are sorted in preferred order.
        /// Each request is generated as it is enumerated to.  Associations are created only as
        /// <see cref="IAuthenticationRequest.RedirectingResponse"/> is called.</para>
        /// <para>No exception is thrown if no OpenID endpoints were discovered.
        /// An empty enumerable is returned instead.</para>
        /// </remarks>
        internal IEnumerable <IAuthenticationRequest> CreateRequests(Identifier userSuppliedIdentifier, Realm realm)
        {
            if (HttpContext.Current == null)
            {
                throw new InvalidOperationException(Strings.CurrentHttpContextRequired);
            }

            // Build the return_to URL
            UriBuilder returnTo = new UriBuilder(Util.GetRequestUrlFromContext());

            // Trim off any parameters with an "openid." prefix, and a few known others
            // to avoid carrying state from a prior login attempt.
            returnTo.Query = string.Empty;
            NameValueCollection queryParams = Util.GetQueryFromContextNVC();
            var returnToParams = new Dictionary <string, string>(queryParams.Count);

            foreach (string key in queryParams)
            {
                if (!ShouldParameterBeStrippedFromReturnToUrl(key))
                {
                    returnToParams.Add(key, queryParams[key]);
                }
            }
            UriUtil.AppendQueryArgs(returnTo, returnToParams);

            return(CreateRequests(userSuppliedIdentifier, realm, returnTo.Uri));
        }
Beispiel #2
0
    /// <summary>
    /// Gets a URL that can be requested to send an indirect message.
    /// </summary>
    public static Uri ExtractUrl(this IResponse message)
    {
        DotNetOpenId.Response response  = (DotNetOpenId.Response)message;
        IEncodable            encodable = response.EncodableMessage;
        UriBuilder            builder   = new UriBuilder(encodable.RedirectUrl);

        UriUtil.AppendQueryArgs(builder, encodable.EncodedFields);
        return(builder.Uri);
    }
Beispiel #3
0
    public static Uri GetFullUrl(string url, IDictionary <string, string> args, bool useSsl)
    {
        Uri        defaultUriBase = new Uri(useSsl ? "https://localhost/" : "http://localhost/");
        Uri        baseUri        = UITestSupport.Host != null ? UITestSupport.Host.BaseUri : defaultUriBase;
        UriBuilder builder        = new UriBuilder(new Uri(baseUri, url));

        UriUtil.AppendQueryArgs(builder, args);
        return(builder.Uri);
    }
Beispiel #4
0
        public AuthenticationResponseTests()
        {
            UriBuilder builder = new UriBuilder(TestSupport.GetFullUrl(TestSupport.ConsumerPage));

            // we add something pointless to the return_to, so some tests have something to remove.
            UriUtil.AppendQueryArgs(builder, new Dictionary <string, string> {
                { returnToRemovableParameter, "b" }
            });
            returnTo = builder.Uri;
        }
Beispiel #5
0
        public void AppendQueryArgs()
        {
            UriBuilder uri  = new UriBuilder("http://baseline.org/page");
            var        args = new Dictionary <string, string>();

            args.Add("a", "b");
            args.Add("c/d", "e/f");
            UriUtil.AppendQueryArgs(uri, args);
            Assert.AreEqual("http://baseline.org/page?a=b&c%2fd=e%2ff", uri.Uri.AbsoluteUri);
            args.Clear();
            args.Add("g", "h");
            UriUtil.AppendQueryArgs(uri, args);
            Assert.AreEqual("http://baseline.org/page?a=b&c%2fd=e%2ff&g=h", uri.Uri.AbsoluteUri);
        }
Beispiel #6
0
 public void AppendQueryArgsNullDictionary()
 {
     UriUtil.AppendQueryArgs(new UriBuilder(), null);
 }
Beispiel #7
0
 public void AppendQueryArgsNullUriBuilder()
 {
     UriUtil.AppendQueryArgs(null, new Dictionary <string, string>());
 }