-
Notifications
You must be signed in to change notification settings - Fork 217
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
NullReferenceException is thrown when using DefaultTokenAcquisitionHost and trying to acquire a token #2394
Comments
@MZOLN Do you have everything in the appsettings.json? Is the authority, instance, etc... all present? |
Those are the settings:
Is anything missing? |
I encounter the same issue with 2.13.3. Short Stack Trace: |
@Jan1503 : Marcin's error was with is code (he forgot to configure the MicrosoftIdentityApplicationOptions) Do you use AddMicrosoftWebApp or AddMicrosoftWebApi? |
@jmprieur : Here's my auth-config: public static IServiceCollection AddDefaultAuthentication(this IServiceCollection services,
IConfigurationSection azureAdConfigurationSection)
{
ArgumentNullException.ThrowIfNull(azureAdConfigurationSection);
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApi(jwt =>
{
IdentityModelEventSource.ShowPII = true;
var opt = new MicrosoftIdentityOptions();
azureAdConfigurationSection.Bind(opt);
jwt.Authority = $"https://sts.windows.net/{opt.TenantId}/v2.0";
jwt.TokenValidationParameters = new TokenValidationParameters
{
ValidIssuer = $"https://sts.windows.net/{opt.TenantId}",
ValidAudiences = new List<string>
{
opt.ClientId!,
$"api://{opt.ClientId}"
}
};
jwt.Events = new JwtBearerEvents
{
OnAuthenticationFailed = ctx => Task.CompletedTask
};
}, azureAdConfigurationSection.Bind)
.EnableTokenAcquisitionToCallDownstreamApi(options => { })
.AddInMemoryTokenCaches();
return services;
} |
@Jan1503 this should be fixed in 2.15.0 that is going to release tomorrow |
Still not fixed apparently. I'm having this issue with the daemon_console sample from https://github.com/Azure-Samples/active-directory-dotnetcore-daemon-v2/tree/master/1-Call-MSGraph I was following this Quickstart guide: |
Microsoft.Identity.Web Library
Microsoft.Identity.Web
Microsoft.Identity.Web version
2.13.3
Web app
Sign-in users
Web API
Protected web APIs (validating tokens)
Token cache serialization
In-memory caches
Description
NRE thrown in the pasted stack.
The issue is that the defaultokenacquisitionhost returns a null redirecturi but msal assumes that it`s not null
Reproduction steps
Create console app
Call downstream api
Error message
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Microsoft.Identity.Web.TokenAcquisition
StackTrace:
at Microsoft.Identity.Web.MergedOptions.PrepareAuthorityInstanceForMsal() in /_/src/Microsoft.Identity.Web.TokenAcquisition/MergedOptions.cs:line 452
at Microsoft.Identity.Web.TokenAcquisition.BuildConfidentialClientApplication(MergedOptions mergedOptions) in /_/src/Microsoft.Identity.Web.TokenAcquisition/TokenAcquisition.cs:line 580
at Microsoft.Identity.Web.TokenAcquisition.GetOrBuildConfidentialClientApplication(MergedOptions mergedOptions) in /_/src/Microsoft.Identity.Web.TokenAcquisition/TokenAcquisition.cs:line 566
at Microsoft.Identity.Web.TokenAcquisition.d__14.MoveNext() in /_/src/Microsoft.Identity.Web.TokenAcquisition/TokenAcquisition.cs:line 235
This exception was originally thrown at this call stack:
Id Web logs
No response
Relevant code snippets
Regression
Id Web 2.13.3
Expected behavior
Token is acquired.
The text was updated successfully, but these errors were encountered: