コード例 #1
0
        public void AddAttributeRequestAgain()
        {
            var req = new FetchRequest();

            req.AddAttribute(new AttributeRequest()
            {
                TypeUri = "http://UriTwice"
            });
            req.AddAttribute(new AttributeRequest()
            {
                TypeUri = "http://UriTwice"
            });
        }
コード例 #2
0
        public void Store()
        {
            var request      = new StoreRequest();
            var newAttribute = new AttributeValues(incrementingAttribute,
                                                   "val" + (incrementingAttributeValue++).ToString(),
                                                   "val" + (incrementingAttributeValue++).ToString()
                                                   );

            request.AddAttribute(newAttribute);

            var response = ParameterizedTest <StoreResponse>(
                TestSupport.Scenarios.ExtensionFullCooperation, Version, request);

            Assert.IsNotNull(response);
            Assert.IsTrue(response.Succeeded);
            Assert.IsNull(response.FailureReason);

            var fetchRequest = new FetchRequest();

            fetchRequest.AddAttribute(new AttributeRequest {
                TypeUri = incrementingAttribute
            });
            var fetchResponse = ParameterizedTest <FetchResponse>(
                TestSupport.Scenarios.ExtensionFullCooperation, Version, fetchRequest);

            Assert.IsNotNull(fetchResponse);
            var att = fetchResponse.GetAttribute(incrementingAttribute);

            Assert.IsNotNull(att);
            Assert.AreEqual(newAttribute.Values.Count, att.Values.Count);
            for (int i = 0; i < newAttribute.Values.Count; i++)
            {
                Assert.AreEqual(newAttribute.Values[i], att.Values[i]);
            }
        }
コード例 #3
0
        public void AddAttributeRequestStrangeUri()
        {
            var req = new FetchRequest();

            req.AddAttribute(new AttributeRequest()
            {
                TypeUri = "=someUri*who*knows*but*this*is*legal"
            });
        }
コード例 #4
0
        public void AddAttributeRequest()
        {
            var req = new FetchRequest();

            req.AddAttribute(new AttributeRequest()
            {
                TypeUri = "http://someUri"
            });
        }
コード例 #5
0
        public void Fetch()
        {
            var request = new FetchRequest();

            request.AddAttribute(new AttributeRequest(nicknameTypeUri));
            request.AddAttribute(new AttributeRequest(emailTypeUri, false, int.MaxValue));
            var response = ParameterizedTest <FetchResponse>(
                TestSupport.Scenarios.ExtensionFullCooperation, Version, request);

            Assert.IsNotNull(response);
            var att = response.GetAttribute(nicknameTypeUri);

            Assert.IsNotNull(att);
            Assert.AreEqual(nicknameTypeUri, att.TypeUri);
            Assert.AreEqual(1, att.Values.Count);
            Assert.AreEqual("Andrew", att.Values[0]);
            att = response.GetAttribute(emailTypeUri);
            Assert.IsNotNull(att);
            Assert.AreEqual(emailTypeUri, att.TypeUri);
            Assert.AreEqual(2, att.Values.Count);
            Assert.AreEqual("*****@*****.**", att.Values[0]);
            Assert.AreEqual("*****@*****.**", att.Values[1]);
        }
コード例 #6
0
        public Address GetOpenIDAddress(Uri claimUri)
        {
            var     openid = new OpenIdRelyingParty();
            Address result = new Address();

            if (openid.Response != null)
            {
                // Stage 2: user submitting Identifier
                var fetch = openid.Response.GetExtension <FetchResponse>();
                if (fetch != null)
                {
                    result.Email           = GetFetchValue(fetch, "contact/email");
                    result.FirstName       = GetFetchValue(fetch, "namePerson/first");
                    result.LastName        = GetFetchValue(fetch, "namePerson/last");
                    result.Street1         = GetFetchValue(fetch, "contact/streetaddressLine1/home");
                    result.Street2         = GetFetchValue(fetch, "contact/streetaddressLine2/home");
                    result.City            = GetFetchValue(fetch, "contact/city/home");
                    result.StateOrProvince = GetFetchValue(fetch, "contact/city/stateorprovince");
                    result.Country         = GetFetchValue(fetch, "contact/country/home");
                    result.Zip             = GetFetchValue(fetch, "contact/postalCode/home");

                    result.UserName = openid.Response.ClaimedIdentifier;
                }
            }
            else
            {
                var request = openid.CreateRequest(claimUri.AbsoluteUri);
                var fetch   = new FetchRequest();
                fetch.AddAttribute(new AttributeRequest("contact/email"));
                fetch.AddAttribute(new AttributeRequest("namePerson/first"));
                fetch.AddAttribute(new AttributeRequest("namePerson/last"));
                fetch.AddAttribute(new AttributeRequest("contact/streetaddressLine1/home"));
                fetch.AddAttribute(new AttributeRequest("contact/streetaddressLine2/home"));
                fetch.AddAttribute(new AttributeRequest("contact/city/home"));
                fetch.AddAttribute(new AttributeRequest("contact/city/stateorprovince"));
                fetch.AddAttribute(new AttributeRequest("contact/country/home"));
                fetch.AddAttribute(new AttributeRequest("contact/postalCode/home"));
                request.AddExtension(fetch);
                request.RedirectToProvider();
            }
            return(result);
        }
