Skip to content

Commit f161eb3

Browse files
author
Tiago Brenck
committed
Merge branch 'master' into jmprieur/removingUis
# Conflicts: # Microsoft.Identity.Web/AuthorizeForScopesAttribute.cs
2 parents 16141bc + 12d1b6d commit f161eb3

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

Microsoft.Identity.Web/AuthorizeForScopesAttribute.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class AuthorizeForScopesAttribute : ExceptionFilterAttribute
4646
public override void OnException(ExceptionContext context)
4747
{
4848
MsalUiRequiredException msalUiRequiredException = context.Exception as MsalUiRequiredException;
49+
4950
if (msalUiRequiredException == null)
5051
{
5152
msalUiRequiredException = context.Exception?.InnerException as MsalUiRequiredException;
@@ -55,6 +56,9 @@ public override void OnException(ExceptionContext context)
5556
{
5657
if (CanBeSolvedByReSignInOfUser(msalUiRequiredException))
5758
{
59+
// Do not re-use the attribute param Scopes. For more info: https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/issues/273
60+
string[] scopes = null;
61+
5862
// the users cannot provide both scopes and ScopeKeySection at the same time
5963
if (!string.IsNullOrWhiteSpace(ScopeKeySection) && Scopes != null && Scopes.Length > 0)
6064
{
@@ -72,10 +76,13 @@ public override void OnException(ExceptionContext context)
7276
throw new InvalidOperationException($"The {nameof(ScopeKeySection)} is provided but the IConfiguration instance is not present in the services collection");
7377
}
7478

75-
Scopes = new string[] { configuration.GetValue<string>(ScopeKeySection) };
79+
scopes = new string[] { configuration.GetValue<string>(ScopeKeySection) };
7680
}
7781

78-
var properties = BuildAuthenticationPropertiesForIncrementalConsent(Scopes, msalUiRequiredException, context.HttpContext);
82+
else
83+
scopes = Scopes;
84+
85+
var properties = BuildAuthenticationPropertiesForIncrementalConsent(scopes, msalUiRequiredException, context.HttpContext);
7986
context.Result = new ChallengeResult(properties);
8087
}
8188
}
@@ -91,7 +98,7 @@ private bool CanBeSolvedByReSignInOfUser(MsalUiRequiredException ex)
9198
// InMemoryCache, the cache could be empty if the server was restarted. This is why
9299
// the null_user exception is thrown.
93100

94-
return ex.ErrorCode.ContainsAny(new [] { MsalError.UserNullError, MsalError.InvalidGrantError });
101+
return ex.ErrorCode.ContainsAny(new[] { MsalError.UserNullError, MsalError.InvalidGrantError });
95102
}
96103

97104
/// <summary>
@@ -102,16 +109,16 @@ private bool CanBeSolvedByReSignInOfUser(MsalUiRequiredException ex)
102109
/// <param name="context">current http context in the pipeline</param>
103110
/// <returns>AuthenticationProperties</returns>
104111
private AuthenticationProperties BuildAuthenticationPropertiesForIncrementalConsent(
105-
string[] scopes,
106-
MsalUiRequiredException ex,
112+
string[] scopes,
113+
MsalUiRequiredException ex,
107114
HttpContext context)
108115
{
109116
var properties = new AuthenticationProperties();
110117

111118
// Set the scopes, including the scopes that ADAL.NET / MSAL.NET need for the token cache
112119
string[] additionalBuiltInScopes =
113-
{OidcConstants.ScopeOpenId,
114-
OidcConstants.ScopeOfflineAccess,
120+
{OidcConstants.ScopeOpenId,
121+
OidcConstants.ScopeOfflineAccess,
115122
OidcConstants.ScopeProfile};
116123
properties.SetParameter<ICollection<string>>(OpenIdConnectParameterNames.Scope,
117124
scopes.Union(additionalBuiltInScopes).ToList());

Microsoft.Identity.Web/Microsoft.Identity.Web.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@
5656
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.1" />
5757
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="3.1.1" />
5858
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.0.1" />
59-
<PackageReference Include="Microsoft.Identity.Client" Version="4.8.0" />
59+
<PackageReference Include="Microsoft.Identity.Client" Version="4.8.1" />
6060
</ItemGroup>
6161
</Project>

0 commit comments

Comments
 (0)