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.
- This code will only work with SharePoint online not with On-Premises Installation.
- Host web provides the content token in URL.
- TokenHelper.GetContextTokenFromRequest method extract that token from URL.
- TokenHelper.ReadAndValidateContextToken validates the context token with ACS.
- With the help of context token, TokenHelper.GetAccessToken retrieves Access token from ACS.
- 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♥