Forum Discussion
PnP Sample Core.CloudService problem
Hi Michael,
You create a clientcontext for the site you need, if that's a sub site you want to work against then you should create the clientcontext using the sub site url.
Regarding the certificate: it's up your implementation to handle this, storing it in the local machine certificate store is definitely a valid option.
Here's my code to create the ClientContext:
ClientContext cc = AM.GetAzureADAppOnlyAuthenticatedContext( "http://psclistens1.sharepoint.com/sites/something/n2s/MailTest", ClientID, "psclistens1.onmicrosoft.com", StoreName.My, StoreLocation.LocalMachine, PfxThumb);
When it runs, I get the error:
"Could not load type 'Microsoft.IdentityModel.Clients.ActiveDirectory.ClientAssertionCertificate' from assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.13.4.878, Culture=neutral, PublicKeyToken=31bf3856ad364e35'."
Any suggestions on troubleshooting this? I know my team site url is correct. The Client ID matches what is registered in AAD. Should the tenant ID be something.onmicrosoft.com or something.sharepoint.com or a GUID? The thumbprint matches what is listed under SSL in the App Service in Azure.
Thanks,
Michael
- Sep 15, 2016
Downgrading that Nuget package to the highest 2.x patch level, v2.28.1, worked. Now I can get a client context, use it to get the title property of a SPO web, and grab the auth token from the client context. I use that auth token to create a graphClient. However, when try to use the graphClient, I get a Microsoft.Graph.ServiceException. I'm struggling with how to troubleshoot that.
if (this.accessToken != string.Empty) { GraphServiceClient graphClient = new GraphServiceClient( "https://graph.microsoft.com/v1.0", new DelegateAuthenticationProvider( async (requestMessage) => { requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", accessToken); })); var currentgraphObject = await graphClient.Organization.Request().GetAsync(); string orgName = currentgraphObject.ToString(); if (orgName != null) { Debug.WriteLine("Got org: " + orgName); } }
In the code above, it fails on the line:
var currentgraphObject = await graphClient.Organization.Request().GetAsync();
I've also tried the following line instead resulting in the same error.
var mailbox = await graphClient.Users["SpecificAccount@psclistens.com"].Request().GetAsync();
Any advice on troubleshooting this would be appreciated.
Thanks,
Michael
- Sep 08, 2016
That's correct, I have v 3.13.4 of Microsoft.IdentityModel.Clients.ActiveDirectory currently. I will change it over to v2.28.1, since that it the newest of the 2.x choices.
- BertJansenSep 07, 2016Microsoft
Can you try to downgrade the Microsoft.IdentityModel.Clients.ActiveDirectory package to a version 2.x version? Assuming your using the latest version 3.x right now...if not then we'll need to search further.
- Sep 06, 2016
Correction to my source code above - the site URL should start with HTTPS.
Realizing that I am running this locally initially, I did try the the other method signature:
ClientContext cc = AM.GetAzureADAppOnlyAuthenticatedContext(spWebUrl, ClientID, O365Tenant, @"C:\Users\mblumenthal\patha\pathb\etc...\Certificate\PSCGroupLLC.pfx", certPassword);
I get the same error.