Esempio n. 1
0
        /// <summary>
        /// Adds extensions to a given authentication request to ask the Provider
        /// for user profile data.
        /// </summary>
        /// <param name="request">The authentication request to add the extensions to.</param>
        private void AddProfileArgs(IAuthenticationRequest request)
        {
            Requires.NotNull(request, "request");

            var sreg = new ClaimsRequest()
            {
                Nickname   = this.RequestNickname,
                Email      = this.RequestEmail,
                FullName   = this.RequestFullName,
                BirthDate  = this.RequestBirthDate,
                Gender     = this.RequestGender,
                PostalCode = this.RequestPostalCode,
                Country    = this.RequestCountry,
                Language   = this.RequestLanguage,
                TimeZone   = this.RequestTimeZone,
                PolicyUrl  = string.IsNullOrEmpty(this.PolicyUrl) ?
                             null : new Uri(this.RelyingParty.Channel.GetRequestFromContext().GetPublicFacingUrl(), this.Page.ResolveUrl(this.PolicyUrl)),
            };

            // Only actually add the extension request if fields are actually being requested.
            if (!sreg.Equals(EmptyClaimsRequest))
            {
                request.AddExtension(sreg);
            }
        }
Esempio n. 2
0
        private void ParameterizedTypeUriPreservedTest(string typeUri)
        {
            ClaimsRequest  request  = new ClaimsRequest(typeUri);
            ClaimsResponse response = request.CreateResponse();

            Assert.AreEqual(typeUri, ((IOpenIdMessageExtension)response).TypeUri);
        }
Esempio n. 3
0
        public void UnifyExtensionsAsSregWithBothSregAndAX()
        {
            var sregInjected = new ClaimsRequest(DotNetOpenAuth.OpenId.Extensions.SimpleRegistration.Constants.TypeUris.Standard)
            {
                Nickname = DemandLevel.Request,
            };

            this.extensions.Add(sregInjected);
            var axInjected = new FetchRequest();

            axInjected.Attributes.AddOptional(WellKnownAttributes.Contact.Email);
            this.extensions.Add(axInjected);
            var sreg = ExtensionsInteropHelper.UnifyExtensionsAsSreg(this.request);

            Assert.AreSame(sregInjected, sreg);
            Assert.AreEqual(DemandLevel.Request, sreg.Nickname);
            Assert.AreEqual(DemandLevel.NoRequest, sreg.Email);

            var sregResponseInjected = sreg.CreateResponse();

            sregResponseInjected.Nickname = "andy";
            this.request.AddResponseExtension(sregResponseInjected);
            var axResponseInjected = new FetchResponse();

            axResponseInjected.Attributes.Add(WellKnownAttributes.Contact.Email, "*****@*****.**");
            this.request.AddResponseExtension(axResponseInjected);
            ExtensionsInteropHelper.ConvertSregToMatchRequest(this.request);
            var extensions   = this.GetResponseExtensions();
            var sregResponse = extensions.OfType <ClaimsResponse>().Single();

            Assert.AreEqual("andy", sregResponse.Nickname);
            var axResponse = extensions.OfType <FetchResponse>().Single();

            Assert.AreEqual("*****@*****.**", axResponse.GetAttributeValue(WellKnownAttributes.Contact.Email));
        }
