Skip to content

Commit 206ed86

Browse files
authored
Enable nullable on more authentication projects (#31230)
1 parent 70e7c40 commit 206ed86

File tree

52 files changed

+588
-233
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+588
-233
lines changed

src/Security/Authentication/Core/src/Events/RemoteAuthenticationContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected RemoteAuthenticationContext(
3535
/// <summary>
3636
/// Gets or sets the <see cref="AuthenticationProperties"/>.
3737
/// </summary>
38-
public virtual AuthenticationProperties Properties { get; set; }
38+
public virtual AuthenticationProperties? Properties { get; set; }
3939

4040
/// <summary>
4141
/// Calls success creating a ticket with the <see cref="Principal"/> and <see cref="Properties"/>.

src/Security/Authentication/Core/src/HandleRequestResult.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class HandleRequestResult : AuthenticateResult
5252
/// <param name="failure">The failure exception.</param>
5353
/// <param name="properties">Additional state values for the authentication session.</param>
5454
/// <returns>The result.</returns>
55-
public static new HandleRequestResult Fail(Exception failure, AuthenticationProperties properties)
55+
public static new HandleRequestResult Fail(Exception failure, AuthenticationProperties? properties)
5656
{
5757
return new HandleRequestResult() { Failure = failure, Properties = properties };
5858
}
@@ -71,7 +71,7 @@ public class HandleRequestResult : AuthenticateResult
7171
/// <param name="failureMessage">The failure message.</param>
7272
/// <param name="properties">Additional state values for the authentication session.</param>
7373
/// <returns>The result.</returns>
74-
public static new HandleRequestResult Fail(string failureMessage, AuthenticationProperties properties)
74+
public static new HandleRequestResult Fail(string failureMessage, AuthenticationProperties? properties)
7575
=> Fail(new Exception(failureMessage), properties);
7676

7777
/// <summary>

src/Security/Authentication/Core/src/IDataSerializer.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public interface IDataSerializer<TModel>
2323
/// </summary>
2424
/// <param name="data">The bytes being deserialized.</param>
2525
/// <returns>The model.</returns>
26-
[return: MaybeNull]
27-
TModel Deserialize(byte[] data);
26+
TModel? Deserialize(byte[] data);
2827
}
2928
}

src/Security/Authentication/Core/src/ISecureDataFormat.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,14 @@ public interface ISecureDataFormat<TData>
3131
/// </summary>
3232
/// <param name="protectedText">The data protected value.</param>
3333
/// <returns>An instance of <typeparamref name="TData"/>.</returns>
34-
[return: MaybeNull]
35-
TData Unprotect(string protectedText);
34+
TData? Unprotect(string? protectedText);
3635

