Forum Discussion
PnP Sample Core.CloudService problem
I've got another question about using App-only authentication with Azure AD. Using GetAzureADAppOnlyAuthenticatedContext() is great for getting a ClientContext, but a ClientContext only helps me with using SharePoint CSOM. In the particular web service I am writing, it recieves the messageID of an email that is in Exchange Online. I want to get the subject and attachment from that email message (and then store it in SharePoint). I believe I can get the email details and content using the Graph REST API, but I need to send a bearer token in the Authorization header in the HTTP request when I do that. Can the AuthenticationManager help me with that? If not, what's the right way to get that? Is lines 43-48 of https://github.com/richdizz/MyO365BackgroundProcess/blob/master/MyO365BackgroundProcess/Program.cs a good example to follow?
Thanks,
Michael
Hi Michael,
Once you've a clientcontext object you can always grab the bearer token using the ExecutingWebRequest handler on the ClientContext object
private void Cc_ExecutingWebRequest(object sender, WebRequestEventArgs e)
{
// Capture the OAuth access token since we want to reuse that one in our REST requests
this.accessToken = e.WebRequestExecutor.RequestHeaders.Get("Authorization").Replace("Bearer ", "");
}