Skip to content

Commit 0579297

Browse files
authored
Annotate WebAssembly.Authentication for nullability (dotnet#43442)
* Annotate WebAssembly.Authentication for nullability * PR feedback * Fix build
1 parent e6a6c87 commit 0579297

28 files changed

+289
-288
lines changed

src/Components/Components/src/NavigationManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ protected virtual void EnsureInitialized()
209209
/// </summary>
210210
/// <param name="relativeUri">The relative URI.</param>
211211
/// <returns>The absolute URI.</returns>
212-
public Uri ToAbsoluteUri(string relativeUri)
212+
public Uri ToAbsoluteUri(string? relativeUri)
213213
{
214214
AssertInitialized();
215215
return new Uri(_baseUri!, relativeUri);

src/Components/Components/src/PublicAPI.Unshipped.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,5 @@ static Microsoft.AspNetCore.Components.EventCallbackFactoryBinderExtensions.Crea
5656
static Microsoft.AspNetCore.Components.EventCallbackFactoryBinderExtensions.CreateBinder<T>(this Microsoft.AspNetCore.Components.EventCallbackFactory! factory, object! receiver, Microsoft.AspNetCore.Components.EventCallback<T> setter, T existingValue, System.Globalization.CultureInfo? culture = null) -> Microsoft.AspNetCore.Components.EventCallback<Microsoft.AspNetCore.Components.ChangeEventArgs!>
5757
virtual Microsoft.AspNetCore.Components.NavigationManager.HandleLocationChangingHandlerException(System.Exception! ex, Microsoft.AspNetCore.Components.Routing.LocationChangingContext! context) -> void
5858
virtual Microsoft.AspNetCore.Components.NavigationManager.SetNavigationLockState(bool value) -> void
59+
*REMOVED*Microsoft.AspNetCore.Components.NavigationManager.ToAbsoluteUri(string! relativeUri) -> System.Uri!
60+
Microsoft.AspNetCore.Components.NavigationManager.ToAbsoluteUri(string? relativeUri) -> System.Uri!

src/Components/WebAssembly/WebAssembly.Authentication/src/Microsoft.AspNetCore.Components.WebAssembly.Authentication.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
<IsShippingPackage>true</IsShippingPackage>
99
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1010
<IsTrimmable>true</IsTrimmable>
11-
<Nullable>disable</Nullable>
1211
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1312
</PropertyGroup>
1413

src/Components/WebAssembly/WebAssembly.Authentication/src/Models/AccessToken.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class AccessToken
1111
/// <summary>
1212
/// Gets or sets the list of granted scopes for the token.
1313
/// </summary>
14-
public IReadOnlyList<string> GrantedScopes { get; set; }
14+
public IReadOnlyList<string> GrantedScopes { get; set; } = default!;
1515

1616
/// <summary>
1717
/// Gets the expiration time of the token.
@@ -21,5 +21,5 @@ public class AccessToken
2121
/// <summary>
2222
/// Gets the serialized representation of the token.
2323
/// </summary>
24-
public string Value { get; set; }
24+
public string Value { get; set; } = default!;
2525
}

src/Components/WebAssembly/WebAssembly.Authentication/src/Models/InteractiveRequestOptions.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ public sealed class InteractiveRequestOptions
2727
/// <summary>
2828
/// Gets the scopes this request must use in the operation.
2929
/// </summary>
30-
public IEnumerable<string> Scopes { get; init; }
30+
public IEnumerable<string> Scopes { get; init; } = Array.Empty<string>();
3131

32-
private Dictionary<string, object> AdditionalRequestParameters { get; set; }
32+
private Dictionary<string, object>? AdditionalRequestParameters { get; set; }
3333

3434
/// <summary>
3535
/// Tries to add an additional parameter to pass in to the underlying provider.
@@ -43,7 +43,7 @@ public sealed class InteractiveRequestOptions
4343
{
4444
ArgumentNullException.ThrowIfNull(name, nameof(name));
4545
AdditionalRequestParameters ??= new();
46-
return AdditionalRequestParameters.TryAdd(name, value);
46+
return AdditionalRequestParameters.TryAdd(name, value!);
4747
}
4848

4949
/// <summary>
@@ -58,7 +58,7 @@ public bool TryRemoveAdditionalParameter(string name)
5858
/// <summary>
5959
/// Tries to retrieve an existing additional parameter.
6060
/// </summary>
61-
public bool TryGetAdditionalParameter<[DynamicallyAccessedMembers(JsonSerialized)] TValue>(string name, out TValue value)
61+
public bool TryGetAdditionalParameter<[DynamicallyAccessedMembers(JsonSerialized)] TValue>(string name, [NotNullWhen(true)] out TValue? value)
6262
{
6363
ArgumentNullException.ThrowIfNull(name);
6464

@@ -69,7 +69,7 @@ public bool TryRemoveAdditionalParameter(string name)
6969
}
7070
if (rawValue is JsonElement json)
7171
{
72-
value = Deserialize(json);
72+
value = Deserialize(json)!;
7373
AdditionalRequestParameters[name] = value;
7474
return true;
7575
}
@@ -83,14 +83,14 @@ public bool TryRemoveAdditionalParameter(string name)
8383
"Trimming",
8484
"IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code",
8585
Justification = "The types this method deserializes are anotated with 'DynamicallyAccessedMembers' to prevent them from being linked out as part of 'TryAddAdditionalParameter'.")]
86-
static TValue Deserialize(JsonElement element) => element.Deserialize<TValue>();
86+
static TValue Deserialize(JsonElement element) => element.Deserialize<TValue>()!;
8787
}
8888