3736
/// <summary>
3837
/// Unprotects the specified <paramref name="protectedText"/> using the specified <paramref name="purpose"/>.
3938
/// </summary>
4039
/// <param name="protectedText">The data protected value.</param>
4140
/// <param name="purpose">The purpose.</param>
4241
/// <returns>An instance of <typeparamref name="TData"/>.</returns>
43-
[return: MaybeNull]
44-
TData Unprotect(string protectedText, string? purpose);
42+
TData? Unprotect(string? protectedText, string? purpose);
4543
}
4644
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
11
#nullable enable
22
*REMOVED*Microsoft.AspNetCore.Authentication.AuthenticationSchemeOptions.ForwardDefaultSelector.get -> System.Func<Microsoft.AspNetCore.Http.HttpContext!, string!>?
33
Microsoft.AspNetCore.Authentication.AuthenticationSchemeOptions.ForwardDefaultSelector.get -> System.Func<Microsoft.AspNetCore.Http.HttpContext!, string?>?
4+
Microsoft.AspNetCore.Authentication.IDataSerializer<TModel>.Deserialize(byte[]! data) -> TModel?
5+
Microsoft.AspNetCore.Authentication.ISecureDataFormat<TData>.Unprotect(string? protectedText) -> TData?
6+
Microsoft.AspNetCore.Authentication.ISecureDataFormat<TData>.Unprotect(string? protectedText, string? purpose) -> TData?
7+
Microsoft.AspNetCore.Authentication.SecureDataFormat<TData>.Unprotect(string? protectedText) -> TData?
8+
Microsoft.AspNetCore.Authentication.SecureDataFormat<TData>.Unprotect(string? protectedText, string? purpose) -> TData?
9+
static Microsoft.AspNetCore.Authentication.HandleRequestResult.Fail(System.Exception! failure, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) -> Microsoft.AspNetCore.Authentication.HandleRequestResult!
10+
static Microsoft.AspNetCore.Authentication.HandleRequestResult.Fail(string! failureMessage, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) -> Microsoft.AspNetCore.Authentication.HandleRequestResult!
11+
virtual Microsoft.AspNetCore.Authentication.RemoteAuthenticationContext<TOptions>.Properties.get -> Microsoft.AspNetCore.Authentication.AuthenticationProperties?
12+
*REMOVED*Microsoft.AspNetCore.Authentication.IDataSerializer<TModel>.Deserialize(byte[]! data) -> TModel
13+
*REMOVED*Microsoft.AspNetCore.Authentication.ISecureDataFormat<TData>.Unprotect(string! protectedText) -> TData
14+
*REMOVED*Microsoft.AspNetCore.Authentication.ISecureDataFormat<TData>.Unprotect(string! protectedText, string? purpose) -> TData
15+
*REMOVED*Microsoft.AspNetCore.Authentication.SecureDataFormat<TData>.Unprotect(string! protectedText) -> TData
16+
*REMOVED*Microsoft.AspNetCore.Authentication.SecureDataFormat<TData>.Unprotect(string! protectedText, string? purpose) -> TData
17+
*REMOVED*static Microsoft.AspNetCore.Authentication.HandleRequestResult.Fail(System.Exception! failure, Microsoft.AspNetCore.Authentication.AuthenticationProperties! properties) -> Microsoft.AspNetCore.Authentication.HandleRequestResult!
18+
*REMOVED*static Microsoft.AspNetCore.Authentication.HandleRequestResult.Fail(string! failureMessage, Microsoft.AspNetCore.Authentication.AuthenticationProperties! properties) -> Microsoft.AspNetCore.Authentication.HandleRequestResult!
19+
*REMOVED*virtual Microsoft.AspNetCore.Authentication.RemoteAuthenticationContext<TOptions>.Properties.get -> Microsoft.AspNetCore.Authentication.AuthenticationProperties!

src/Security/Authentication/Core/src/RemoteAuthenticationHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public virtual async Task<bool> HandleRequestAsync()
145145
ticket.Properties.RedirectUri = null;
146146

147147
// Mark which provider produced this identity so we can cross-check later in HandleAuthenticateAsync
148-
ticketContext.Properties.Items[AuthSchemeKey] = Scheme.Name;
148+
ticketContext.Properties!.Items[AuthSchemeKey] = Scheme.Name;
149149

150150
await Events.TicketReceived(ticketContext);
151151

src/Security/Authentication/Core/src/SecureDataFormat.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,13 @@ public string Protect(TData data, string? purpose)
4848
}
4949

5050
/// <inheritdoc />
51-
[return: MaybeNull]
52-
public TData Unprotect(string protectedText)
51+
public TData? Unprotect(string? protectedText)
5352
{
5453
return Unprotect(protectedText, purpose: null);
5554
}
5655

