Skip to content
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

Enable nullable on more authentication projects #31230

Merged
merged 3 commits into from
Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected RemoteAuthenticationContext(
/// <summary>
/// Gets or sets the <see cref="AuthenticationProperties"/>.
/// </summary>
public virtual AuthenticationProperties Properties { get; set; }
public virtual AuthenticationProperties? Properties { get; set; }

/// <summary>
/// Calls success creating a ticket with the <see cref="Principal"/> and <see cref="Properties"/>.
Expand Down
4 changes: 2 additions & 2 deletions src/Security/Authentication/Core/src/HandleRequestResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class HandleRequestResult : AuthenticateResult
/// <param name="failure">The failure exception.</param>
/// <param name="properties">Additional state values for the authentication session.</param>
/// <returns>The result.</returns>
public static new HandleRequestResult Fail(Exception failure, AuthenticationProperties properties)
public static new HandleRequestResult Fail(Exception failure, AuthenticationProperties? properties)
{
return new HandleRequestResult() { Failure = failure, Properties = properties };
}
Expand All @@ -71,7 +71,7 @@ public class HandleRequestResult : AuthenticateResult
/// <param name="failureMessage">The failure message.</param>
/// <param name="properties">Additional state values for the authentication session.</param>
/// <returns>The result.</returns>
public static new HandleRequestResult Fail(string failureMessage, AuthenticationProperties properties)
public static new HandleRequestResult Fail(string failureMessage, AuthenticationProperties? properties)
=> Fail(new Exception(failureMessage), properties);

/// <summary>
Expand Down
3 changes: 1 addition & 2 deletions src/Security/Authentication/Core/src/IDataSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public interface IDataSerializer<TModel>
/// </summary>
/// <param name="data">The bytes being deserialized.</param>
/// <returns>The model.</returns>
[return: MaybeNull]
TModel Deserialize(byte[] data);
TModel? Deserialize(byte[] data);
}
}
6 changes: 2 additions & 4 deletions src/Security/Authentication/Core/src/ISecureDataFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,14 @@ public interface ISecureDataFormat<TData>
/// </summary>
/// <param name="protectedText">The data protected value.</param>
/// <returns>An instance of <typeparamref name="TData"/>.</returns>
[return: MaybeNull]
TData Unprotect(string protectedText);
TData? Unprotect(string? protectedText);

/// <summary>
/// Unprotects the specified <paramref name="protectedText"/> using the specified <paramref name="purpose"/>.
/// </summary>
/// <param name="protectedText">The data protected value.</param>
/// <param name="purpose">The purpose.</param>
/// <returns>An instance of <typeparamref name="TData"/>.</returns>
[return: MaybeNull]
TData Unprotect(string protectedText, string? purpose);
TData? Unprotect(string? protectedText, string? purpose);
}
}
16 changes: 16 additions & 0 deletions src/Security/Authentication/Core/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
#nullable enable
*REMOVED*Microsoft.AspNetCore.Authentication.AuthenticationSchemeOptions.ForwardDefaultSelector.get -> System.Func<Microsoft.AspNetCore.Http.HttpContext!, string!>?
Microsoft.AspNetCore.Authentication.AuthenticationSchemeOptions.ForwardDefaultSelector.get -> System.Func<Microsoft.AspNetCore.Http.HttpContext!, string?>?
Microsoft.AspNetCore.Authentication.IDataSerializer<TModel>.Deserialize(byte[]! data) -> TModel?
Microsoft.AspNetCore.Authentication.ISecureDataFormat<TData>.Unprotect(string? protectedText) -> TData?
Microsoft.AspNetCore.Authentication.ISecureDataFormat<TData>.Unprotect(string? protectedText, string? purpose) -> TData?
Microsoft.AspNetCore.Authentication.SecureDataFormat<TData>.Unprotect(string? protectedText) -> TData?
Microsoft.AspNetCore.Authentication.SecureDataFormat<TData>.Unprotect(string? protectedText, string? purpose) -> TData?
static Microsoft.AspNetCore.Authentication.HandleRequestResult.Fail(System.Exception! failure, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) -> Microsoft.AspNetCore.Authentication.HandleRequestResult!
static Microsoft.AspNetCore.Authentication.HandleRequestResult.Fail(string! failureMessage, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) -> Microsoft.AspNetCore.Authentication.HandleRequestResult!
virtual Microsoft.AspNetCore.Authentication.RemoteAuthenticationContext<TOptions>.Properties.get -> Microsoft.AspNetCore.Authentication.AuthenticationProperties?
*REMOVED*Microsoft.AspNetCore.Authentication.IDataSerializer<TModel>.Deserialize(byte[]! data) -> TModel
*REMOVED*Microsoft.AspNetCore.Authentication.ISecureDataFormat<TData>.Unprotect(string! protectedText) -> TData
*REMOVED*Microsoft.AspNetCore.Authentication.ISecureDataFormat<TData>.Unprotect(string! protectedText, string? purpose) -> TData
*REMOVED*Microsoft.AspNetCore.Authentication.SecureDataFormat<TData>.Unprotect(string! protectedText) -> TData
*REMOVED*Microsoft.AspNetCore.Authentication.SecureDataFormat<TData>.Unprotect(string! protectedText, string? purpose) -> TData
*REMOVED*static Microsoft.AspNetCore.Authentication.HandleRequestResult.Fail(System.Exception! failure, Microsoft.AspNetCore.Authentication.AuthenticationProperties! properties) -> Microsoft.AspNetCore.Authentication.HandleRequestResult!
*REMOVED*static Microsoft.AspNetCore.Authentication.HandleRequestResult.Fail(string! failureMessage, Microsoft.AspNetCore.Authentication.AuthenticationProperties! properties) -> Microsoft.AspNetCore.Authentication.HandleRequestResult!
*REMOVED*virtual Microsoft.AspNetCore.Authentication.RemoteAuthenticationContext<TOptions>.Properties.get -> Microsoft.AspNetCore.Authentication.AuthenticationProperties!
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public virtual async Task<bool> HandleRequestAsync()
ticket.Properties.RedirectUri = null;

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