Esempio n. 4
0
    public void SetRequiredFieldsFromRequest(ClaimsRequest requestFields)
    {
        if (requestFields.PolicyUrl != null)
        {
            privacyLink.NavigateUrl = requestFields.PolicyUrl.AbsoluteUri;
        }
        else
        {
            privacyLink.Visible = false;
        }

        dobRequiredLabel.Visible      = (requestFields.BirthDate == DemandLevel.Require);
        countryRequiredLabel.Visible  = (requestFields.Country == DemandLevel.Require);
        emailRequiredLabel.Visible    = (requestFields.Email == DemandLevel.Require);
        fullnameRequiredLabel.Visible = (requestFields.FullName == DemandLevel.Require);
        genderRequiredLabel.Visible   = (requestFields.Gender == DemandLevel.Require);
        languageRequiredLabel.Visible = (requestFields.Language == DemandLevel.Require);
        nicknameRequiredLabel.Visible = (requestFields.Nickname == DemandLevel.Require);
        postcodeRequiredLabel.Visible = (requestFields.PostalCode == DemandLevel.Require);
        timezoneRequiredLabel.Visible = (requestFields.TimeZone == DemandLevel.Require);

        dateOfBirthRow.Visible = !(requestFields.BirthDate == DemandLevel.NoRequest);
        countryRow.Visible     = !(requestFields.Country == DemandLevel.NoRequest);
        emailRow.Visible       = !(requestFields.Email == DemandLevel.NoRequest);
        fullnameRow.Visible    = !(requestFields.FullName == DemandLevel.NoRequest);
        genderRow.Visible      = !(requestFields.Gender == DemandLevel.NoRequest);
        languageRow.Visible    = !(requestFields.Language == DemandLevel.NoRequest);
        nicknameRow.Visible    = !(requestFields.Nickname == DemandLevel.NoRequest);
        postcodeRow.Visible    = !(requestFields.PostalCode == DemandLevel.NoRequest);
        timezoneRow.Visible    = !(requestFields.TimeZone == DemandLevel.NoRequest);
    }
