SPAppToken (context token) is null

By : Marijn

I have a Sharepoint 2013 on premise environment for which I am developing an provider hosted app using Visual Studio.

The Visual Studio project has an app project which contains a custom ribbon button that goes to the web project. The web project is hosted on Windows Azure and here I get the error that the context token is null or an empty string.

Getting the token is done using the following code:

var contextTokenString = TokenHelper.GetContextTokenFromRequest(Request);
SharePointContextToken contextToken =
                             (contextTokenString, Request.Url.Authority);

When I see what is passed to the site hosted on Azure I notice that the SPAppToken is null. When using ULS viewer I get the error "The Azure Access Control service is unavailable"

I have already checked if the app is registered (using appregnew.aspx) and that the id is the same for this and in the appManifest.xml and web.config files.

How do I get the context token? Do I need to do something else in Azure in order to make it work?

By : Marijn


The link from the comments helped me. I'm posting the answer here so we don't need to rely on a url sticking around.

You get the "EndpointAuthorityDoesNotMatch" message when your app's launch url doesn't match the "app domain" registered for your app's client_id.
For mine this meant that I needed to re-register the app for our test server separately from our develoment server via the _layouts/15/appregnew.aspx page on the O365 site. Here's a link with more info on registering client ids:

By : mark

Message 'The Azure Access Control service is unavailable' says that SharePoint can’t construct the SPAppToken because it can’t talk to ACS (Azure Access Control) in order to do that. This could be for a variety of reasons (e.g. network connectivity problems).

You can also check this blog: CJG: The Azure Access Control service is unavailable.

By : lu_ko

This video can help you solving your question :)
By: admin