await Events.TicketReceived(ticketContext);

Expand Down
6 changes: 2 additions & 4 deletions src/Security/Authentication/Core/src/SecureDataFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,13 @@ public string Protect(TData data, string? purpose)
}

/// <inheritdoc />
[return: MaybeNull]
public TData Unprotect(string protectedText)
public TData? Unprotect(string? protectedText)
{
return Unprotect(protectedText, purpose: null);
}

/// <inheritdoc />
[return: MaybeNull]
public TData Unprotect(string protectedText, string? purpose)
public TData? Unprotect(string? protectedText, string? purpose)
{
try
{
Expand Down
6 changes: 3 additions & 3 deletions src/Security/Authentication/Facebook/src/FacebookHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public FacebookHandler(IOptionsMonitor<FacebookOptions> options, ILoggerFactory
/// <inheritdoc />
protected override async Task<AuthenticationTicket> CreateTicketAsync(ClaimsIdentity identity, AuthenticationProperties properties, OAuthTokenResponse tokens)
{
var endpoint = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "access_token", tokens.AccessToken);
var endpoint = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "access_token", tokens.AccessToken!);
if (Options.SendAppSecretProof)
{
endpoint = QueryHelpers.AddQueryString(endpoint, "appsecret_proof", GenerateAppSecretProof(tokens.AccessToken));
endpoint = QueryHelpers.AddQueryString(endpoint, "appsecret_proof", GenerateAppSecretProof(tokens.AccessToken!));
}
if (Options.Fields.Count > 0)
{
Expand All @@ -54,7 +54,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(ClaimsIden
var context = new OAuthCreatingTicketContext(new ClaimsPrincipal(identity), properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);
context.RunClaimActions();
await Events.CreatingTicket(context);
return new AuthenticationTicket(context.Principal, context.Properties, Scheme.Name);
return new AuthenticationTicket(context.Principal!, context.Properties, Scheme.Name);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageTags>aspnetcore;authentication;security</PackageTags>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
18 changes: 18 additions & 0 deletions src/Security/Authentication/Facebook/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
#nullable enable
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
Microsoft.AspNetCore.Authentication.Facebook.FacebookOptions.AppId.get -> string!
Microsoft.AspNetCore.Authentication.Facebook.FacebookOptions.AppId.set -> void
Microsoft.AspNetCore.Authentication.Facebook.FacebookOptions.AppSecret.get -> string!
Microsoft.AspNetCore.Authentication.Facebook.FacebookOptions.AppSecret.set -> void
Microsoft.AspNetCore.Authentication.Facebook.FacebookOptions.Fields.get -> System.Collections.Generic.ICollection<string!>!
const Microsoft.AspNetCore.Authentication.Facebook.FacebookDefaults.AuthenticationScheme = "Facebook" -> string!
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!>!
override Microsoft.AspNetCore.Authentication.Facebook.FacebookHandler.FormatScope() -> string!
override Microsoft.AspNetCore.Authentication.Facebook.FacebookHandler.FormatScope(System.Collections.Generic.IEnumerable<string!>! scopes) -> string!
static Microsoft.Extensions.DependencyInjection.FacebookAuthenticationOptionsExtensions.AddFacebook(this Microsoft.AspNetCore.Authentication.AuthenticationBuilder! builder) -> Microsoft.AspNetCore.Authentication.AuthenticationBuilder!
static Microsoft.Extensions.DependencyInjection.FacebookAuthenticationOptionsExtensions.AddFacebook(this Microsoft.AspNetCore.Authentication.AuthenticationBuilder! builder, System.Action<Microsoft.AspNetCore.Authentication.Facebook.FacebookOptions!>! configureOptions) -> Microsoft.AspNetCore.Authentication.AuthenticationBuilder!
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!
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!
static readonly Microsoft.AspNetCore.Authentication.Facebook.FacebookDefaults.AuthorizationEndpoint -> string!
static readonly Microsoft.AspNetCore.Authentication.Facebook.FacebookDefaults.DisplayName -> string!
static readonly Microsoft.AspNetCore.Authentication.Facebook.FacebookDefaults.TokenEndpoint -> string!
static readonly Microsoft.AspNetCore.Authentication.Facebook.FacebookDefaults.UserInformationEndpoint -> string!
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,22 @@ public GoogleChallengeProperties()
/// Initializes a new instance of <see cref="GoogleChallengeProperties"/>.
/// </summary>
/// <inheritdoc />
public GoogleChallengeProperties(IDictionary<string, string> items)
public GoogleChallengeProperties(IDictionary<string, string?> items)
: base(items)
{ }

/// <summary>
/// Initializes a new instance of <see cref="GoogleChallengeProperties"/>.
/// </summary>
/// <inheritdoc />
public GoogleChallengeProperties(IDictionary<string, string> items, IDictionary<string, object> parameters)
public GoogleChallengeProperties(IDictionary<string, string?> items, IDictionary<string, object?> parameters)
: base(items, parameters)
{ }

/// <summary>
/// The "access_type" parameter value being used for a challenge request.
/// </summary>
public string AccessType
public string? AccessType
{
get => GetParameter<string>(AccessTypeKey);
set => SetParameter(AccessTypeKey, value);
Expand All @@ -67,7 +67,7 @@ public string AccessType
/// <summary>
/// The "approval_prompt" parameter value being used for a challenge request.
/// </summary>
public string ApprovalPrompt
public string? ApprovalPrompt
{
get => GetParameter<string>(ApprovalPromptKey);
set => SetParameter(ApprovalPromptKey, value);
Expand All @@ -85,7 +85,7 @@ public bool? IncludeGrantedScopes
/// <summary>
/// The "login_hint" parameter value being used for a challenge request.
/// </summary>
public string LoginHint
public string? LoginHint
{
get => GetParameter<string>(LoginHintKey);
set => SetParameter(LoginHintKey, value);
Expand All @@ -94,7 +94,7 @@ public string LoginHint
/// <summary>
/// The "prompt" parameter value being used for a challenge request.
/// </summary>
public string Prompt
public string? Prompt
{
get => GetParameter<string>(PromptParameterKey);
set => SetParameter(PromptParameterKey, value);
Expand Down
10 changes: 5 additions & 5 deletions src/Security/Authentication/Google/src/GoogleHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
var context = new OAuthCreatingTicketContext(new ClaimsPrincipal(identity), properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);
context.RunClaimActions();
await Events.CreatingTicket(context);
return new AuthenticationTicket(context.Principal, context.Properties, Scheme.Name);
return new AuthenticationTicket(context.Principal!, context.Properties, Scheme.Name);
}
}

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

var authorizationEndpoint = QueryHelpers.AddQueryString(Options.AuthorizationEndpoint, queryStrings);
var authorizationEndpoint = QueryHelpers.AddQueryString(Options.AuthorizationEndpoint, queryStrings!);
return authorizationEndpoint;
}

private static void AddQueryString<T>(
IDictionary<string, string> queryStrings,
AuthenticationProperties properties,
string name,
Func<T, string> formatter,
Func<T, string?> formatter,
T defaultValue)
{
string value = null;
string? value;
var parameterValue = properties.GetParameter<T>(name);
if (parameterValue != null)
{
Expand All @@ -111,7 +111,7 @@ private static void AddQueryString(
IDictionary<string, string> queryStrings,
AuthenticationProperties properties,
string name,
string defaultValue = null)
string? defaultValue = null)
=> AddQueryString(queryStrings, properties, name, x => x, defaultValue);
}
}
2 changes: 1 addition & 1 deletion src/Security/Authentication/Google/src/GoogleOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ public GoogleOptions()
/// Set the value to offline if your application needs to refresh access tokens when the user is not present at the browser.
/// </para>
/// </summary>
public string AccessType { get; set; }
public string? AccessType { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageTags>aspnetcore;authentication;security</PackageTags>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading