Skip to content

Commit 6e54e06

Browse files
authored
Add nullable to Auth.Abstractions, and Auth.Core (#22541)
1 parent a963bbe commit 6e54e06

29 files changed

+239
-217
lines changed

src/Http/Authentication.Abstractions/ref/Microsoft.AspNetCore.Authentication.Abstractions.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
44
<TargetFrameworks>$(DefaultNetCoreTargetFramework)</TargetFrameworks>
5+
<Nullable>annotations</Nullable>
56
</PropertyGroup>
67
<ItemGroup Condition="'$(TargetFramework)' == '$(DefaultNetCoreTargetFramework)'">
78
<Compile Include="Microsoft.AspNetCore.Authentication.Abstractions.netcoreapp.cs" />

src/Http/Authentication.Abstractions/ref/Microsoft.AspNetCore.Authentication.Abstractions.netcoreapp.cs

Lines changed: 63 additions & 62 deletions
Large diffs are not rendered by default.

src/Http/Authentication.Abstractions/src/AuthenticateResult.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,22 @@ protected AuthenticateResult() { }
2424
/// <summary>
2525
/// The authentication ticket.
2626
/// </summary>
27-
public AuthenticationTicket Ticket { get; protected set; }
27+
public AuthenticationTicket? Ticket { get; protected set; }
2828

2929
/// <summary>
3030
/// Gets the claims-principal with authenticated user identities.
3131
/// </summary>
32-
public ClaimsPrincipal Principal => Ticket?.Principal;
32+
public ClaimsPrincipal? Principal => Ticket?.Principal;
3333

3434
/// <summary>
3535
/// Additional state values for the authentication session.
3636
/// </summary>
37-
public AuthenticationProperties Properties { get; protected set; }
37+
public AuthenticationProperties? Properties { get; protected set; }
3838

3939
/// <summary>
4040
/// Holds failure information from the authentication.
4141
/// </summary>
42-
public Exception Failure { get; protected set; }
42+
public Exception? Failure { get; protected set; }
4343

4444
/// <summary>
4545
/// Indicates that there was no information returned for this authentication scheme.
@@ -58,11 +58,11 @@ public AuthenticateResult Clone()
5858
}
5959
if (Failure != null)
6060
{
61-
return Fail(Failure, Properties.Clone());
61+
return Fail(Failure, Properties?.Clone());
6262
}
6363
if (Succeeded)
6464
{
65-
return Success(Ticket.Clone());
65+
return Success(Ticket!.Clone());
6666
}
6767
// This shouldn't happen
6868
throw new NotImplementedException();
@@ -96,7 +96,7 @@ public static AuthenticateResult NoResult()
9696
/// </summary>
9797
/// <param name="failure">The failure exception.</param>
9898
/// <returns>The result.</returns>
99-
public static AuthenticateResult Fail(Exception failure)
99+
public static AuthenticateResult Fail(Exception? failure)
100100
{
101101
return new AuthenticateResult() { Failure = failure };
102102
}
@@ -107,7 +107,7 @@ public static AuthenticateResult Fail(Exception failure)
107107
/// <param name="failure">The failure exception.</param>
108108
/// <param name="properties">Additional state values for the authentication session.</param>
109109
/// <returns>The result.</returns>
110-
public static AuthenticateResult Fail(Exception failure, AuthenticationProperties properties)
110+
public static AuthenticateResult Fail(Exception? failure, AuthenticationProperties? properties)
111111
{
112112
return new AuthenticateResult() { Failure = failure, Properties = properties };
113113
}
@@ -117,7 +117,7 @@ public static AuthenticateResult Fail(Exception failure, AuthenticationPropertie
117117
/// </summary>
118118
/// <param name="failureMessage">The failure message.</param>
119119
/// <returns>The result.</returns>
120-
public static AuthenticateResult Fail(string failureMessage)
120+
public static AuthenticateResult Fail(string? failureMessage)
121121
=> Fail(new Exception(failureMessage));
122122

123123
/// <summary>
@@ -126,7 +126,7 @@ public static AuthenticateResult Fail(string failureMessage)
126126
/// <param name="failureMessage">The failure message.</param>
127127
/// <param name="properties">Additional state values for the authentication session.</param>
128128
/// <returns>The result.</returns>
129-
public static AuthenticateResult Fail(string failureMessage, AuthenticationProperties properties)
129+
public static AuthenticateResult Fail(string? failureMessage, AuthenticationProperties? properties)
130130
=> Fail(new Exception(failureMessage), properties);
131131
}
132132
}

src/Http/Authentication.Abstractions/src/AuthenticationHttpContextExtensions.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static class AuthenticationHttpContextExtensions
1818
/// </summary>
1919
/// <param name="context">The <see cref="HttpContext"/> context.</param>
2020
/// <returns>The <see cref="AuthenticateResult"/>.</returns>
21-
public static Task<AuthenticateResult> AuthenticateAsync(this HttpContext context) =>
21+
public static Task<AuthenticateResult?> AuthenticateAsync(this HttpContext context) =>
2222
context.AuthenticateAsync(scheme: null);
2323

