コード例 #1
0
        public void CanUpdateTokens()
        {
            var props  = new AuthenticationProperties();
            var tokens = new List <AuthenticationToken>();
            var tok1   = new AuthenticationToken {
                Name = "One", Value = "1"
            };
            var tok2 = new AuthenticationToken {
                Name = "Two", Value = "2"
            };
            var tok3 = new AuthenticationToken {
                Name = "Three", Value = "3"
            };

            tokens.Add(tok1);
            tokens.Add(tok2);
            tokens.Add(tok3);
            props.StoreTokens(tokens);

            tok1.Value = ".1";
            tok2.Value = ".2";
            tok3.Value = ".3";
            props.StoreTokens(tokens);

            Assert.Equal(".1", props.GetTokenValue("One"));
            Assert.Equal(".2", props.GetTokenValue("Two"));
            Assert.Equal(".3", props.GetTokenValue("Three"));
            Assert.Equal(3, props.GetTokens().Count());
        }
コード例 #2
0
        public void SubsequentStoreTokenDeletesPreviousTokens()
        {
            var props  = new AuthenticationProperties();
            var tokens = new List <AuthenticationToken>();
            var tok1   = new AuthenticationToken {
                Name = "One", Value = "1"
            };
            var tok2 = new AuthenticationToken {
                Name = "Two", Value = "2"
            };
            var tok3 = new AuthenticationToken {
                Name = "Three", Value = "3"
            };

            tokens.Add(tok1);
            tokens.Add(tok2);
            tokens.Add(tok3);

            props.StoreTokens(tokens);

            props.StoreTokens(new[] { new AuthenticationToken {
                                          Name = "Zero", Value = "0"
                                      } });

            Assert.Equal("0", props.GetTokenValue("Zero"));
            Assert.Null(props.GetTokenValue("One"));
            Assert.Null(props.GetTokenValue("Two"));
            Assert.Null(props.GetTokenValue("Three"));
            Assert.Single(props.GetTokens());
        }
コード例 #3
0
        public void UpdateTokenValueReturnsFalseForUnknownToken()
        {
            var props  = new AuthenticationProperties();
            var tokens = new List <AuthenticationToken>();
            var tok1   = new AuthenticationToken {
                Name = "One", Value = "1"
            };
            var tok2 = new AuthenticationToken {
                Name = "Two", Value = "2"
            };
            var tok3 = new AuthenticationToken {
                Name = "Three", Value = "3"
            };

            tokens.Add(tok1);
            tokens.Add(tok2);
            tokens.Add(tok3);
            props.StoreTokens(tokens);

            Assert.False(props.UpdateTokenValue("ONE", ".11"));
            Assert.False(props.UpdateTokenValue("Jigglypuff", ".11"));

            Assert.Null(props.GetTokenValue("ONE"));
            Assert.Null(props.GetTokenValue("Jigglypuff"));
            Assert.Equal(3, props.GetTokens().Count());
        }
        /// <summary>
        /// Returns all of the AuthenticationTokens contained in the properties.
        /// </summary>
        /// <param name="properties">The <see cref="AuthenticationProperties"/> properties.</param>
        /// <returns>The authentication toekns.</returns>
        public static IEnumerable <AuthenticationToken> GetTokens(this AuthenticationProperties properties)
        {
            if (properties == null)
            {
                throw new ArgumentNullException(nameof(properties));
            }

            var tokens = new List <AuthenticationToken>();

            if (properties.Items.ContainsKey(TokenNamesKey))
            {
                var tokenNames = properties.Items[TokenNamesKey].Split(';');
                foreach (var name in tokenNames)
                {
                    var token = properties.GetTokenValue(name);
                    if (token != null)
                    {
                        tokens.Add(new AuthenticationToken {
                            Name = name, Value = token
                        });
                    }
                }
            }

            return(tokens);
        }
コード例 #5
0
        /// <summary>
        /// Returns all of the <see cref="AuthenticationToken"/> instances contained in the properties.
        /// </summary>
        /// <param name="properties">The <see cref="AuthenticationProperties"/> properties.</param>
        /// <returns>The authentication tokens.</returns>
        public static IEnumerable <AuthenticationToken> GetTokens(this AuthenticationProperties properties)
        {
            if (properties == null)
            {
                throw new ArgumentNullException(nameof(properties));
            }

            var tokens = new List <AuthenticationToken>();

            if (properties.Items.TryGetValue(TokenNamesKey, out var value) && !string.IsNullOrEmpty(value))
            {
                var tokenNames = value.Split(';');
                foreach (var name in tokenNames)
                {
                    var token = properties.GetTokenValue(name);
                    if (token != null)
                    {
                        tokens.Add(new AuthenticationToken {
                            Name = name, Value = token
                        });
                    }
                }
            }

            return(tokens);
        }