4

I am creating a provider hosted app with my office 365 subscription. I created it as an asp.net MVC application and Modified the code according to this post

http://blogs.msdn.com/b/bspann/archive/2013/01/19/asp-net-mvc-based-apps-for-sharepoint-2013-on-premises.aspx

However I got this error in the token helper class, so I am clueless.

enter image description here

Update 1: WHen I initialize Visual Studio, and press F5 the first time in the app, VS asks me my office 365 credentials, however when debugging I see my account name on the Request object which is weird, I am thinking that could be the source of the issue but how to fix it?

Maybe my browser has that credential on memory:?

enter image description here

`

Update 2:
Code

[SharePointContextFilter]
public ActionResult Index()
{
    Uri hostWeb = new Uri(Request.QueryString["SPHostUrl"]);
    using(var clientContext=TokenHelper.GetS2SClientContextWithWindowsIdentity(hostWeb,Request.LogonUserIdentity))
    {
        var web= clientContext.Web;
        clientContext.Load(web, w=>w.Lists.Include(l=>l.Title).Where(l=> !l.Hidden));
        clientContext.ExecuteQuery();
        return View(web.Lists);
    }
}
3
  • What do you use for VS to get that color scheme? – RJ Cuthbertson Mar 6 '14 at 19:35
  • tools, options,color theme dark! – Luis Valencia Mar 6 '14 at 20:01
  • Oh nice. Simple enough. I thought maybe you were using an extension. – RJ Cuthbertson Mar 6 '14 at 20:19
1

Well, if you analyze the code for a second the name of the method is GetS2SClientContextWithWindowsIdentity, but I am creating a Sharepoint Online Provider Hosted App.

Does it make sense to get the client contex from a windows identity? obviously it does not.

After investigating for some minutes, I found there are other methods in the token helper class, and the one below makes more sense, doesnt it?

var contextToken = TokenHelper.GetContextTokenFromRequest(Request);
var hostWeb = Request.QueryString["SPHostUrl"];
using (var clientContext = TokenHelper.GetClientContextWithContextToken(hostWeb, contextToken, Request.Url.Authority))
{
  var web = clientContext.Web;
  clientContext.Load(web, w=>w.Lists.Include(l=>l.Title).Where(l=> !l.Hidden));
  clientContext.ExecuteQuery();
  return View(web.Lists);
​}
​ 

Posted also here on my blog for future reference: http://levalencia-public.sharepoint.com/Pages/2014/03/Solving-SigningCredentials-was-not-initialized-on-Sharepoint-Provider-Hosted-Apps.aspx

1
  • Please clarify that the link you have added is actually pointing to your own private blog – Robert Lindgren Mar 11 '14 at 7:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.