2424
/// <summary>
@@ -27,7 +27,7 @@ public static Task<AuthenticateResult> AuthenticateAsync(this HttpContext contex
2727
/// <param name="context">The <see cref="HttpContext"/> context.</param>
2828
/// <param name="scheme">The name of the authentication scheme.</param>
2929
/// <returns>The <see cref="AuthenticateResult"/>.</returns>
30-
public static Task<AuthenticateResult> AuthenticateAsync(this HttpContext context, string scheme) =>
30+
public static Task<AuthenticateResult?> AuthenticateAsync(this HttpContext context, string? scheme) =>
3131
context.RequestServices.GetRequiredService<IAuthenticationService>().AuthenticateAsync(context, scheme);
3232

3333
/// <summary>
@@ -53,7 +53,7 @@ public static Task ChallengeAsync(this HttpContext context) =>
5353
/// <param name="context">The <see cref="HttpContext"/> context.</param>
5454
/// <param name="properties">The <see cref="AuthenticationProperties"/> properties.</param>
5555
/// <returns>The task.</returns>
56-
public static Task ChallengeAsync(this HttpContext context, AuthenticationProperties properties) =>
56+
public static Task ChallengeAsync(this HttpContext context, AuthenticationProperties? properties) =>
5757
context.ChallengeAsync(scheme: null, properties: properties);
5858

5959
/// <summary>
@@ -63,7 +63,7 @@ public static Task ChallengeAsync(this HttpContext context, AuthenticationProper
6363
/// <param name="scheme">The name of the authentication scheme.</param>
6464
/// <param name="properties">The <see cref="AuthenticationProperties"/> properties.</param>
6565
/// <returns>The task.</returns>
66-
public static Task ChallengeAsync(this HttpContext context, string scheme, AuthenticationProperties properties) =>
66+
public static Task ChallengeAsync(this HttpContext context, string? scheme, AuthenticationProperties? properties) =>
6767
context.RequestServices.GetRequiredService<IAuthenticationService>().ChallengeAsync(context, scheme, properties);
6868

6969
/// <summary>
@@ -89,7 +89,7 @@ public static Task ForbidAsync(this HttpContext context) =>
8989
/// <param name="context">The <see cref="HttpContext"/> context.</param>
9090
/// <param name="properties">The <see cref="AuthenticationProperties"/> properties.</param>
9191
/// <returns>The task.</returns>
92-
public static Task ForbidAsync(this HttpContext context, AuthenticationProperties properties) =>
92+
public static Task ForbidAsync(this HttpContext context, AuthenticationProperties? properties) =>
9393
context.ForbidAsync(scheme: null, properties: properties);
9494

9595
/// <summary>
@@ -99,7 +99,7 @@ public static Task ForbidAsync(this HttpContext context, AuthenticationPropertie
9999
/// <param name="scheme">The name of the authentication scheme.</param>
100100
/// <param name="properties">The <see cref="AuthenticationProperties"/> properties.</param>
101101
/// <returns>The task.</returns>
102-
public static Task ForbidAsync(this HttpContext context, string scheme, AuthenticationProperties properties) =>
102+
public static Task ForbidAsync(this HttpContext context, string? scheme, AuthenticationProperties? properties) =>
103103
context.RequestServices.GetRequiredService<IAuthenticationService>().ForbidAsync(context, scheme, properties);
104104

105105
/// <summary>
@@ -128,7 +128,7 @@ public static Task SignInAsync(this HttpContext context, ClaimsPrincipal princip
128128
/// <param name="principal">The user.</param>
129129
/// <param name="properties">The <see cref="AuthenticationProperties"/> properties.</param>
130130
/// <returns>The task.</returns>
131-
public static Task SignInAsync(this HttpContext context, ClaimsPrincipal principal, AuthenticationProperties properties) =>
131+
public static Task SignInAsync(this HttpContext context, ClaimsPrincipal principal, AuthenticationProperties? properties) =>
132132
context.SignInAsync(scheme: null, principal: principal, properties: properties);
133133

134134
/// <summary>
@@ -139,7 +139,7 @@ public static Task SignInAsync(this HttpContext context, ClaimsPrincipal princip
139139
/// <param name="principal">The user.</param>
140140
/// <param name="properties">The <see cref="AuthenticationProperties"/> properties.</param>
141141
/// <returns>The task.</returns>
142-
public static Task SignInAsync(this HttpContext context, string scheme, ClaimsPrincipal principal, AuthenticationProperties properties) =>
142+
public static Task SignInAsync(this HttpContext context, string? scheme, ClaimsPrincipal principal, AuthenticationProperties? properties) =>
143143
context.RequestServices.GetRequiredService<IAuthenticationService>().SignInAsync(context, scheme, principal, properties);
144144

145145
/// <summary>
@@ -155,15 +155,15 @@ public static Task SignInAsync(this HttpContext context, string scheme, ClaimsPr
155155
/// <param name="context">The <see cref="HttpContext"/> context.</param>
156156
/// <param name="properties">The <see cref="AuthenticationProperties"/> properties.</param>
157157
/// <returns>The task.</returns>
158-
public static Task SignOutAsync(this HttpContext context, AuthenticationProperties properties) => context.SignOutAsync(scheme: null, properties: properties);
158+
public static Task SignOutAsync(this HttpContext context, AuthenticationProperties? properties) => context.SignOutAsync(scheme: null, properties: properties);
159159

160160
/// <summary>
161161
/// Extension method for SignOut.
162162
/// </summary>
163163
/// <param name="context">The <see cref="HttpContext"/> context.</param>
164164
/// <param name="scheme">The name of the authentication scheme.</param>
165165
/// <returns>The task.</returns>
166-
public static Task SignOutAsync(this HttpContext context, string scheme) => context.SignOutAsync(scheme, properties: null);
166+
public static Task SignOutAsync(this HttpContext context, string? scheme) => context.SignOutAsync(scheme, properties: null);
167167

168168
/// <summary>
169169
/// Extension method for SignOut.
@@ -172,7 +172,7 @@ public static Task SignInAsync(this HttpContext context, string scheme, ClaimsPr
172172
/// <param name="scheme">The name of the authentication scheme.</param>
173173
/// <param name="properties">The <see cref="AuthenticationProperties"/> properties.</param>
174174
/// <returns>The task.</returns>
175-
public static Task SignOutAsync(this HttpContext context, string scheme, AuthenticationProperties properties) =>
175+
public static Task SignOutAsync(this HttpContext context, string? scheme, AuthenticationProperties? properties) =>
176176
context.RequestServices.GetRequiredService<IAuthenticationService>().SignOutAsync(context, scheme, properties);
177177

178178
/// <summary>
@@ -182,7 +182,7 @@ public static Task SignOutAsync(this HttpContext context, string scheme, Authent
182182
/// <param name="scheme">The name of the authentication scheme.</param>
183183
/// <param name="tokenName">The name of the token.</param>
184184
/// <returns>The value of the token.</returns>
185-
public static Task<string> GetTokenAsync(this HttpContext context, string scheme, string tokenName) =>
185+
public static Task<string?> GetTokenAsync(this HttpContext context, string? scheme, string tokenName) =>
186186
context.RequestServices.GetRequiredService<IAuthenticationService>().GetTokenAsync(context, scheme, tokenName);
187187

188188
/// <summary>
@@ -191,7 +191,7 @@ public static Task<string> GetTokenAsync(this HttpContext context, string scheme
191191
/// <param name="context">The <see cref="HttpContext"/> context.</param>
192192
/// <param name="tokenName">The name of the token.</param>
193193
/// <returns>The value of the token.</returns>
194-
public static Task<string> GetTokenAsync(this HttpContext context, string tokenName) =>
194+
public static Task<string?> GetTokenAsync(this HttpContext context, string tokenName) =>
195195
context.RequestServices.GetRequiredService<IAuthenticationService>().GetTokenAsync(context, tokenName);
196196
}
197197
}

src/Http/Authentication.Abstractions/src/AuthenticationOptions.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,32 +64,32 @@ public void AddScheme<THandler>(string name, string displayName) where THandler
6464
/// <summary>
6565
/// Used as the fallback default scheme for all the other defaults.
6666
/// </summary>
67-
public string DefaultScheme { get; set; }
67+
public string? DefaultScheme { get; set; }
6868

6969
/// <summary>
7070
/// Used as the default scheme by <see cref="IAuthenticationService.AuthenticateAsync(HttpContext, string)"/>.
7171
/// </summary>
72-
public string DefaultAuthenticateScheme { get; set; }
72+
public string? DefaultAuthenticateScheme { get; set; }
7373

7474
/// <summary>
7575
/// Used as the default scheme by <see cref="IAuthenticationService.SignInAsync(HttpContext, string, System.Security.Claims.ClaimsPrincipal, AuthenticationProperties)"/>.
7676
/// </summary>
77-
public string DefaultSignInScheme { get; set; }
77+
public string? DefaultSignInScheme { get; set; }
7878

7979
/// <summary>
8080
/// Used as the default scheme by <see cref="IAuthenticationService.SignOutAsync(HttpContext, string, AuthenticationProperties)"/>.
8181
/// </summary>
82-
public string DefaultSignOutScheme { get; set; }
82+
public string? DefaultSignOutScheme { get; set; }
8383

8484
/// <summary>
8585
/// Used as the default scheme by <see cref="IAuthenticationService.ChallengeAsync(HttpContext, string, AuthenticationProperties)"/>.
8686
/// </summary>
87-
public string DefaultChallengeScheme { get; set; }
87+
public string? DefaultChallengeScheme { get; set; }
8888

8989
/// <summary>
9090
/// Used as the default scheme by <see cref="IAuthenticationService.ForbidAsync(HttpContext, string, AuthenticationProperties)"/>.
9191
/// </summary>
92-
public string DefaultForbidScheme { get; set; }
92+
public string? DefaultForbidScheme { get; set; }
9393

9494
/// <summary>
9595
/// If true, SignIn should throw if attempted with a ClaimsPrincipal.Identity.IsAuthenticated = false.

0 commit comments

Comments
 (0)