Created
July 10, 2014 21:07
-
-
Save chrisobriensp/220f7f1b5cdbb8067474 to your computer and use it in GitHub Desktop.
SharePoint .NET CSOM code sample showing how to get ClientContext using "app only" authentication. (N.B. the app permissions must allow this)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // obtain web URL somehow - line below is fine for a list item RER, but you'll need another approach elsewhere.. | |
| string webUrl = properties.ItemEventProperties.WebUrl; | |
| Uri webUri = new Uri(webUrl); | |
| string realm = TokenHelper.GetRealmFromTargetUrl(webUri); | |
| string accessToken = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, webUri.Authority, realm).AccessToken; | |
| using (var clientContext = TokenHelper.GetClientContextWithAccessToken(webUrl, accessToken)) | |
| { | |
| // do CSOM stuff here.. | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment