Skip to content
This repository has been archived by the owner on Jan 24, 2021. It is now read-only.

FormsAuthentication Login/logout methods assume configuration is not null #1755

Open
Worthaboutapig opened this issue Nov 29, 2014 · 2 comments
Labels

Comments

@Worthaboutapig
Copy link

The (public) methods to Nancy.Authentication.Forms.FormsAuthentication login and logout methods, e.g. UserLoggedInRedirectResponse(..) or LogOutAndRedirectResponse(...) assume that the FormsAuthenticationConfiguration currentConfiguration has been set by the Enable method.

However, if it's not, then BuildCookie throws a NullReferenceException at runtime, with no explanation of what's wrong. It's taken me about an hour to track down that I'm returning from the bootstrapper RequestStartup before setting the forms configuration. It's a silly mistake, but easy to make.

Would there be an objection to adding a guard on these methods, something like:

if (configuration == null)
{
throw new InvalidOperationException("The internal FormsAuthenticationConfiguration has not been set. Ensure that FormsAuthentication has been enabled in the bootstrapper.");
}

@Crisfole
Copy link
Contributor

Crisfole commented Dec 5, 2014

+1 for anything that makes tracking down mysterious errors more obvious

@Worthaboutapig
Copy link
Author

I've made the changes and created a Pull Request.

Worthaboutapig added a commit to Worthaboutapig/Nancy that referenced this issue Feb 6, 2015
Worthaboutapig added a commit to Worthaboutapig/Nancy that referenced this issue Apr 30, 2015
Worthaboutapig added a commit to Worthaboutapig/Nancy that referenced this issue Apr 30, 2015
@thecodejunkie thecodejunkie added this to the 1.3 milestone Aug 26, 2015
@jchannon jchannon modified the milestones: 1.4, 1.3 Sep 14, 2015
@thecodejunkie thecodejunkie modified the milestones: 2.0, 1.4 Sep 24, 2015
@khellang khellang modified the milestones: 2.0, 2.0-beta Mar 22, 2016
@thecodejunkie thecodejunkie modified the milestones: 2.0-barneyrubble, 2.1 Jul 12, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants