コード例 #1
0
ファイル: ClaimActionTests.cs プロジェクト: wserr/AspNetCore
        public void MapAllSucceeds()
        {
            var userData = JsonDocument.Parse("{ \"name0\": \"value0\", \"name1\": \"value1\" }");

            var identity = new ClaimsIdentity();
            var action   = new MapAllClaimsAction();

            action.Run(userData.RootElement, identity, "iss");

            Assert.Equal("name0", identity.FindFirst("name0").Type);
            Assert.Equal("value0", identity.FindFirst("name0").Value);
            Assert.Equal("name1", identity.FindFirst("name1").Type);
            Assert.Equal("value1", identity.FindFirst("name1").Value);
        }
コード例 #2
0
ファイル: ClaimActionTests.cs プロジェクト: wserr/AspNetCore
        public void MapAllSkipsDuplicateValues()
        {
            var userData = JsonDocument.Parse("{ \"name0\": \"value0\", \"name1\": \"value1\" }");

            var identity = new ClaimsIdentity();

            identity.AddClaim(new Claim("name0", "value0"));
            identity.AddClaim(new Claim("name1", "value1"));
            var action = new MapAllClaimsAction();

            action.Run(userData.RootElement, identity, "iss");

            Assert.Single(identity.FindAll("name0"));
            Assert.Single(identity.FindAll("name1"));
        }
コード例 #3
0
ファイル: ClaimActionTests.cs プロジェクト: wserr/AspNetCore
        public void MapAllAllowesDulicateKeysWithUniqueValues()
        {
            var userData = JsonDocument.Parse("{ \"name0\": \"value0\", \"name1\": \"value1\" }");

            var identity = new ClaimsIdentity();

            identity.AddClaim(new Claim("name0", "value2"));
            identity.AddClaim(new Claim("name1", "value3"));
            var action = new MapAllClaimsAction();

            action.Run(userData.RootElement, identity, "iss");

            Assert.Equal(2, identity.FindAll("name0").Count());
            Assert.Equal(2, identity.FindAll("name1").Count());
        }
コード例 #4
0
        public void MapAllSucceeds()
        {
            var userData = new JObject
            {
                ["name0"] = "value0",
                ["name1"] = "value1",
            };

            var identity = new ClaimsIdentity();
            var action   = new MapAllClaimsAction();

            action.Run(userData, identity, "iss");

            Assert.Equal("name0", identity.FindFirst("name0").Type);
            Assert.Equal("value0", identity.FindFirst("name0").Value);
            Assert.Equal("name1", identity.FindFirst("name1").Type);
            Assert.Equal("value1", identity.FindFirst("name1").Value);
        }
コード例 #5
0
        public void MapAllAllowesDulicateKeysWithUniqueValues()
        {
            var userData = new JObject
            {
                ["name0"] = "value0",
                ["name1"] = "value1",
            };

            var identity = new ClaimsIdentity();

            identity.AddClaim(new Claim("name0", "value2"));
            identity.AddClaim(new Claim("name1", "value3"));
            var action = new MapAllClaimsAction();

            action.Run(userData, identity, "iss");

            Assert.Equal(2, identity.FindAll("name0").Count());
            Assert.Equal(2, identity.FindAll("name1").Count());
        }
コード例 #6
0
        public void MapAllSkipsDuplicateValues()
        {
            var userData = new JObject
            {
                ["name0"] = "value0",
                ["name1"] = "value1",
            };

            var identity = new ClaimsIdentity();

            identity.AddClaim(new Claim("name0", "value0"));
            identity.AddClaim(new Claim("name1", "value1"));
            var action = new MapAllClaimsAction();

            action.Run(userData, identity, "iss");

            Assert.Single(identity.FindAll("name0"));
            Assert.Single(identity.FindAll("name1"));
        }
コード例 #7
0
        /// <summary>
        /// Событие получения маркера доступа.
        /// </summary>
        public override async Task TokenValidated(TokenValidatedContext context)
        {
            // We cannot use default UserInfoEndpoint because there are {oId} in uri, BLYATTTT!

            var userOid    = context.SecurityToken.Subject;
            var httpClient = context.Options.Backchannel;

            var httpRequest = new HttpRequestMessage(HttpMethod.Get, EsiaEnvironment.RestPersonsEndpoint + userOid);

            httpRequest.Headers.Authorization = new AuthenticationHeaderValue(context.TokenEndpointResponse.TokenType, context.TokenEndpointResponse.AccessToken);
            var prnsResult = await httpClient.SendAsync(httpRequest);

            if (prnsResult.IsSuccessStatusCode)
            {
                using var doc = JsonDocument.Parse(await prnsResult.Content.ReadAsStringAsync());
                var claimsAction = new MapAllClaimsAction();
                claimsAction.Run(doc.RootElement, context.Principal.Identity as ClaimsIdentity, "esia_prns");
            }

            context.Properties.SetString(EsiaDefaults.EnablesScopesPropertiesKey, string.Join(" ", (context.Properties as OpenIdConnectChallengeProperties)?.Scope ?? context.Options.Scope));
        }