コード例 #7
0
        public void FetchLimitEmails()
        {
            var request = new FetchRequest();

            request.AddAttribute(new AttributeRequest {
                TypeUri = emailTypeUri, Count = 1
            });
            var response = ParameterizedTest <FetchResponse>(
                TestSupport.Scenarios.ExtensionFullCooperation, Version, request);

            Assert.IsNotNull(response);
            var att = response.GetAttribute(emailTypeUri);

            Assert.IsNotNull(att);
            Assert.AreEqual(emailTypeUri, att.TypeUri);
            Assert.AreEqual(1, att.Values.Count);
            Assert.AreEqual("*****@*****.**", att.Values[0]);
        }
コード例 #8
0
        public Yield UserLogin(DreamContext context, DreamMessage request, Result <DreamMessage> response)
        {
            string userSuppliedIdentifier = context.GetParam("url", null);

            if (String.IsNullOrEmpty(userSuppliedIdentifier))
            {
                _log.Info("No identifier was specified");
                throw new DreamBadRequestException("No identifier was specified.");
            }

            XUri   returnUri = new XUri(context.GetParam("returnurl", null));
            String realm     = context.GetParam("realm", null);

            if (String.IsNullOrEmpty(realm))
            {
                realm = returnUri.WithoutPathQueryFragment().ToString();
            }

            IAuthenticationRequest openIdRequest;

            // dummy parameters required by DotNetOpenId 2.x; in 3.x, you can
            // just pass null to the OpenIdRelyingParty constructor.
            Uri identifierUri            = new Uri(userSuppliedIdentifier);
            NameValueCollection queryCol = System.Web.HttpUtility.ParseQueryString(identifierUri.Query);
            OpenIdRelyingParty  openid   = new OpenIdRelyingParty(null, identifierUri, queryCol);

            // creating an OpenID request will authenticate that
            // the endpoint exists and is an OpenID provider.
            _log.DebugFormat("Creating OpenID request: identifier {0}, return URL {1}, realm {2}", userSuppliedIdentifier, returnUri.ToString(), realm);

            try {
                openIdRequest = openid.CreateRequest(
                    userSuppliedIdentifier,
                    realm,
                    returnUri.ToUri());
            } catch (OpenIdException ex) {
                _log.WarnFormat("'{0}' rejected as OpenID identifier: {1}", userSuppliedIdentifier, ex.Message);
                throw new DreamBadRequestException(string.Format("'{0}' is not a valid OpenID identifier. {1}", userSuppliedIdentifier, ex.Message));
            }

            // Ask for the e-mail address on this request.
            // Use both SREG and AX, to increase the odds of getting it.
            openIdRequest.AddExtension(new ClaimsRequest {
                Email = DemandLevel.Require,
            });

            var fetch = new FetchRequest();

            fetch.AddAttribute(new AttributeRequest(WellKnownAttributes.Contact.Email, true));
            openIdRequest.AddExtension(fetch);

            // The RedirectingResponse either contains a "Location" header for
            // a HTTP GET, which will return in the response as 'endpoint', or
            // a HTML FORM which needs to be displayed to the user, which will
            // return in the response as 'form'.
            IResponse wr = openIdRequest.RedirectingResponse;

            XDoc result = new XDoc("openid");

            if (String.IsNullOrEmpty(wr.Headers["Location"]))
            {
                System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
                string formBody = enc.GetString(wr.Body);
                _log.DebugFormat("OpenID redirect by HTML FORM: {0}", formBody);
                result.Attr("form", formBody);
            }
            else
            {
                string redirectUrl = wr.Headers["Location"];
                _log.DebugFormat("OpenID redirect URL: {0}", redirectUrl);
                result.Attr("endpoint", redirectUrl);
            }

            response.Return(DreamMessage.Ok(result));
            yield break;
        }