diff --git a/src/Nancy.Authentication.Forms.Tests/FormsAuthenticationFixture.cs b/src/Nancy.Authentication.Forms.Tests/FormsAuthenticationFixture.cs index d0a6897f9c..487b850ab8 100644 --- a/src/Nancy.Authentication.Forms.Tests/FormsAuthenticationFixture.cs +++ b/src/Nancy.Authentication.Forms.Tests/FormsAuthenticationFixture.cs @@ -348,7 +348,7 @@ public void Should_get_username_from_mapping_service_with_valid_cookie() fakePipelines.BeforeRequest.Invoke(this.context); - A.CallTo(() => mockMapper.GetUserFromIdentifier(this.userGuid)) + A.CallTo(() => mockMapper.GetUserFromIdentifier(this.userGuid, this.context)) .MustHaveHappened(Repeated.Exactly.Once); } @@ -359,7 +359,7 @@ public void Should_set_user_in_context_with_valid_cookie() var fakeMapper = A.Fake(); var fakeUser = A.Fake(); fakeUser.UserName = "Bob"; - A.CallTo(() => fakeMapper.GetUserFromIdentifier(this.userGuid)).Returns(fakeUser); + A.CallTo(() => fakeMapper.GetUserFromIdentifier(this.userGuid, this.context)).Returns(fakeUser); this.config.UserMapper = fakeMapper; FormsAuthentication.Enable(fakePipelines, this.config); this.context.Request.Cookies.Add(FormsAuthentication.FormsAuthenticationCookieName, this.validCookieValue); @@ -376,7 +376,7 @@ public void Should_not_set_user_in_context_with_invalid_hmac() var fakeMapper = A.Fake(); var fakeUser = A.Fake(); fakeUser.UserName = "Bob"; - A.CallTo(() => fakeMapper.GetUserFromIdentifier(this.userGuid)).Returns(fakeUser); + A.CallTo(() => fakeMapper.GetUserFromIdentifier(this.userGuid, this.context)).Returns(fakeUser); this.config.UserMapper = fakeMapper; FormsAuthentication.Enable(fakePipelines, this.config); this.context.Request.Cookies.Add(FormsAuthentication.FormsAuthenticationCookieName, this.cookieWithInvalidHmac); @@ -393,7 +393,7 @@ public void Should_not_set_user_in_context_with_empty_hmac() var fakeMapper = A.Fake(); var fakeUser = A.Fake(); fakeUser.UserName = "Bob"; - A.CallTo(() => fakeMapper.GetUserFromIdentifier(this.userGuid)).Returns(fakeUser); + A.CallTo(() => fakeMapper.GetUserFromIdentifier(this.userGuid, this.context)).Returns(fakeUser); this.config.UserMapper = fakeMapper; FormsAuthentication.Enable(fakePipelines, this.config); this.context.Request.Cookies.Add(FormsAuthentication.FormsAuthenticationCookieName, this.cookieWithEmptyHmac); @@ -410,7 +410,7 @@ public void Should_not_set_user_in_context_with_no_hmac() var fakeMapper = A.Fake(); var fakeUser = A.Fake(); fakeUser.UserName = "Bob"; - A.CallTo(() => fakeMapper.GetUserFromIdentifier(this.userGuid)).Returns(fakeUser); + A.CallTo(() => fakeMapper.GetUserFromIdentifier(this.userGuid, this.context)).Returns(fakeUser); this.config.UserMapper = fakeMapper; FormsAuthentication.Enable(fakePipelines, this.config); this.context.Request.Cookies.Add(FormsAuthentication.FormsAuthenticationCookieName, this.cookieWithNoHmac); @@ -427,7 +427,7 @@ public void Should_not_set_username_in_context_with_broken_encryption_data() var fakeMapper = A.Fake(); var fakeUser = A.Fake(); fakeUser.UserName = "Bob"; - A.CallTo(() => fakeMapper.GetUserFromIdentifier(this.userGuid)).Returns(fakeUser); + A.CallTo(() => fakeMapper.GetUserFromIdentifier(this.userGuid, this.context)).Returns(fakeUser); this.config.UserMapper = fakeMapper; FormsAuthentication.Enable(fakePipelines, this.config); this.context.Request.Cookies.Add(FormsAuthentication.FormsAuthenticationCookieName, this.cookieWithBrokenEncryptedData); diff --git a/src/Nancy.Authentication.Forms/FormsAuthentication.cs b/src/Nancy.Authentication.Forms/FormsAuthentication.cs index 26bc5b3518..546e13d6a3 100644 --- a/src/Nancy.Authentication.Forms/FormsAuthentication.cs +++ b/src/Nancy.Authentication.Forms/FormsAuthentication.cs @@ -164,8 +164,8 @@ private static Func GetLoadAuthenticationHook(FormsAuthe if (userGuid != Guid.Empty) { - context.CurrentUser = - configuration.UserMapper.GetUserFromIdentifier(userGuid); + + context.CurrentUser = configuration.UserMapper.GetUserFromIdentifier(userGuid, context); } return null; diff --git a/src/Nancy.Authentication.Forms/IUsernameMapper.cs b/src/Nancy.Authentication.Forms/IUsernameMapper.cs index ad89a84298..c33d5cfe49 100644 --- a/src/Nancy.Authentication.Forms/IUsernameMapper.cs +++ b/src/Nancy.Authentication.Forms/IUsernameMapper.cs @@ -14,7 +14,8 @@ public interface IUserMapper /// Get the real username from an indentifier /// /// User identifier - /// Matching username, or empty - IUserIdentity GetUserFromIdentifier(Guid identifier); + /// The current NancyFx context + /// Matching populated IUserIdentity object, or empty + IUserIdentity GetUserFromIdentifier(Guid identifier, NancyContext context); } } \ No newline at end of file diff --git a/src/Nancy.Demo.Authentication.Forms/UserDatabase.cs b/src/Nancy.Demo.Authentication.Forms/UserDatabase.cs index 203dd5e944..c1ac762df1 100644 --- a/src/Nancy.Demo.Authentication.Forms/UserDatabase.cs +++ b/src/Nancy.Demo.Authentication.Forms/UserDatabase.cs @@ -18,7 +18,7 @@ static UserDatabase() users.Add(new Tuple("user", "password", new Guid("56E1E49E-B7E8-4EEA-8459-7A906AC4D4C0"))); } - public IUserIdentity GetUserFromIdentifier(Guid identifier) + public IUserIdentity GetUserFromIdentifier(Guid identifier, NancyContext context) { var userRecord = users.Where(u => u.Item3 == identifier).FirstOrDefault();