-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add nullable annotations to Authentication.Core & Authentication.Cookies #24307
Conversation
@@ -17,7 +17,7 @@ public class AuthenticationTicket | |||
/// <param name="principal">the <see cref="ClaimsPrincipal"/> that represents the authenticated user.</param> | |||
/// <param name="properties">additional properties that can be consumed by the user or runtime.</param> | |||
/// <param name="authenticationScheme">the authentication middleware that was responsible for this ticket.</param> | |||
public AuthenticationTicket(ClaimsPrincipal principal, AuthenticationProperties? properties, string? authenticationScheme) | |||
public AuthenticationTicket(ClaimsPrincipal principal, AuthenticationProperties? properties, string authenticationScheme) |
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.
Should authenticationScheme throw ArgumentNullException if null?
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.
We generally haven't added explicit null-checks to our code to express the non-nullness. IIRC, there was one code path that would result in an arg-null \ null-ref if the scheme was null, but I wasn't a 100% certain if this was the right default
@@ -122,7 +123,7 @@ private AuthenticationTicket CloneTicket(AuthenticationTicket ticket, ClaimsPrin | |||
|
|||
private async Task<AuthenticateResult> ReadCookieTicket() | |||
{ | |||
var cookie = Options.CookieManager.GetRequestCookie(Context, Options.Cookie.Name); | |||
var cookie = Options.CookieManager.GetRequestCookie(Context, Options.Cookie.Name!); |
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.
What happens if Options.Cookie.Name is null?
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.
In the default case, this is guaranteed to be non-null. The option configures it to a value and you cannot assign a null value to it.
|
||
/// <summary> | ||
/// Calls success creating a ticket with the <see cref="Principal"/> and <see cref="Properties"/>. | ||
/// </summary> | ||
public void Success() => Result = HandleRequestResult.Success(new AuthenticationTicket(Principal, Properties, Scheme.Name)); | ||
public void Success() => Result = HandleRequestResult.Success(new AuthenticationTicket(Principal!, Properties, Scheme.Name)); |
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.
What happens if Principal is null? Ok because AuthenticationTicket checks for null?
namespace Microsoft.AspNetCore.Authentication | ||
{ | ||
public interface IDataSerializer<TModel> | ||
{ | ||
byte[] Serialize(TModel model); | ||
|
||
[return: MaybeNull] |
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.
This is fine for now, but we could switch MaybeNull/AllowNull attributes to use ? before .NET 5
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 version of the compiler we have doesn't support this as yet.
Contributes to #5680