8989
internal string ToState() => JsonSerializer.Serialize(this, InteractiveRequestOptionsSerializerContext.Default.InteractiveRequestOptions);
9090

9191
internal static InteractiveRequestOptions FromState(string state) => JsonSerializer.Deserialize(
9292
state,
93-
InteractiveRequestOptionsSerializerContext.Default.InteractiveRequestOptions);
93+
InteractiveRequestOptionsSerializerContext.Default.InteractiveRequestOptions)!;
9494

9595
internal class Converter : JsonConverter<InteractiveRequestOptions>
9696
{
@@ -119,7 +119,7 @@ internal record struct OptionsRecord(
119119
[property: JsonInclude] string ReturnUrl,
120120
[property: JsonInclude] IEnumerable<string> Scopes,
121121
[property: JsonInclude] InteractionType Interaction,
122-
[property: JsonInclude] Dictionary<string, object> AdditionalRequestParameters);
122+
[property: JsonInclude] Dictionary<string, object>? AdditionalRequestParameters);
123123
}
124124
}
125125

src/Components/WebAssembly/WebAssembly.Authentication/src/Models/RemoteAuthenticationContext.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ public class RemoteAuthenticationContext<[DynamicallyAccessedMembers(JsonSeriali
1515
/// <summary>
1616
/// Gets or sets the url for the current authentication operation.
1717
/// </summary>
18-
public string Url { get; set; }
18+
public string? Url { get; set; }
1919

2020
/// <summary>
2121
/// Gets or sets the state instance for the current authentication operation.
2222
/// </summary>
23-
public TRemoteAuthenticationState State { get; set; }
23+
public TRemoteAuthenticationState? State { get; set; }
2424

2525
/// <summary>
2626
/// Gets or sets the interaction request for the current authentication operation.
2727
/// </summary>
28-
public InteractiveRequestOptions InteractiveRequest { get; set; }
28+
public InteractiveRequestOptions? InteractiveRequest { get; set; }
2929
}

src/Components/WebAssembly/WebAssembly.Authentication/src/Models/RemoteAuthenticationResult.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ public class RemoteAuthenticationResult<TRemoteAuthenticationState> where TRemot
1717
/// <summary>
1818
/// Gets or sets the error message of a failed authentication operation.
1919
/// </summary>
20-
public string ErrorMessage { get; set; }
20+
public string? ErrorMessage { get; set; }
2121

2222
/// <summary>
2323
/// Gets or sets the preserved state of a successful authentication operation.
2424
/// </summary>
25-
public TRemoteAuthenticationState State { get; set; }
25+
public TRemoteAuthenticationState? State { get; set; }
2626
}

src/Components/WebAssembly/WebAssembly.Authentication/src/Models/RemoteAuthenticationState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ public class RemoteAuthenticationState
1212
/// Gets or sets the URL to which the application should redirect after a successful authentication operation.
1313
/// It must be a url within the page.
1414
/// </summary>
15-
public string ReturnUrl { get; set; }
15+
public string? ReturnUrl { get; set; }
1616
}

src/Components/WebAssembly/WebAssembly.Authentication/src/Models/RemoteUserAccount.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ public class RemoteUserAccount
1717
/// Gets or sets properties not explicitly mapped about the user.
1818
/// </summary>
1919
[JsonExtensionData]
20-
public IDictionary<string, object> AdditionalProperties { get; set; }
20+
public IDictionary<string, object> AdditionalProperties { get; set; } = default!;
2121
}

src/Components/WebAssembly/WebAssembly.Authentication/src/NavigationManagerExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ public static void NavigateToLogout(this NavigationManager manager, [StringSynta
3232
/// <param name="manager">The <see cref="NavigationManager"/>.</param>
3333
/// <param name="logoutPath">The path to navigate too.</param>
3434
/// <param name="returnUrl">The url to redirect the user to after logging out.</param>
35-
public static void NavigateToLogout(this NavigationManager manager, [StringSyntax(StringSyntaxAttribute.Uri, UriKind.Relative)] string logoutPath, [StringSyntax(StringSyntaxAttribute.Uri)] string returnUrl)
35+
public static void NavigateToLogout(this NavigationManager manager, [StringSyntax(StringSyntaxAttribute.Uri, UriKind.Relative)] string logoutPath, [StringSyntax(StringSyntaxAttribute.Uri)] string? returnUrl)
3636
{
3737
manager.NavigateTo(logoutPath, new NavigationOptions
3838
{
3939
HistoryEntryState = new InteractiveRequestOptions
4040
{
4141
Interaction = InteractionType.SignOut,
42-
ReturnUrl = returnUrl
42+
ReturnUrl = returnUrl!
4343
}.ToState()
4444
});
4545
}

0 commit comments

Comments
 (0)