Esempio n. 5
0
        public async Task <ActionResult> SubmitClaim(ClaimsRequest claimsRequest)
        {
            try
            {
                if (claimsRequest == null)
                {
                    return(BadRequest());
                }

                string ServiceBusConnectionString = _configuration.GetSection("ConnectionStrings").GetSection("SendServiceBusConnection").Value;
                string TopicName = _configuration.GetSection("ConnectionStrings").GetSection("TopicName").Value;

                topicClient = new TopicClient(ServiceBusConnectionString, TopicName);

                var serializeBody = JsonConvert.SerializeObject(claimsRequest);

                var busMessage = new Message(Encoding.UTF8.GetBytes(serializeBody));

                await topicClient.SendAsync(busMessage);

                await topicClient.CloseAsync();

                return(Created(HttpContext.Request.Scheme + HttpContext.Request.Host.ToUriComponent(), "Success"));
                //await _claimsService.SaveClaims(claimsRequest);
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Error creating new Member record"));
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Looks for Simple Registration and Attribute Exchange (all known formats)
        /// request extensions and returns them as a Simple Registration extension,
        /// and adds the new extension to the original request message if it was absent.
        /// </summary>
        /// <param name="request">The authentication request.</param>
        /// <returns>
        /// The Simple Registration request if found,
        /// or a fabricated one based on the Attribute Exchange extension if found,
        /// or <c>null</c> if no attribute extension request is found.</returns>
        internal static ClaimsRequest UnifyExtensionsAsSreg(this Provider.IHostProcessedRequest request)
        {
            Requires.NotNull(request, "request");

            var req  = (Provider.HostProcessedRequest)request;
            var sreg = req.GetExtension <ClaimsRequest>();

            if (sreg != null)
            {
                return(sreg);
            }

            var ax = req.GetExtension <FetchRequest>();

            if (ax != null)
            {
                sreg             = new ClaimsRequest(DotNetOpenAuth.OpenId.Extensions.SimpleRegistration.Constants.TypeUris.Standard);
                sreg.Synthesized = true;
                ((IProtocolMessageWithExtensions)req.RequestMessage).Extensions.Add(sreg);
                sreg.BirthDate  = GetDemandLevelFor(ax, WellKnownAttributes.BirthDate.WholeBirthDate);
                sreg.Country    = GetDemandLevelFor(ax, WellKnownAttributes.Contact.HomeAddress.Country);
                sreg.Email      = GetDemandLevelFor(ax, WellKnownAttributes.Contact.Email);
                sreg.FullName   = GetDemandLevelFor(ax, WellKnownAttributes.Name.FullName);
                sreg.Gender     = GetDemandLevelFor(ax, WellKnownAttributes.Person.Gender);
                sreg.Language   = GetDemandLevelFor(ax, WellKnownAttributes.Preferences.Language);
                sreg.Nickname   = GetDemandLevelFor(ax, WellKnownAttributes.Name.Alias);
                sreg.PostalCode = GetDemandLevelFor(ax, WellKnownAttributes.Contact.HomeAddress.PostalCode);
                sreg.TimeZone   = GetDemandLevelFor(ax, WellKnownAttributes.Preferences.TimeZone);
            }

            return(sreg);
        }
Esempio n. 7
0
        protected void add_Click(object sender, System.EventArgs e)
        {
            SharedBasePage requestPage = Page as SharedBasePage;

            // validate base entries Captcha and Comment
            Page.Validate("Base");
            bool baseValid = Page.IsValid;

            // check the openid controls
            Page.Validate("OpenId");
            bool openIdValid = Page.IsValid;

            // check the classic controls Name and Email
            Page.Validate("Classic");
            bool classicValid = Page.IsValid;

            if (baseValid && openIdValid)
            {
                if (String.IsNullOrEmpty(openid_identifier.Text) == false && openid_identifier.Text != "Click to Sign In")
                {
                    Session["pendingComment"] = comment.Text;
                    Session["pendingEntryId"] = ViewState["entryId"].ToString().ToUpper();
                    OpenIdRelyingParty openid = new OpenIdRelyingParty();
                    try
                    {
                        IAuthenticationRequest req         = openid.CreateRequest(openid_identifier.Text);
                        ClaimsRequest          sregRequest = new ClaimsRequest();
                        sregRequest.Email    = DemandLevel.Require;
                        sregRequest.Nickname = DemandLevel.Require;
                        sregRequest.FullName = DemandLevel.Request;
                        req.AddExtension(sregRequest);

                        // Also add AX request explicitly so we can request first and last name individually.
                        FetchRequest axRequest = new FetchRequest();
                        axRequest.Attributes.AddRequired(WellKnownAttributes.Name.First);
                        axRequest.Attributes.AddRequired(WellKnownAttributes.Name.Last);
                        req.AddExtension(axRequest);

                        SaveCookies();
                        req.RedirectToProvider();
                        return;
                    }
                    catch (UriFormatException ue) //They've entered something that's not a URI!
                    {
                        requestPage.LoggingService.AddEvent(new EventDataItem(EventCodes.Error, "ERROR: " + openid_identifier.Text + " is not a valid URL. " + ue.Message, ""));
                    }
                }
            }

            if (baseValid && classicValid)
            {
                //Why isn't Page.Validate("Normal") working? It returns false. Hm.
                if (!String.IsNullOrEmpty(name.Text.Trim()))
                {
                    SaveCookies();
                    AddNewComment(name.Text, email.Text, homepage.Text, comment.Text, ViewState["entryId"].ToString().ToUpper(), /* openid */ false);
                }
            }
        }
Esempio n. 8
0
        internal static string SignIn(Guid userDetailsPageId)
        {
            string errorMessage = string.Empty;

            using (var openid = new OpenIdRelyingParty())
            {
                //fix wrong URI, add PathInfo
                HttpContext.Current.RewritePath(HttpContext.Current.Request.RawUrl);
                IAuthenticationResponse response = openid.GetResponse();
                if (response == null)
                {
                    //request
                    string openIDIdentifier = HttpContext.Current.Request.Form["openid_identifier"];

                    if (!string.IsNullOrEmpty(openIDIdentifier))
                    {
                        IAuthenticationRequest request = openid.CreateRequest(openIDIdentifier);
                        var claims = new ClaimsRequest();
                        claims.Email    = DemandLevel.Require;
                        claims.Nickname = DemandLevel.Require;
                        claims.FullName = DemandLevel.Require;
                        claims.Country  = DemandLevel.Require;
                        request.AddExtension(claims);

                        //small fix for request.RedirectToProvider();
                        string location = request.RedirectingResponse.Headers["Location"];
                        HttpContext.Current.Response.Redirect(location, false);
                    }
                }
                else
                {
                    //response
                    switch (response.Status)
                    {
                    case AuthenticationStatus.Authenticated:
                        HandleSuccessfulSignIn(response, userDetailsPageId);
                        break;

                    case AuthenticationStatus.Canceled:
                        errorMessage = "Login was cancelled at the provider.";
                        break;

                    case AuthenticationStatus.Failed:
                        errorMessage = "Login failed at the provider.";
                        break;

                    case AuthenticationStatus.SetupRequired:
                        errorMessage = "The provider requires setup.";
                        break;

                    default:
                        errorMessage = "Login failed.";
                        break;
                    }
                }
            }
            return(errorMessage);
        }
Esempio n. 9
0
    public async Task <string[]> GetAppRolesAsync(ClaimsRequest request)
    {
        ServicePrincipal?servicePrincipal = await GetServicePrincipalAsync(request.ClientId);

        if (servicePrincipal == null)
        {
            throw new ArgumentException($"App role not found for \"{request.ClientId}\".");
        }

        return(await GetAppRoleAssignmentsAsync(servicePrincipal, request.ObjectId.ToString()));
    }
Esempio n. 10
0
    public async Task <IActionResult> Roles(ClaimsRequest request)
    {
        var roles = await _graphAPIService.GetAppRolesAsync(request);

        RolesClaimResponse response = new RolesClaimResponse()
        {
            Roles = roles
        };

        return(Ok(response));
    }
 public void Delete(ClaimsRequest delObj)
 {
     using (var session = GetSession())
     {
         using (var trans = session.BeginTransaction())
         {
             session.Delete(delObj);
             trans.Commit();
         }
     }
 }
Esempio n. 12
0
        public async Task ResponseAlternateTypeUriTests()
        {
            var request = new ClaimsRequest(Constants.TypeUris.Variant10);

            request.Email = DemandLevel.Require;

            var response = new ClaimsResponse(Constants.TypeUris.Variant10);

            response.Email = "*****@*****.**";

            await this.RoundtripAsync(Protocol.Default, new[] { request }, new[] { response });
        }
        public void Partial()
        {
            var request = new ClaimsRequest();

            request.FullName = DemandLevel.Request;
            request.Email    = DemandLevel.Require;
            var response = ParameterizedTest <ClaimsResponse>(
                TestSupport.Scenarios.ExtensionPartialCooperation, Version, request);

            Assert.IsNull(response.FullName);
            Assert.AreEqual("*****@*****.**", response.Email);
        }
Esempio n. 14
0
        public void ResponseAlternateTypeUriTests()
        {
            var request = new ClaimsRequest(Constants.TypeUris.Variant10);

            request.Email = DemandLevel.Require;

            var response = new ClaimsResponse(Constants.TypeUris.Variant10);

            response.Email = "*****@*****.**";

            ExtensionTestUtilities.Roundtrip(Protocol.Default, new[] { request }, new[] { response });
        }
Esempio n. 15
0
        void parameterizedPreserveVersionFromRequest(string versionTypeUri)
        {
            Dictionary <string, string> fields = new Dictionary <string, string> {
                { "optional", "nickname" },
            };
            var req = new ClaimsRequest();

            Assert.IsTrue(((IExtensionRequest)req).Deserialize(fields, null, versionTypeUri));
            Assert.AreEqual(DemandLevel.Request, req.Nickname);
            ClaimsResponse resp = req.CreateResponse();

            Assert.AreEqual(versionTypeUri, ((IExtensionResponse)resp).TypeUri);
        }
Esempio n. 16
0
        public void EqualityTests()
        {
            ClaimsRequest req1 = new ClaimsRequest();
            ClaimsRequest req2 = new ClaimsRequest();

            Assert.AreEqual(req1, req2);

            req1.BirthDate = DemandLevel.Request;
            Assert.AreNotEqual(req1, req2);

            req2.BirthDate = DemandLevel.Request;
            req1.Country   = DemandLevel.Request;
            Assert.AreNotEqual(req1, req2);
        }
 public void Save(ClaimsRequest saveObj)
 {
     using (var session = GetSession())
     {
         using (var trans = session.BeginTransaction())
         {
             session.FlushMode = FlushMode.Commit;
             session.SaveOrUpdate(saveObj);
             trans.Commit();
             session.Flush();
             //}
         }
     }
 }
Esempio n. 18
0
        public IAuthenticationRequest ValidateAtOpenIdProvider(string openIdIdentifier)
        {
            IAuthenticationRequest openIdRequest = openId.CreateRequest(Identifier.Parse(openIdIdentifier));

            var fields = new ClaimsRequest()
            {
                Email    = DemandLevel.Require,
                FullName = DemandLevel.Require,
                Nickname = DemandLevel.Require
            };

            openIdRequest.AddExtension(fields);

            return(openIdRequest);
        }
Esempio n. 19
0
        public static IOpenIdMessageExtension CreateClaimsRequest(
            IOpenAuthenticationProviderPermissionService openAuthenticationProviderPermissionService)
        {
            var claimsRequest = new ClaimsRequest();

            if (openAuthenticationProviderPermissionService.IsPermissionEnabled("Birthdate", Provider.SystemName))
            {
                claimsRequest.BirthDate = DemandLevel.Require;
            }

            if (openAuthenticationProviderPermissionService.IsPermissionEnabled("Country", Provider.SystemName))
            {
                claimsRequest.Country = DemandLevel.Require;
            }

            //            if (openAuthenticationProviderPermissionService.IsPermissionEnabled("Email", Provider.OpenId))
            claimsRequest.Email = DemandLevel.Require;

            //            if (openAuthenticationProviderPermissionService.IsPermissionEnabled("FullName", Provider.OpenId))
            claimsRequest.FullName = DemandLevel.Require;

            if (openAuthenticationProviderPermissionService.IsPermissionEnabled("Gender", Provider.SystemName))
            {
                claimsRequest.Gender = DemandLevel.Require;
            }

            if (openAuthenticationProviderPermissionService.IsPermissionEnabled("Language", Provider.SystemName))
            {
                claimsRequest.Language = DemandLevel.Require;
            }

            if (openAuthenticationProviderPermissionService.IsPermissionEnabled("Nickname", Provider.SystemName))
            {
                claimsRequest.Nickname = DemandLevel.Require;
            }

            if (openAuthenticationProviderPermissionService.IsPermissionEnabled("PostalCode", Provider.SystemName))
            {
                claimsRequest.PostalCode = DemandLevel.Require;
            }

            if (openAuthenticationProviderPermissionService.IsPermissionEnabled("TimeZone", Provider.SystemName))
            {
                claimsRequest.TimeZone = DemandLevel.Require;
            }

            return(claimsRequest);
        }
Esempio n. 20
0
    public async Task <IActionResult> Permissions(ClaimsRequest request)
    {
        _logger.LogDebug("Custom claims where requested for user id: {objectId}", request.ObjectId);
        var permissions = await _permissionsService.GetPermissionsAsync(request.ObjectId.ToString());

        string[] permissionStrings = permissions.Select(x => x.ToTenantPermissionString())
                                     // Append default permission with the users object ID
                                     .Append($"{request.ObjectId}.Self")
                                     .ToArray();
        PermissionsClaimResponse response = new PermissionsClaimResponse()
        {
            Permissions = permissionStrings
        };

        return(Ok(response));
    }
Esempio n. 21
0
        public static IOpenIdMessageExtension CreateClaimsRequest()
        {
            var claimsRequest = new ClaimsRequest();

            //claimsRequest.BirthDate = DemandLevel.Require;
            //claimsRequest.Country = DemandLevel.Require;
            claimsRequest.Email    = DemandLevel.Require;
            claimsRequest.FullName = DemandLevel.Require;
            //claimsRequest.Gender = DemandLevel.Require;
            //claimsRequest.Language = DemandLevel.Require;
            //claimsRequest.Nickname = DemandLevel.Require;
            //claimsRequest.PostalCode = DemandLevel.Require;
            //claimsRequest.TimeZone = DemandLevel.Require;

            return(claimsRequest);
        }
Esempio n. 22
0
        public string CreateRequestWithSimpleRegistration(string userSuppliedIdentifier, string realm, string returnToUrl, string optionalSreg, string requiredSreg)
        {
            var request = relyingParty.CreateRequest(userSuppliedIdentifier, realm, new Uri(returnToUrl));

            ClaimsRequest sreg = new ClaimsRequest();

            if (!string.IsNullOrEmpty(optionalSreg))
            {
                sreg.SetProfileRequestFromList(optionalSreg.Split(','), DemandLevel.Request);
            }
            if (!string.IsNullOrEmpty(requiredSreg))
            {
                sreg.SetProfileRequestFromList(requiredSreg.Split(','), DemandLevel.Require);
            }
            request.AddExtension(sreg);
            return(request.RedirectingResponse.GetDirectUriRequest(relyingParty.Channel).AbsoluteUri);
        }
Esempio n. 23
0
        /// <summary>
        /// Called when a request is received by the Provider.
        /// </summary>
        /// <param name="request">The incoming request.</param>
        /// <returns>
        ///     <c>true</c> if this behavior owns this request and wants to stop other behaviors
        /// from handling it; <c>false</c> to allow other behaviors to process this request.
        /// </returns>
        /// <remarks>
        /// Implementations may set a new value to <see cref="IRequest.SecuritySettings"/> but
        /// should not change the properties on the instance of <see cref="ProviderSecuritySettings"/>
        /// itself as that instance may be shared across many requests.
        /// </remarks>
        bool IProviderBehavior.OnIncomingRequest(IRequest request)
        {
            var extensionRequest = request as Provider.HostProcessedRequest;

            if (extensionRequest != null)
            {
                if (extensionRequest.GetExtension <ClaimsRequest>() == null)
                {
                    ClaimsRequest sreg = extensionRequest.UnifyExtensionsAsSreg();
                    if (sreg != null)
                    {
                        ((IProtocolMessageWithExtensions)extensionRequest.RequestMessage).Extensions.Add(sreg);
                    }
                }
            }

            return(false);
        }
Esempio n. 24
0
        public void RequiredOptionalLists()
        {
            ClaimsRequest     req        = new ClaimsRequest();
            MessageDictionary dictionary = this.MessageDescriptions.GetAccessor(req);

            Assert.AreEqual(string.Empty, dictionary["required"]);
            Assert.AreEqual(string.Empty, dictionary["optional"]);

            req.BirthDate = DemandLevel.Request;
            req.Nickname  = DemandLevel.Require;
            Assert.AreEqual("dob", dictionary["optional"]);
            Assert.AreEqual("nickname", dictionary["required"]);

            req.PostalCode = DemandLevel.Require;
            req.Gender     = DemandLevel.Request;
            Assert.AreEqual("dob,gender", dictionary["optional"]);
            Assert.AreEqual("nickname,postcode", dictionary["required"]);
        }
Esempio n. 25
0
    public ClaimsResponse GetOpenIdProfileFields(ClaimsRequest request)
    {
        if (request == null)
        {
            throw new ArgumentNullException("request");
        }
        ClaimsResponse fields = request.CreateResponse();

        fields.BirthDate  = DateOfBirth;
        fields.Country    = countryDropdownList.SelectedValue;
        fields.Email      = emailTextBox.Text;
        fields.FullName   = fullnameTextBox.Text;
        fields.Gender     = Gender;
        fields.Language   = languageDropdownList.SelectedValue;
        fields.Nickname   = nicknameTextBox.Text;
        fields.PostalCode = postcodeTextBox.Text;
        fields.TimeZone   = timezoneDropdownList.SelectedValue;
        return(fields);
    }
Esempio n. 26
0
        public override void SetUp()
        {
            base.SetUp();

            var        rp         = CreateRelyingParty(true);
            Identifier identifier = this.GetMockIdentifier(ProtocolVersion.V20);

            this.authReq = (AuthenticationRequest)rp.CreateRequestAsync(identifier, RPRealmUri, RPUri).Result;
            this.sreg    = new ClaimsRequest {
                Nickname   = DemandLevel.Request,
                FullName   = DemandLevel.Request,
                BirthDate  = DemandLevel.Request,
                Email      = DemandLevel.Require,
                Country    = DemandLevel.Request,
                PostalCode = DemandLevel.Request,
                Gender     = DemandLevel.Request,
                Language   = DemandLevel.Request,
                TimeZone   = DemandLevel.Request,
            };
        }
        public void UnifyExtensionsAsSregWithSreg()
        {
            var sregInjected = new ClaimsRequest {
                Nickname = DemandLevel.Request,
            };

            this.extensions.Add(sregInjected);
            var sreg = ExtensionsInteropHelper.UnifyExtensionsAsSreg(this.request);

            Assert.AreSame(sregInjected, sreg);
            Assert.AreEqual(DemandLevel.Request, sreg.Nickname);
            Assert.AreEqual(DemandLevel.NoRequest, sreg.FullName);

            var sregResponse = new ClaimsResponse();

            this.request.AddResponseExtension(sregResponse);
            ExtensionsInteropHelper.ConvertSregToMatchRequest(this.request);
            var extensions = this.GetResponseExtensions();

            Assert.AreSame(sregResponse, extensions.Single());
        }
Esempio n. 28
0
        public void UnifyExtensionsAsSregWithSreg()
        {
            var sregInjected = new ClaimsRequest(DotNetOpenAuth.OpenId.Extensions.SimpleRegistration.Constants.TypeUris.Standard)
            {
                Nickname = DemandLevel.Request,
            };

            this.extensions.Add(sregInjected);
            var sreg = ExtensionsInteropHelper.UnifyExtensionsAsSreg(this.request);

            Assert.AreSame(sregInjected, sreg);
            Assert.AreEqual(DemandLevel.Request, sreg.Nickname);
            Assert.AreEqual(DemandLevel.NoRequest, sreg.FullName);

            var sregResponse = sreg.CreateResponse();

            this.request.AddResponseExtension(sregResponse);
            ExtensionsInteropHelper.ConvertSregToMatchRequest(this.request);
            var extensions = this.GetResponseExtensions();

            Assert.AreSame(sregResponse, extensions.Single());
        }
        protected void loginButton_Click(object sender, EventArgs e)
        {
            if (!openidValidator.IsValid)
            {
                return;                           // don't login if custom validation failed.
            }
            OpenIdRelyingParty openid = new OpenIdRelyingParty();

            try {
                IAuthenticationRequest request = openid.CreateRequest(openid_identifier.Text);
                // Send your visitor to their Provider for authentication.
                ClaimsRequest fetch = new ClaimsRequest();
                fetch.Nickname = DemandLevel.Require;
                fetch.Email    = DemandLevel.Require;
                request.AddExtension(fetch);
                request.RedirectToProvider();
            } catch (OpenIdException ex) {
                // The user probably entered an Identifier that
                // was not a valid OpenID endpoint.
                openidValidator.Text    = ex.Message;
                openidValidator.IsValid = false;
            }
        }
Esempio n. 30
0
        public void CreateRequestMessage()
        {
            OpenIdCoordinator coordinator = new OpenIdCoordinator(
                rp => {
                Identifier id = this.GetMockIdentifier(ProtocolVersion.V20);
                IAuthenticationRequest authRequest = rp.CreateRequest(id, this.realm, this.returnTo);

                // Add some callback arguments
                authRequest.AddCallbackArguments("a", "b");
                authRequest.AddCallbackArguments(new Dictionary <string, string> {
                    { "c", "d" }, { "e", "f" }
                });

                // Assembly an extension request.
                ClaimsRequest sregRequest = new ClaimsRequest();
                sregRequest.Nickname      = DemandLevel.Request;
                authRequest.AddExtension(sregRequest);

                // Construct the actual authentication request message.
                var authRequestAccessor = AuthenticationRequest_Accessor.AttachShadow(authRequest);
                var req = authRequestAccessor.CreateRequestMessage();
                Assert.IsNotNull(req);

                // Verify that callback arguments were included.
                NameValueCollection callbackArguments = HttpUtility.ParseQueryString(req.ReturnTo.Query);
                Assert.AreEqual("b", callbackArguments["a"]);
                Assert.AreEqual("d", callbackArguments["c"]);
                Assert.AreEqual("f", callbackArguments["e"]);

                // Verify that extensions were included.
                Assert.AreEqual(1, req.Extensions.Count);
                Assert.IsTrue(req.Extensions.Contains(sregRequest));
            },
                AutoProvider);

            coordinator.Run();
        }