5756
/// <inheritdoc />
58-
[return: MaybeNull]
59-
public TData Unprotect(string protectedText, string? purpose)
57+
public TData? Unprotect(string? protectedText, string? purpose)
6058
{
6159
try
6260
{

src/Security/Authentication/Facebook/src/FacebookHandler.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ public FacebookHandler(IOptionsMonitor<FacebookOptions> options, ILoggerFactory
3333
/// <inheritdoc />
3434
protected override async Task<AuthenticationTicket> CreateTicketAsync(ClaimsIdentity identity, AuthenticationProperties properties, OAuthTokenResponse tokens)
3535
{
36-
var endpoint = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "access_token", tokens.AccessToken);
36+
var endpoint = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "access_token", tokens.AccessToken!);
3737
if (Options.SendAppSecretProof)
3838
{
39-
endpoint = QueryHelpers.AddQueryString(endpoint, "appsecret_proof", GenerateAppSecretProof(tokens.AccessToken));
39+
endpoint = QueryHelpers.AddQueryString(endpoint, "appsecret_proof", GenerateAppSecretProof(tokens.AccessToken!));
4040
}
4141
if (Options.Fields.Count > 0)
4242
{
@@ -54,7 +54,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(ClaimsIden
5454
var context = new OAuthCreatingTicketContext(new ClaimsPrincipal(identity), properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);
5555
context.RunClaimActions();
5656
await Events.CreatingTicket(context);
57-
return new AuthenticationTicket(context.Principal, context.Properties, Scheme.Name);
57+
return new AuthenticationTicket(context.Principal!, context.Properties, Scheme.Name);
5858
}
5959
}
6060

src/Security/Authentication/Facebook/src/Microsoft.AspNetCore.Authentication.Facebook.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
66
<GenerateDocumentationFile>true</GenerateDocumentationFile>
77
<PackageTags>aspnetcore;authentication;security</PackageTags>
8+
<Nullable>enable</Nullable>
89
</PropertyGroup>
910

1011
<ItemGroup>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,19 @@
11
#nullable enable
2+
Microsoft.AspNetCore.Authentication.Facebook.FacebookHandler.FacebookHandler(Microsoft.Extensions.Options.IOptionsMonitor<Microsoft.AspNetCore.Authentication.Facebook.FacebookOptions!>! options, Microsoft.Extensions.Logging.ILoggerFactory! logger, System.Text.Encodings.Web.UrlEncoder! encoder, Microsoft.AspNetCore.Authentication.ISystemClock! clock) -> void
3+
Microsoft.AspNetCore.Authentication.Facebook.FacebookOptions.AppId.get -> string!
4+
Microsoft.AspNetCore.Authentication.Facebook.FacebookOptions.AppId.set -> void
5+
Microsoft.AspNetCore.Authentication.Facebook.FacebookOptions.AppSecret.get -> string!
6+
Microsoft.AspNetCore.Authentication.Facebook.FacebookOptions.AppSecret.set -> void
7+
Microsoft.AspNetCore.Authentication.Facebook.FacebookOptions.Fields.get -> System.Collections.Generic.ICollection<string!>!
8+
const Microsoft.AspNetCore.Authentication.Facebook.FacebookDefaults.AuthenticationScheme = "Facebook" -> string!
9+
override Microsoft.AspNetCore.Authentication.Facebook.FacebookHandler.CreateTicketAsync(System.Security.Claims.ClaimsIdentity! identity, Microsoft.AspNetCore.Authentication.AuthenticationProperties! properties, Microsoft.AspNetCore.Authentication.OAuth.OAuthTokenResponse! tokens) -> System.Threading.Tasks.Task<Microsoft.AspNetCore.Authentication.AuthenticationTicket!>!
10+
override Microsoft.AspNetCore.Authentication.Facebook.FacebookHandler.FormatScope() -> string!
11+
override Microsoft.AspNetCore.Authentication.Facebook.FacebookHandler.FormatScope(System.Collections.Generic.IEnumerable<string!>! scopes) -> string!
12+
static Microsoft.Extensions.DependencyInjection.FacebookAuthenticationOptionsExtensions.AddFacebook(this Microsoft.AspNetCore.Authentication.AuthenticationBuilder! builder) -> Microsoft.AspNetCore.Authentication.AuthenticationBuilder!
13+
static Microsoft.Extensions.DependencyInjection.FacebookAuthenticationOptionsExtensions.AddFacebook(this Microsoft.AspNetCore.Authentication.AuthenticationBuilder! builder, System.Action<Microsoft.AspNetCore.Authentication.Facebook.FacebookOptions!>! configureOptions) -> Microsoft.AspNetCore.Authentication.AuthenticationBuilder!
14+
static Microsoft.Extensions.DependencyInjection.FacebookAuthenticationOptionsExtensions.AddFacebook(this Microsoft.AspNetCore.Authentication.AuthenticationBuilder! builder, string! authenticationScheme, System.Action<Microsoft.AspNetCore.Authentication.Facebook.FacebookOptions!>! configureOptions) -> Microsoft.AspNetCore.Authentication.AuthenticationBuilder!
15+
static Microsoft.Extensions.DependencyInjection.FacebookAuthenticationOptionsExtensions.AddFacebook(this Microsoft.AspNetCore.Authentication.AuthenticationBuilder! builder, string! authenticationScheme, string! displayName, System.Action<Microsoft.AspNetCore.Authentication.Facebook.FacebookOptions!>! configureOptions) -> Microsoft.AspNetCore.Authentication.AuthenticationBuilder!
16+
static readonly Microsoft.AspNetCore.Authentication.Facebook.FacebookDefaults.AuthorizationEndpoint -> string!
17+
static readonly Microsoft.AspNetCore.Authentication.Facebook.FacebookDefaults.DisplayName -> string!
18+
static readonly Microsoft.AspNetCore.Authentication.Facebook.FacebookDefaults.TokenEndpoint -> string!
19+
static readonly Microsoft.AspNetCore.Authentication.Facebook.FacebookDefaults.UserInformationEndpoint -> string!

src/Security/Authentication/Google/src/GoogleChallengeProperties.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,22 @@ public GoogleChallengeProperties()
4343
/// Initializes a new instance of <see cref="GoogleChallengeProperties"/>.
4444
/// </summary>
4545
/// <inheritdoc />
46-
public GoogleChallengeProperties(IDictionary<string, string> items)
46+
public GoogleChallengeProperties(IDictionary<string, string?> items)
4747
: base(items)
4848
{ }
4949

5050
/// <summary>
5151
/// Initializes a new instance of <see cref="GoogleChallengeProperties"/>.
5252
/// </summary>
5353
/// <inheritdoc />
54-
public GoogleChallengeProperties(IDictionary<string, string> items, IDictionary<string, object> parameters)
54+
public GoogleChallengeProperties(IDictionary<string, string?> items, IDictionary<string, object?> parameters)
5555
: base(items, parameters)
5656
{ }
5757

5858
/// <summary>
5959
/// The "access_type" parameter value being used for a challenge request.
6060
/// </summary>
61-
public string AccessType
61+
public string? AccessType
6262
{
6363
get => GetParameter<string>(AccessTypeKey);
6464
set => SetParameter(AccessTypeKey, value);
@@ -67,7 +67,7 @@ public string AccessType
6767
/// <summary>
6868
/// The "approval_prompt" parameter value being used for a challenge request.
6969
/// </summary>
70-
public string ApprovalPrompt
70+
public string? ApprovalPrompt
7171
{
7272
get => GetParameter<string>(ApprovalPromptKey);
7373
set => SetParameter(ApprovalPromptKey, value);
@@ -85,7 +85,7 @@ public bool? IncludeGrantedScopes
8585
/// <summary>
8686
/// The "login_hint" parameter value being used for a challenge request.
8787
/// </summary>
88-
public string LoginHint
88+
public string? LoginHint
8989
{
9090
get => GetParameter<string>(LoginHintKey);
9191
set => SetParameter(LoginHintKey, value);
@@ -94,7 +94,7 @@ public string LoginHint
9494
/// <summary>
9595
/// The "prompt" parameter value being used for a challenge request.
9696
/// </summary>
97-
public string Prompt
97+
public string? Prompt
9898
{
9999
get => GetParameter<string>(PromptParameterKey);
100100
set => SetParameter(PromptParameterKey, value);

src/Security/Authentication/Google/src/GoogleHandler.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
5151
var context = new OAuthCreatingTicketContext(new ClaimsPrincipal(identity), properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);
5252
context.RunClaimActions();
5353
await Events.CreatingTicket(context);
54-
return new AuthenticationTicket(context.Principal, context.Properties, Scheme.Name);
54+
return new AuthenticationTicket(context.Principal!, context.Properties, Scheme.Name);
5555
}
5656
}
5757

@@ -76,18 +76,18 @@ protected override string BuildChallengeUrl(AuthenticationProperties properties,
7676
var state = Options.StateDataFormat.Protect(properties);
7777
queryStrings.Add("state", state);
7878

79-
var authorizationEndpoint = QueryHelpers.AddQueryString(Options.AuthorizationEndpoint, queryStrings);
79+
var authorizationEndpoint = QueryHelpers.AddQueryString(Options.AuthorizationEndpoint, queryStrings!);
8080
return authorizationEndpoint;
8181
}
8282

8383
private static void AddQueryString<T>(
8484
IDictionary<string, string> queryStrings,
8585
AuthenticationProperties properties,
8686
string name,
87-
Func<T, string> formatter,
87+
Func<T, string?> formatter,
8888
T defaultValue)
8989
{
90-
string value = null;
90+
string? value;
9191
var parameterValue = properties.GetParameter<T>(name);
9292
if (parameterValue != null)
9393
{
@@ -111,7 +111,7 @@ private static void AddQueryString(
111111
IDictionary<string, string> queryStrings,
112112
AuthenticationProperties properties,
113113
string name,
114-
string defaultValue = null)
114+
string? defaultValue = null)
115115
=> AddQueryString(queryStrings, properties, name, x => x, defaultValue);
116116
}
117117
}

src/Security/Authentication/Google/src/GoogleOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ public GoogleOptions()
4040
/// Set the value to offline if your application needs to refresh access tokens when the user is not present at the browser.
4141
/// </para>
4242
/// </summary>
43-
public string AccessType { get; set; }
43+
public string? AccessType { get; set; }
4444
}
4545
}

src/Security/Authentication/Google/src/Microsoft.AspNetCore.Authentication.Google.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
66
<GenerateDocumentationFile>true</GenerateDocumentationFile>
77
<PackageTags>aspnetcore;authentication;security</PackageTags>
8+
<Nullable>enable</Nullable>
89
</PropertyGroup>
910

1011
<ItemGroup>

0 commit comments

Comments
 (0)