Skip to content

TokenHelper in AppForSharePointWebToolkit fails to validate host URL with port number #1358

@jensotto

Description

@jensotto

Category

  • Question
  • Typo
  • Bug
  • Additional article idea

Expected or Desired Behavior

CreateAppEventClientContext should work when using ACS and nonstandard port for provider hosted add-in (like when using Visual Studio Development Server).

Observed Behavior

If using non default port for provider hosted add-in (for example VS Development Server), you will get
an AudienceUriValidationFailedException with the message: "localhost" is not the intended audience "b99d1203-1862-4c3a-9947-45663236d2ee/localhost:44349@12768036-4522-497f-833f-7ad2d7e89856" when creating an App Event Client Context (TokenHelper.CreateAppEventClientContext)

Steps to Reproduce

Create a new SharePoint provider hosted Add In project using ACS and select either SharePoint 2013 or SharePoint 2016 as the minimum version (I have not testet for SharePoint Online, but suspect the same issue there as well).
Enable Handle Add-in Installed.
Set a breakpoint on line 130 in TokenHelper.cs (inside method ReadAndValidateContextToken on the line that starts with: if (StringComparer.OrdinalIgnoreCase.Equals(token.Audience, principal)))
Debug the project.
The breakpoint will be hit and the principal does not match token.Audience because of missing port number.
Creating a token like the one in the default HomeController.cs works as expected with the port number applied.

The problem lies in that the method CreateAcsClientContextForUrl calls ReadAndValidateContextToken only including the host and not the port number.

Not sure if this is the right channel, but I get no response from contacting the AppForSharePointWebToolkit NuGet package owners (which contains the TokenHelper.cs)

Workaround is to manually modify the TokenHelper but it would be best to have this fixed in the NuGet package.

Metadata

Metadata

Assignees

Labels

area:csom/rest/apiCategory: SharePoint Client Side Object Model SDK / REST APIstatus:trackedCurrently tracked with Microsoft’s internal issue tracking system. DO NOT ADD/REMOVE (MSFT managed)type:archive-old-issueIssues which are closed as tool old for active worktype:bug-confirmedConfirmed bug, not working as designed / expected.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions