Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Getting access token in Provider hosted app.

$
0
0

Below code is used to get the access token that is required for SharePoint authorization. I have created below understanding with this code, please correct me if i am wrong somewhere.

  1. This code will only work with SharePoint online not with On-Premises Installation.
  2. Host web provides the content token in URL.
  3. TokenHelper.GetContextTokenFromRequest method extract that token from URL.
  4. TokenHelper.ReadAndValidateContextToken validates the context token with ACS.
  5. With the help of context token, TokenHelper.GetAccessToken retrieves Access token from ACS.
  6. Access token will be passed to TokenHelper.GetClientContextWithAccessToken() to create clientcontext.

TokenHelper.TrustAllCertificates();
string contextTokenString = TokenHelper.GetContextTokenFromRequest(Request);
if (contextTokenString != null)
{
contextToken = TokenHelper.ReadAndValidateContextToken(contextTokenString, Request.Url.Authority);
sharepointUrl = new Uri(Request.QueryString["SPHostUrl"]);
accessToken = TokenHelper.GetAccessToken(contextToken, sharepointUrl.Authority).AccessToken;
}

If i need to do same thing on-premises SharePoint installation what should i do?



Amit - Our life is short, so help others to grow.....

Whenever you see a reply and if you think is helpful, click ♥Vote As Helpful♥ And whenever you see a reply being an answer to the question of the thread, click ♥Mark As Answer♥


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>