Skip to content

Commit 31b82d5

Browse files
Fix nullable errors
Fix compiler errors caused by new nullable annotations.
1 parent 1781067 commit 31b82d5

File tree

19 files changed

+36
-35
lines changed

19 files changed

+36
-35
lines changed

src/AspNet.Security.OAuth.Apple/AppleAuthenticationHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ protected virtual IEnumerable<Claim> ExtractClaimsFromUser([NotNull] JsonElement
176176

177177
if (user.TryGetProperty("email", out var email))
178178
{
179-
claims.Add(new Claim(ClaimTypes.Email, email.GetString(), ClaimValueTypes.String, ClaimsIssuer));
179+
claims.Add(new Claim(ClaimTypes.Email, email.GetString() ?? string.Empty, ClaimValueTypes.String, ClaimsIssuer));
180180
}
181181

182182
return claims;

src/AspNet.Security.OAuth.Bitbucket/BitbucketAuthenticationHandler.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,19 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
6363
!identity.HasClaim(claim => claim.Type == ClaimTypes.Email) &&
6464
Options.Scope.Contains("email"))
6565
{
66-
string address = await GetEmailAsync(tokens);
66+
string? address = await GetEmailAsync(tokens);
6767

6868
if (!string.IsNullOrEmpty(address))
6969
{
70-
identity.AddClaim(new Claim(ClaimTypes.Email, address, ClaimValueTypes.String, Options.ClaimsIssuer));
70+
identity.AddClaim(new Claim(ClaimTypes.Email, address!, ClaimValueTypes.String, Options.ClaimsIssuer));
7171
}
7272
}
7373

7474
await Options.Events.CreatingTicket(context);
7575
return new AuthenticationTicket(context.Principal, context.Properties, Scheme.Name);
7676
}
7777

78-
protected virtual async Task<string> GetEmailAsync([NotNull] OAuthTokenResponse tokens)
78+
protected virtual async Task<string?> GetEmailAsync([NotNull] OAuthTokenResponse tokens)
7979
{
8080
using var request = new HttpRequestMessage(HttpMethod.Get, Options.UserEmailsEndpoint);
8181
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

src/AspNet.Security.OAuth.Deezer/DeezerAuthenticationHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ protected override string BuildChallengeUrl([NotNull] AuthenticationProperties p
129129
properties.Items.Add(OAuthConstants.CodeVerifierKey, codeVerifier);
130130

131131
using var sha256 = HashAlgorithm.Create("SHA256");
132-
byte[] challengeBytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(codeVerifier));
132+
byte[] challengeBytes = sha256!.ComputeHash(Encoding.UTF8.GetBytes(codeVerifier));
133133
parameters[OAuthConstants.CodeChallengeKey] = WebEncoders.Base64UrlEncode(challengeBytes);
134134
parameters[OAuthConstants.CodeChallengeMethodKey] = OAuthConstants.CodeChallengeMethodS256;
135135
}

src/AspNet.Security.OAuth.Fitbit/FitbitAuthenticationHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected override async Task<OAuthTokenResponse> ExchangeCodeAsync([NotNull] OA
7676
["code"] = context.Code
7777
};
7878

79-
request.Content = new FormUrlEncodedContent(parameters);
79+
request.Content = new FormUrlEncodedContent(parameters!);
8080

8181
using var response = await Backchannel.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, Context.RequestAborted);
8282
if (!response.IsSuccessStatusCode)

