/// <summary>
        /// This method is called whenever claims about the user are requested (e.g. during token creation or via the userinfo endpoint)
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public virtual Task GetProfileDataAsync(ProfileDataRequestContext context)
        {
            var logValues = new FormattedLogValues("Get profile called for subject {subject} from client {client} with claim types {claimTypes} via {caller}",
                                                   context.Subject.GetSubjectId(),
                                                   context.Client.ClientName ?? context.Client.ClientId,
                                                   context.RequestedClaimTypes,
                                                   context.Caller);

            Logger.LogDebug(logValues.ToString());

            if (context.RequestedClaimTypes.Any())
            {
                var user = Users.FindBySubjectId(context.Subject.GetSubjectId());
                if (user != null)
                {
                    context.AddFilteredClaims(user.Claims);
                }
                else
                {
                    Logger.LogWarning("Users.FindBySubjectId returned null when " + logValues.ToString());
                }
            }

            return(Task.FromResult(0));
        }
        public void ClonesSimpleSuccessfully()
        {
            var original = new FormattedLogValues("Foo");
            var cloned   = original.Clone();

            Assert.Equal(original.ToString(), cloned.ToString());
        }
 public void LogValues_With_UnbalancedBraces(string format)
 {
     Assert.Throws <FormatException>(() =>
     {
         var logValues = new FormattedLogValues(format, new object[] { "arg1" });
         logValues.ToString();
     });
 }
        public void ClonesComplexSuccessfully()
        {
            var original = new FormattedLogValues("The first number is {first} and the second is {second}", 10.ToString(), 20.ToString());
            var cloned   = original.Clone();

            Assert.Equal(original.ToString(), cloned.ToString());
            Assert.True(original.GetValues().SequenceEqual(cloned.GetValues()));
        }
        public void LogValues_With_Basic_Types(string expected, string format, object[] args)
        {
            var logValues = new FormattedLogValues(format, args);

            Assert.Equal(expected, logValues.ToString());

            // Original format is expected to be returned from GetValues.
            Assert.Equal(format, logValues.First(v => v.Key == "{OriginalFormat}").Value);
        }
        public void LogValues_With_DateTime(string expected, string format)
        {
            var dateTime  = new DateTime(2015, 1, 1, 1, 1, 1);
            var logValues = new FormattedLogValues(format, new object[] { dateTime, dateTime });

            Assert.Equal(expected, logValues.ToString());

            // Original format is expected to be returned from GetValues.
            Assert.Equal(format, logValues.First(v => v.Key == "{OriginalFormat}").Value);
        }
        public void LogValues_WithNullAndEnumerable_IsNotMutatingParameter()
        {
            string format = "TestMessage {Param1} {Param2} {Param3} {Param4}";
            int    param1 = 1;
            string param2 = null;

            int[]  param3 = new[] { 1, 2, 3, 4 };
            string param4 = "string";

            var logValues = new FormattedLogValues(format, param1, param2, param3, param4);

            logValues.ToString();

            var state = logValues.ToArray();

            Assert.Equal(new[]
            {
                new KeyValuePair <string, object>("Param1", param1),
                new KeyValuePair <string, object>("Param2", param2),
                new KeyValuePair <string, object>("Param3", param3),
                new KeyValuePair <string, object>("Param4", param4),
                new KeyValuePair <string, object>("{OriginalFormat}", format),
            }, state);
        }
        public void LogValues_WithNulls(string expected, string format, object[] args)
        {
            var logValues = new FormattedLogValues(format, args);

            Assert.Equal(expected, logValues.ToString());
        }
        public void FormatsEnumerableValues(string messageFormat, object[] arguments, string expected)
        {
            var logValues = new FormattedLogValues(messageFormat, arguments);

            Assert.Equal(expected, logValues.ToString());
        }
 public override string ToString() => _formatter.ToString();
Exemple #11
0
 private static string FormatMessage(FormattedLogValues state, Exception error)
 {
     return(state.ToString());
 }
        private static bool messageMatches(string expectedMessage, FormattedLogValues formattedLogValues)
        {
            // separate method as opposed to lambda for easier debugging

            return(formattedLogValues.ToString() == expectedMessage);
        }
Exemple #13
0
 private static string MessageFormatter(FormattedLogValues state, Exception error) => state.ToString();