-
Notifications
You must be signed in to change notification settings - Fork 191
Print available scheme names in exception message for invalid scheme #961
Conversation
if (handler == null) | ||
{ | ||
throw new InvalidOperationException($"No authentication handler is configured to authenticate for the scheme: {scheme}"); | ||
var schemes = await GetAllSchemeNames(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Helper like throw await CreateMissingHandlerError(scheme)
?
|
||
if (string.IsNullOrEmpty(schemes)) | ||
{ | ||
return "[none]"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naw, I think the message should be different instead of saying none.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"There are no registered authentication schemes."?
Then what?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"You need to add your authentication scheme to the AuthenticationBuilder returned by AddAuthentication()"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or "Did you forget to call AddAuthentication().AddScheme()?"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's only so much we can cram in here. How about a fwlink to the auth docs instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The EF team is notorious for good error message like this. It's super valuable.
210e1d8
to
9683013
Compare
{ | ||
// CookieAuth is the only implementation of sign-in. | ||
return new InvalidOperationException(mismatchError | ||
+ $"Did you intended to call AddAuthentication().AddCookies(\"Cookies\") and SignInAsync(\"Cookies\",...)?"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: intended => intend
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or should just be consistent and use forget?
{ | ||
// CookieAuth is the most common implementation of sign-out, but OpenIdConnect and WsFederation also support it. | ||
return new InvalidOperationException(mismatchError | ||
+ $"Did you intended to call AddAuthentication().AddCookies(\"Cookies\") and {nameof(SignOutAsync)}(\"Cookies\",...)?"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo here too
#955 A lot of users mess up their auth scheme registrations. This adds more information to the error messages to help them figure out what's wrong.