Skip to content
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

[Bug] Object Null Reference in GetAuthenticationResultForAppAsync - background task #1656

Closed
2 of 8 tasks
xubinzheng opened this issue Mar 11, 2022 · 2 comments
Closed
2 of 8 tasks
Assignees
Labels
Milestone

Comments

@xubinzheng
Copy link

xubinzheng commented Mar 11, 2022

Which version of Microsoft Identity Web are you using?
Note that to get help, you need to run the latest version.
Microsoft Identity Web 1.23.0

Where is the issue?

  • Web app
    • Sign-in users
    • Sign-in users and call web APIs
  • Web API
    • Protected web APIs (validating tokens)
    • Protected web APIs (validating scopes)
    • Protected web APIs call downstream web APIs
  • Token cache serialization
    • In-memory caches
    • Session caches
    • Distributed caches
  • Other (please describe)

Is this a new or an existing app?
c. This is a new app or an experiment.

Repro
We are trying to get an App-only token for MSGraph in C# background task by uisng services.AddHostedService<>();
The code we use to get token:
await _tokenAcquisition.GetAuthenticationResultForAppAsync($"{ResourceId}/.default", tenant: tenantId, null);
Then we received a null Ref error from IdWeb library

Expected behavior
The background task should be able to get an app-only token

Actual behavior
An exception was thrown by IdWeb.

Possible solution

Additional context / logs / screenshots / link to code

Exception details:
at Microsoft.Identity.Web.MergedOptions.PrepareAuthorityInstanceForMsal()
at Microsoft.Identity.Web.TokenAcquisition.BuildConfidentialClientApplication(MergedOptions mergedOptions)
at Microsoft.Identity.Web.TokenAcquisition.GetOrBuildConfidentialClientApplication(MergedOptions mergedOptions)
at Microsoft.Identity.Web.TokenAcquisition.GetAuthenticationResultForAppAsync(String scope, String authenticationScheme, String tenant, TokenAcquisitionOptions tokenAcquisitionOptions)
at Microsoft.Identity.Web.TokenAcquisition.d__19.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Clients.BaseAuthenticationHandler.d__16.MoveNext() in D:\Code\AD-IAM-Services-MyApps\src\Clients\BaseAuthenticationHandler.cs:line 167

@xubinzheng xubinzheng changed the title [Bug] [Bug] Object Null Reference in GetAuthenticationResultForAppAsync - background task Mar 11, 2022
@xubinzheng
Copy link
Author

Looks like this issue has been fixed in IdWeb 1.23.1 with this PR: #1648

@jmprieur jmprieur added this to the 1.23.1 milestone Mar 11, 2022
@jmprieur jmprieur added bug Something isn't working P1 labels Mar 11, 2022
@jmprieur jmprieur added the fixed label Mar 11, 2022
@jennyf19
Copy link
Collaborator

released in 1.23.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants