pnp / PnP-Sites-Core

Microsoft 365 Dev PnP Core component (.NET) targeted for increasing developer productivity with CSOM based solutions.
Other
416 stars 642 forks source link

JWT 5.2.0 PnP DotNetCore 2.0 Compatability issue #1589

Open dbnardi opened 6 years ago

dbnardi commented 6 years ago

Hi all, seem to have an issue with the JWT authentication using NetCore 2.0. This was working until I switched to JWT authentication from standard aspnetcore identity, so I believe it may be some kind of compatibility problem.

(Apologies for the code formatting, not sure what's going on there...)

Category

[X] Bug [ ] Enhancement

Environment

[X] Office 365 / SharePoint Online [ ] SharePoint 2016 [ ] SharePoint 2013

Expected or Desired Behavior

When calling the ApplyProvisioningTemplate function it should provision the content to my SharePoint environment

Observed Behavior

Exception is thrown: Could not load type 'System.IdentityModel.Tokens.JwtSecurityToken' from assembly 'System.IdentityModel.Tokens.Jwt, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

Stack Trace:

at Microsoft.SharePoint.Client.ClientContextExtensions.IsAppOnly(ClientRuntimeContext clientContext) at OfficeDevPnP.Core.Framework.Provisioning.ObjectHandlers.TokenParser..ctor(Web web, ProvisioningTemplate template) at OfficeDevPnP.Core.Framework.Provisioning.ObjectHandlers.SiteToTemplateConversion.ApplyRemoteTemplate(Web web, ProvisioningTemplate template, ProvisioningTemplateApplyingInformation provisioningInfo) at Microsoft.SharePoint.Client.WebExtensions.ApplyProvisioningTemplate(Web web, ProvisioningTemplate template, ProvisioningTemplateApplyingInformation applyingInformation) at MTP.DeploymentPortal.PnP.Utility.PnPHelper.ApplyProvisioningTemplate(String webUrl, String userName, SecureString pwd, ProvisioningTemplate template, Nullable1 environment, ProgressNotifier progressCallback)`

Steps to Reproduce

Believe this may be a compatibility issue with the latest version of SharePointPnPCoreOnline and System.IdentityModel.Tokens.Jwt.

Here is my function:

` //prep data string cstring = config.GetConnectionString("MTPAzureContainer"); XMLAzureStorageTemplateProvider provider = new XMLAzureStorageTemplateProvider(cstring, model.Product.AzureBlobName); var template = provider.GetTemplate("provision.xml");

            // Associate file connector for assets
            AzureStorageConnector connector = new AzureStorageConnector(cstring, model.Product.AzureBlobName);
            template.Connector = connector;

            // Apply template to new site from 
            PnPHelper.ApplyProvisioningTemplate(environment.Url, environment.Login, GeneralHelpers.Decrypt(environment.Password), template, environment.SharePointEnvironment, new PnPHelper.ProgressNotifier(PnPProgress)); //***FAILS HERE***

            //Save the deployment
            Deployment deployment = new Deployment(){
                ProductVersion = currentVersion,
                SystemEnvironment = environment,
                Status = DeploymentStatus.Success,
                DeploymentDate = DateTime.Now,
                DeploymentLog = string.Format("Deployment of product: {0} to environment: {1} for client: {2} completed successfully at {3}", product.Name, environment.EnvironmentName, environment.Client.Name, DateTime.Now.ToString())
            };
            SaveDeployment(deployment);

            //TODO: include version here when we implement the version deployment system
            var prodVM = model.Product;
            prodVM.LastDeployed = DateTime.Now.ToString();
            return Json(prodVM);`

Here is my csproj manifest:

`

<TargetFramework>net462</TargetFramework>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
<IsPackable>false</IsPackable>

` Thanks in advance!
mortizjimenez commented 6 years ago

I am also facing similar issues with version 2.23.1802.

Issue 1 - When calling GetTemplate, there is an exception. Exception details reveal the following LoaderExceptions (the same exception is listed three times):

"Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory, Version=2.29.0.1078, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified."

asumner commented 5 years ago

@mortizjimenez @nardz Is this because the Microsoft.SharePoint.Client is not yet .Net Standard compatible (something we are eagerly awaiting, I hope is released soon March 2019 who knows??)