-
Notifications
You must be signed in to change notification settings - Fork 372
Added better error message for OIDC error #5433
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,15 +87,18 @@ public static MockHttpMessageHandler AddFailureTokenEndpointResponse( | |
this MockHttpManager httpManager, | ||
string error, | ||
string authority = TestConstants.AuthorityCommonTenant, | ||
string correlationId = null) | ||
string correlationId = null, | ||
string AadErrorCode = "AADSTS00000", | ||
string expectedUrl = null) | ||
{ | ||
var handler = new MockHttpMessageHandler() | ||
{ | ||
ExpectedUrl = authority + "oauth2/v2.0/token", | ||
ExpectedUrl = expectedUrl != null? expectedUrl : $"{authority}oauth2/v2.0/token", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: space between "null" and "?" |
||
ExpectedMethod = HttpMethod.Post, | ||
ResponseMessage = MockHelpers.CreateFailureTokenResponseMessage( | ||
error, | ||
correlationId: correlationId) | ||
error, | ||
correlationId: correlationId, | ||
errorCode: AadErrorCode) | ||
}; | ||
httpManager.AddMockHandler(handler); | ||
return handler; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,6 +122,8 @@ public static HashSet<string> s_scope | |
public const string CiamAuthorityMainFormat = "https://tenant.ciamlogin.com/"; | ||
public const string CiamAuthorityWithFriendlyName = "https://tenant.ciamlogin.com/tenant.onmicrosoft.com"; | ||
public const string CiamAuthorityWithGuid = "https://tenant.ciamlogin.com/aaaaaaab-aaaa-aaaa-cccc-aaaaaaaaaaaa"; | ||
public const string CiamCUDAuthority = "https://login.msidlabsciam.com/aaaaaaab-aaaa-aaaa-cccc-aaaaaaaaaaaa/v2.0"; | ||
public const string CiamCUDAuthorityMalformed = "https://login.msidlabsciam.com/aaaaaaab-aaaa-aaaa-cccc-aaaaaaaaaaaa"; | ||
|
||
public const string B2CLoginGlobal = ".b2clogin.com"; | ||
public const string B2CLoginUSGov = ".b2clogin.us"; | ||
|
@@ -229,6 +231,9 @@ public static HashSet<string> s_scope | |
public const string Pop = "PoP"; | ||
public const string FmiNodeClientId = "urn:microsoft:identity:fmi"; | ||
|
||
public const string AadAccountTypeAndResourceIncompatibleErrorCode = "AADSTS500207"; | ||
public const string AadMissingScopeErrorCode = "AADSTS900144"; | ||
|
||
Comment on lines
+234
to
+236
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't you re-use the constants from |
||
public static IDictionary<string, string> ExtraQueryParameters | ||
{ | ||
get | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
using System.Diagnostics; | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
@@ -333,6 +334,60 @@ public async Task BadOidcResponse_ThrowsException_Async(string badOidcResponseTy | |
} | ||
} | ||
|
||
[TestMethod] | ||
public async Task Oidc_Malformed_Failure_Async() | ||
{ | ||
using (var httpManager = new MockHttpManager()) | ||
{ | ||
string authority = TestConstants.CiamCUDAuthorityMalformed; | ||
IConfidentialClientApplication app = ConfidentialClientApplicationBuilder | ||
.Create(TestConstants.ClientId) | ||
.WithHttpManager(httpManager) | ||
.WithOidcAuthority(authority) | ||
.WithClientSecret(TestConstants.ClientSecret) | ||
.Build(); | ||
|
||
httpManager.AddMockHandler( | ||
CreateOidcHttpHandler(authority + "/" + Constants.WellKnownOpenIdConfigurationPath)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I know you said you didn't want to use string interpolation for just one string character, but I think we should try to be consistent. |
||
|
||
httpManager.AddFailureTokenEndpointResponse( | ||
error: "error", | ||
AadErrorCode: TestConstants.AadAccountTypeAndResourceIncompatibleErrorCode, | ||
expectedUrl: $"{TestConstants.CiamCUDAuthorityMalformed}/connect/token"); | ||
|
||
Assert.AreEqual(authority, app.Authority); | ||
var confidentailClientApp = (ConfidentialClientApplication)app; | ||
Assert.AreEqual(AuthorityType.Generic, confidentailClientApp.AuthorityInfo.AuthorityType); | ||
|
||
var ex = await AssertException.TaskThrowsAsync<MsalServiceException>(() => | ||
app.AcquireTokenForClient(new[] { "api" }) | ||
.ExecuteAsync()) | ||
.ConfigureAwait(false); | ||
|
||
Assert.IsTrue(ex.Message.Contains( | ||
string.Format( | ||
CultureInfo.InvariantCulture, | ||
MsalErrorMessage.MalformedOidcAuthorityFormat, | ||
TestConstants.CiamCUDAuthorityMalformed))); | ||
|
||
httpManager.AddFailureTokenEndpointResponse( | ||
error: "error", | ||
AadErrorCode: TestConstants.AadMissingScopeErrorCode, | ||
expectedUrl: $"{TestConstants.CiamCUDAuthorityMalformed}/connect/token"); | ||
|
||
ex = await AssertException.TaskThrowsAsync<MsalServiceException>(() => | ||
app.AcquireTokenForClient(new[] { "api" }) | ||
.ExecuteAsync()) | ||
.ConfigureAwait(false); | ||
|
||
Assert.IsTrue(ex.Message.Contains( | ||
string.Format( | ||
CultureInfo.InvariantCulture, | ||
MsalErrorMessage.MalformedOidcAuthorityFormat, | ||
TestConstants.CiamCUDAuthorityMalformed))); | ||
} | ||
} | ||
|
||
[TestMethod] | ||
public async Task OidcIssuerValidation_ThrowsForNonMatchingIssuer_Async() | ||
{ | ||
|
Uh oh!
There was an error while loading. Please reload this page.