Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SPAppToken (context token) is null

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 =
     TokenHelper.ReadAndValidateContextToken
                             (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?

like image 931
Marijn Avatar asked Nov 12 '22 22:11

Marijn


1 Answers

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: http://msdn.microsoft.com/en-us/library/jj687469.aspx

like image 141
mark Avatar answered Nov 15 '22 06:11

mark