poshbotio / PoshBot

Powershell-based bot framework
MIT License
536 stars 108 forks source link

Using Sharepoint CSOM in a plugin causes error #160

Closed steam23 closed 5 years ago

steam23 commented 5 years ago

Expected Behavior

Trying to make a plugin that will use sharepoint CSOM to query a sharepoint site. When I run the module in a terminal (i.e. not in poshbot) my test module returns the name of the site.

Current Behavior

Running the plugin command in poshbot gives the error Exception calling "ExecuteQuery" with "0" argument(s): "The request was aborted: Could not create SSL/TLS secure channel."

Interestingly, if I stop poshbot and try to run the command again in the terminal I get the error as well (as opposed to before running poshbot in that terminal)

Possible Solution

I'm a little out of my depth here, but is it possible that poshbot is adding a type that is interfering with the SSL channel?

Steps to Reproduce (for bugs)

  1. Create a plugin using the following code `function test-csom() { Add-Type -path (Resolve-path "C:\Program Files\Common Files\microsoft shared\SharePoint Client\Microsoft.SharePoint.Client.dll") Add-Type -path (Resolve-path "C:\Program Files\Common Files\microsoft shared\SharePoint Client\Microsoft.SharePoint.Client.Runtime.dll")

    $siteUrl = "https://my.domain.com" $context = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl) $web = $context.Web $context.Load($web) $context.ExecuteQuery() $web.Title }

export-modulemember test-csom`

  1. install and run plugin in poshbot

Context

I'm trying to create a way for my users to interact with my sharepoint site though slack. Being able to use CSOM would open up a lot for us.

Your Environment

devblackops commented 5 years ago

Hey @steam23, You may be running into a TLS version issue. PoshBot is enforcing TLS 1.2 when the module loads but that may not work depending on what your endpoint supports.

https://github.com/poshbotio/PoshBot/blob/master/PoshBot/PoshBot.psm1#L21

In your plugin, try running the code below and using different values defined in the [Net.SecurityProtocolType] enum.

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
devblackops commented 5 years ago

Oh I just saw you're running v0.11.3. We started enforcing TLS 1.2 in v0.11.4. Maybe your endpoint is requiring TLS 1.2. Try updating to the latest PoshBot version.

steam23 commented 5 years ago

OK! That pointed me in the right direction! Turns out I had the version wrong and I was in fact using the current version. The problem turned out to be that my sharepoint 2010 install wasn't enforcing tls1.2. Using instructions from microsoft I was able to update it and it's now working. Thanks for your help and for this module :)

fredericDietrich commented 4 years ago

you should do a simple request, to your site, get cookies wich contains authentification then use it in your csom query here there is a working sample : http://fdi-sharepoint.e-monsite.com/blog/powershell/csompowershellssl.html