src/AspNet.Security.OAuth.GitHub/GitHubAuthenticationHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
6363
!identity.HasClaim(claim => claim.Type == ClaimTypes.Email) &&
6464
Options.Scope.Contains("user:email"))
6565
{
66-
string address = await GetEmailAsync(tokens);
66+
string? address = await GetEmailAsync(tokens);
6767

6868
if (!string.IsNullOrEmpty(address))
6969
{
@@ -75,7 +75,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
7575
return new AuthenticationTicket(context.Principal, context.Properties, Scheme.Name);
7676
}
7777

78-
protected virtual async Task<string> GetEmailAsync([NotNull] OAuthTokenResponse tokens)
78+
protected virtual async Task<string?> GetEmailAsync([NotNull] OAuthTokenResponse tokens)
7979
{
8080
// See https://developer.github.com/v3/users/emails/ for more information about the /user/emails endpoint.
8181
using var request = new HttpRequestMessage(HttpMethod.Get, Options.UserEmailsEndpoint);

src/AspNet.Security.OAuth.Gitee/GiteeAuthenticationHandler.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ public GiteeAuthenticationHandler(
2727
[NotNull] UrlEncoder encoder,
2828
[NotNull] ISystemClock clock)
2929
: base(options, logger, encoder, clock)
30-
{
31-
}
30+
{
31+
}
3232

3333
protected override async Task<AuthenticationTicket> CreateTicketAsync(
3434
[NotNull] ClaimsIdentity identity,
@@ -63,7 +63,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
6363
!identity.HasClaim(claim => claim.Type == ClaimTypes.Email) &&
6464
Options.Scope.Contains("emails"))
6565
{
66-
string address = await GetEmailAsync(tokens);
66+
string? address = await GetEmailAsync(tokens);
6767

6868
if (!string.IsNullOrEmpty(address))
6969
{
@@ -75,7 +75,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
7575
return new AuthenticationTicket(context.Principal, context.Properties, Scheme.Name);
7676
}
7777

78-
protected async Task<string> GetEmailAsync([NotNull] OAuthTokenResponse tokens)
78+
protected async Task<string?> GetEmailAsync([NotNull] OAuthTokenResponse tokens)
7979
{
8080
using var request = new HttpRequestMessage(HttpMethod.Get, Options.UserEmailsEndpoint);
8181
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

src/AspNet.Security.OAuth.LinkedIn/LinkedInAuthenticationOptions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public LinkedInAuthenticationOptions()
7272
/// 3. Returns the first value.
7373
/// </summary>
7474
/// <see cref="DefaultMultiLocaleStringResolver(IReadOnlyDictionary{string, string}, string?)"/>
75-
public Func<IReadOnlyDictionary<string, string>, string?, string> MultiLocaleStringResolver { get; set; } = DefaultMultiLocaleStringResolver;
75+
public Func<IReadOnlyDictionary<string, string?>, string?, string?> MultiLocaleStringResolver { get; set; } = DefaultMultiLocaleStringResolver;
7676

7777
/// <summary>
7878
/// Gets the <c>MultiLocaleString</c> value using the configured resolver.
@@ -100,7 +100,7 @@ public LinkedInAuthenticationOptions()
100100
preferredLocaleKey = $"{preferredLocale.GetString("language")}_{preferredLocale.GetString("country")}";
101101
}
102102

103-
var preferredLocales = new Dictionary<string, string>();
103+
var preferredLocales = new Dictionary<string, string?>();
104104

105105
foreach (var element in propertyLocalized.EnumerateObject())
106106
{
@@ -164,7 +164,7 @@ private static IEnumerable<string> GetPictureUrls(JsonElement user)
164164
/// <param name="localizedValues">The localized values with culture keys.</param>
165165
/// <param name="preferredLocale">The preferred locale, if provided by LinkedIn.</param>
166166
/// <returns>The localized value.</returns>
167-
private static string DefaultMultiLocaleStringResolver(IReadOnlyDictionary<string, string> localizedValues, string? preferredLocale)
167+
private static string? DefaultMultiLocaleStringResolver(IReadOnlyDictionary<string, string?> localizedValues, string? preferredLocale)
168168
{
169169
if (!string.IsNullOrEmpty(preferredLocale) &&
170170
localizedValues.TryGetValue(preferredLocale, out string? preferredLocaleValue))

src/AspNet.Security.OAuth.Odnoklassniki/OdnoklassnikiAuthenticationHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
4040
[NotNull] OAuthTokenResponse tokens)
4141
{
4242
using var algorithm = HashAlgorithm.Create("MD5");
43-
string accessSecret = GetHash(algorithm, tokens.AccessToken + Options.ClientSecret);
44-
string sign = GetHash(algorithm, $"application_key={Options.PublicSecret}format=jsonmethod=users.getCurrentUser{accessSecret}");
43+
string accessSecret = GetHash(algorithm!, tokens.AccessToken + Options.ClientSecret);
44+
string sign = GetHash(algorithm!, $"application_key={Options.PublicSecret}format=jsonmethod=users.getCurrentUser{accessSecret}");
4545

4646
string address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, new Dictionary<string, string>
4747
{

src/AspNet.Security.OAuth.Reddit/RedditAuthenticationHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ protected override async Task<OAuthTokenResponse> ExchangeCodeAsync([NotNull] OA
108108
["code"] = context.Code
109109
};
110110

111-
request.Content = new FormUrlEncodedContent(parameters);
111+
request.Content = new FormUrlEncodedContent(parameters!);
112112

113113
using var response = await Backchannel.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, Context.RequestAborted);
114114
if (!response.IsSuccessStatusCode)

src/AspNet.Security.OAuth.Shopify/ShopifyAuthenticationHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ protected override async Task<OAuthTokenResponse> ExchangeCodeAsync([NotNull] OA
186186
["code"] = context.Code
187187
};
188188

189-
request.Content = new FormUrlEncodedContent(parameters);
189+
request.Content = new FormUrlEncodedContent(parameters!);
190190

191191
using var response = await Backchannel.SendAsync(request, Context.RequestAborted);
192192

0 commit comments

Comments
 (0)