SystemLink Forum

cancel
Showing results for 
Search instead for 
Did you mean: 

SystemLink Package Repo Access from HTTP and Powershell

Solved!
Go to solution

I have been working on trying to get packages better integrated into our CI process using the NI Package Builder and packages, but I am running into issues trying to use the HTTP API with Powershell to post a package to the repository. So I took a step back and tried to use Powershell to just get all the feeds, which only results in Unauthorized errors, even when trying to use BasicAuth options. I have checked the LabVIEW API and the python examples, which seem to work, but I'd like to consolidate all my CI work to Powershell scripts. This is my the call I am trying to get to work (for now):

InvokeWebRequest -Uri "http://<syslinkserver>/nirepo/v1/feeds" -Headers @{"Authorization" = "Basic "+[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("admin:password"))} -Session s -Method Get

A coworker got things working if he posts the login creds to the form and creates the cookie that way, but shouldn't basic authorization work? Am I missing a header of something? Thanks for the suggestions!

0 Kudos
Message 1 of 3
(2,739 Views)
Solution
Accepted by topic author royalcow

AH. So I had to set the user agent to be something that wasn't whatever Powershell sets it to be (which is Mozilla something something). It doesn't matter what I use as long as it's not the default. For example:

 

InvokeWebRequest -Uri 'http://<syslink_server>/nirepo/v1/feeds/' -Headers @{ 'Authorization' = 'Basic ' + [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes('admin:password')) } -UserAgent 'totally-not-powershell'

 Note the following at the end:

-UserAgent 'totally-not-powershell'

 This seems like something that should probably be documented in the API? 

0 Kudos
Message 2 of 3
(2,712 Views)

Thanks for that information about Powershell. Interesting that it claims to be Mozilla-compatible in its user agent by default. NI Web Server uses that header to determine if the client understands HTML and tries to present a login page instead of looking for basic auth credentials. As you noticed, you can substitute another user agent that does not include Mozilla, and NI Web Server will default to basic auth. Alternatively, you can specify the "X-NI-Auth-Method: Basic" header to tell the web server that you want to use basic auth instead of whichever default it would choose.

 

Another thing to keep in mind if you use Powershell to make web requests is that it doesn't enable TLS 1.2 by default. Since current security guidelines advise moving away from TLS 1.1, future versions of NI Web Server will not have TLS 1.1 enabled. So I would recommend enabling TLS 1.2 in your scripts before making any web requests:

 

[Net.ServicePointManager]::SecurityProtocol = "tls12"

 

Or if you find that you need to still support TLS 1.1 servers:

[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11"

 

Message 3 of 3
(2,703 Views)