Skip to content

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

Closed

Description

@xubinzheng

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

Activity

  1. changed the title [-][Bug] [/-] [+][Bug] Object Null Reference in GetAuthenticationResultForAppAsync - background task[/+] on Mar 11, 2022
  2. xubinzheng commented on Mar 11, 2022

    @xubinzheng
    Author

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

  3. jennyf19 commented on Mar 15, 2022

    @jennyf19
    Collaborator

    released in 1.23.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions