Skip to content
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 @@ -66,7 +66,7 @@ public IActionResult Challenge(
string claims)
{
string scheme = OpenIdConnectDefaults.AuthenticationScheme;
Dictionary<string, string> properties = new Dictionary<string, string>
Dictionary<string, string?> properties = new Dictionary<string, string?>
{
{ Constants.Scope, scope },
{ Constants.LoginHint, loginHint },
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.Identity.Web/Constants/IDWebErrorMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace Microsoft.Identity.Web
/// </summary>
internal static class IDWebErrorMessage
{
// General
// public const string IDW10000 = "IDW10000:";
// General IDW10000 = "IDW10000:"
public const string HttpContextIsNull = "IDW10000: HttpContext is null. ";

// Configuration IDW10100 = "IDW10100:"
public const string ProvideEitherScopeKeySectionOrScopes = "IDW10101: Either provide the '{0}' or the '{1}' to the 'AuthorizeForScopes'. ";
Expand Down
26 changes: 15 additions & 11 deletions src/Microsoft.Identity.Web/Microsoft.Identity.Web.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 11 additions & 13 deletions src/Microsoft.Identity.Web/MicrosoftIdentityCircuitHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
namespace Microsoft.Identity.Web
{
/// <summary>
/// Extensions for IServiceCollection for startup initialization of web APIs.
/// Extensions for IServerSideBlazorBuilder for startup initialization of web APIs.
/// </summary>
public static class MicrosoftIdentityBlazorServiceCollectionExtensions
{
/// <summary>
/// Add the incremental consent and conditional access handler for blazor
/// Add the incremental consent and conditional access handler for Blazor
/// server side pages.
/// </summary>
/// <param name="builder">Service side blazor builder.</param>
Expand Down Expand Up @@ -55,10 +55,10 @@ public class MicrosoftIdentityConsentAndConditionalAccessHandler
/// <summary>
/// Current user.
/// </summary>
public ClaimsPrincipal User { get; internal set; }
public ClaimsPrincipal User { get; internal set; } = null!;

/// <summary>
/// Base uri to use in forming the redirect.
/// Base URI to use in forming the redirect.
/// </summary>
public string? BaseUri { get; internal set; }

Expand Down Expand Up @@ -88,13 +88,13 @@ public void HandleException(Exception exception)
User);

string redirectUri = NavigationManager.Uri;
List<string> scope = properties.Parameters.ContainsKey(Constants.Scope) ? (List<string>)properties.Parameters[Constants.Scope] : new List<string>();
string loginHint = properties.Parameters.ContainsKey(Constants.LoginHint) ? (string)properties.Parameters[Constants.LoginHint] : string.Empty;
string domainHint = properties.Parameters.ContainsKey(Constants.DomainHint) ? (string)properties.Parameters[Constants.DomainHint] : string.Empty;
string claims = properties.Parameters.ContainsKey(Constants.Claims) ? (string)properties.Parameters[Constants.Claims] : string.Empty;
List<string> scope = properties.Parameters.ContainsKey(Constants.Scope) ? (List<string>)properties.Parameters[Constants.Scope]! : new List<string>();
string loginHint = properties.Parameters.ContainsKey(Constants.LoginHint) ? (string)properties.Parameters[Constants.LoginHint]! : string.Empty;
string domainHint = properties.Parameters.ContainsKey(Constants.DomainHint) ? (string)properties.Parameters[Constants.DomainHint]! : string.Empty;
string claims = properties.Parameters.ContainsKey(Constants.Claims) ? (string)properties.Parameters[Constants.Claims]! : string.Empty;
string url = $"{NavigationManager.BaseUri}{Constants.BlazorChallengeUri}{redirectUri}"
+ $"&{Constants.Scope}={string.Join(" ", scope)}&{Constants.LoginHint}={loginHint}"
+ $"&{Constants.DomainHint}={domainHint}&{Constants.Claims}={claims}";
+ $"&{Constants.Scope}={string.Join(" ", scope!)}&{Constants.LoginHint}={loginHint}"
+ $"&{Constants.DomainHint}={domainHint}&{Constants.Claims}={claims}";

NavigationManager.NavigateTo(url, true);
}
Expand All @@ -104,9 +104,7 @@ public void HandleException(Exception exception)
}
}

#pragma warning disable CS8618 // Non-nullable field is uninitialized. Consider declaring as nullable.
internal NavigationManager NavigationManager { get; set; }
#pragma warning restore CS8618 // Non-nullable field is uninitialized. Consider declaring as nullable.
internal NavigationManager NavigationManager { get; set; } = null!;
}

#pragma warning disable SA1402 // File may only contain a single type
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.Identity.Web/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ public static IServiceCollection AddTokenAcquisition(
if (isTokenAcquisitionSingleton)
{
services.AddSingleton<ITokenAcquisition, TokenAcquisition>();
services.AddSingleton<ITokenAcquisitionInternal>(s => (ITokenAcquisitionInternal)s.GetService<ITokenAcquisition>());
services.AddSingleton<ITokenAcquisitionInternal>(s => (ITokenAcquisitionInternal)s.GetRequiredService<ITokenAcquisition>());
}
else
{
services.AddScoped<ITokenAcquisition, TokenAcquisition>();
services.AddScoped<ITokenAcquisitionInternal>(s => (ITokenAcquisitionInternal)s.GetService<ITokenAcquisition>());
services.AddScoped<ITokenAcquisitionInternal>(s => (ITokenAcquisitionInternal)s.GetRequiredService<ITokenAcquisition>());
}

return services;
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.Identity.Web/TokenAcquisition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal class TokenAcquisition : ITokenAcquisition, ITokenAcquisitionInternal

private IConfidentialClientApplication? _application;
private readonly IHttpContextAccessor _httpContextAccessor;
private HttpContext CurrentHttpContext => _httpContextAccessor.HttpContext;
private HttpContext? CurrentHttpContext => _httpContextAccessor.HttpContext;
private readonly IMsalHttpClientFactory _httpClientFactory;
private readonly ILogger _logger;
private readonly IServiceProvider _serviceProvider;
Expand Down Expand Up @@ -270,9 +270,9 @@ public async Task<string> GetAccessTokenForUserAsync(
// GetAccessTokenForUserAsync is an abstraction that can be called from a web app or a web API
_logger.LogInformation(ex.Message);

// To get a token for a web API on behalf of the user, but not necessarily with the on behalf of OAuth2.0
// flow as this one only applies to web APIs.
JwtSecurityToken? validatedToken = CurrentHttpContext.GetTokenUsedToCallWebAPI();
// to get a token for a Web API on behalf of the user, but not necessarily with the on behalf of OAuth2.0
// flow as this one only applies to Web APIs.
JwtSecurityToken? validatedToken = CurrentHttpContext?.GetTokenUsedToCallWebAPI();

// Case of web APIs: we need to do an on-behalf-of flow
if (validatedToken != null)
Expand Down
Loading