I have a provider hosted app connected to a SharePoint site. I want to write some code that allows the provider hosted app to create/get data on a different sharepoint site. I read articles that imply OAUTH should let this all happen, but I cant get it to work. Here's my code that doesnt work

var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);
string userAccessToken = spContext.UserAccessTokenForSPHost;
UserAssertion userAssertion = new UserAssertion(userAccessToken);
AuthenticationContext authenticationContext = new AuthenticationContext("https://login.windows.net/siteA.onmicrosoft.com", false);
ClientCredential clientCred = new ClientCredential("clientID", "clientSecret");
AuthenticationResult authenticationResult = await authenticationContext.AcquireTokenAsync("https://siteB.sharepoint.com", clientCred,userAssertion)

I don't think this kind of code works in SharePoint. I think you need to use OAuthAuthorize.aspx to get an oauth token for the current user on a different sharepoint instance.

lots of articles how to use OAuthAuthorize.aspx, this is one of them


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.