LabVIEW Web Development Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Using NI-Auth from Javascript

Hi,


This follows on from https://forums.ni.com/t5/LabVIEW/Web-services-login-from-python/td-p/3093074/page/3?lang=en but that thread is old so I thought I would start again.


We have embedded cRIOs with web configs (built in HTML and JS). These query LabVIEW VIs through HTTP to set config and pull status. We are required to add authentication to config changes so naturally would like to use NI-Auth so that 1. We don't have to implement our own auth server and system and 2. The passwords match logins for webdav, NI admin etc.

 

I found the thread above and attempted to follow it but still don't have it working. What I think I have right:

 

1. I'm using the NI primes as posted and using N to select generators and prime sets. I've had to modify the original library to support this but it is quite a simple change.

2. I am converting inputs from base64 to hex for the library and this matches online conversion utilties.

3. I'm setting the library to use 1024bit.

4. Using the jsrp library.

 

However this is still failing. There are two points that I can see that might be causing issues:

 

1. The hash function - the SRP library defaults to sha1 for 1024bit - is this correct?

2. When I wireshark the NI login page it seems to use two different base64 encodings. One for the header response (using + and / as final chars) but another for the form field inputs on the POST (using _ and - as additional characters). Can you confirm what the actual requirements are here?

 

I attach a screenshot of my library use.

James Mc
========
CLA and cRIO Fanatic
My writings on LabVIEW Development are at devs.wiresmithtech.com
Message 1 of 9
(6,536 Views)

What are the two different base64 encodings you are seeing? When you ask "what the actual requirements are here?", are you referring to the base64 encoding you need to follow in order to correctly call a POST?

0 Kudos
Message 2 of 9
(6,480 Views)

Hi Sekine,

 

Yes - I see one encoding using / and + as the final 2 characters of base64 and I see another encoding using _ and - as the final 2 characters. Knowing the requirements for this would be a good start (i.e. will one be rejected if wrong - or can either work). Obviously any other details on getting this working would be very useful as well!

 

Cheers,

James

James Mc
========
CLA and cRIO Fanatic
My writings on LabVIEW Development are at devs.wiresmithtech.com
0 Kudos
Message 3 of 9
(6,460 Views)

I've attached a packet capture image showing the different characters. Blue is server response, red is client request.

 

You can see in the server response with B it uses + and / as the additional character encodings for the base64. In the client POST it is using _ and -.

 

Any other ideas on this?

James Mc
========
CLA and cRIO Fanatic
My writings on LabVIEW Development are at devs.wiresmithtech.com
0 Kudos
Message 4 of 9
(6,427 Views)

Hi!

 

I don't typically lurk over on this side of the forums, but JoshuaP recently pointed me in this direction because I also have some JavaScript code for dealing with NIAuth logins that was part of a different internal project. Thanks to Joshua's prodding and support, I've refactored that out into its own module and got that up on the NI GitHub: https://github.com/ni/niauth-js

 

Right now all it can do is log in; there's presently no support for other NI Auth operations (such as adding or removing users). Hopefully there's enough there to get you going. Feedback is welcome. 🙂

——
Brandon Streiff
ni.com/compactdaq · ni.com/daq
Message 5 of 9
(6,409 Views)

Hi Brandon,

 

That is fantastic! I'll take a look over the next couple of days but it looks like exactly what I need. I'm not concerned about managing users at this stage - I'm assuming doing this through the silverlight interface will be acceptable to them.

 

Cheers,
James

James Mc
========
CLA and cRIO Fanatic
My writings on LabVIEW Development are at devs.wiresmithtech.com
0 Kudos
Message 6 of 9
(6,401 Views)

This is looking very promising. I'm not to familiar will calling npm modules in the browser so I built with browserify using browserify node_modules/niauth/index.js --s niauth -o hmi/lib/niauth/niauth.js

 

Now I can call niauth.login from my application and it succeeds. Need to work through making sure this follows through on future calls but it is further than I got before.

James Mc
========
CLA and cRIO Fanatic
My writings on LabVIEW Development are at devs.wiresmithtech.com
Message 7 of 9
(6,344 Views)

I stumbled accross this thread after I accidently found the niauth.js git repository and struggled with the modules as well.

Thank you both!

 

This is exactly what the NI webservices feature needs but was neglected for the last 5 years: native js NI-auth login.

 

0 Kudos
Message 8 of 9
(6,162 Views)

Hello,


We have similar requirements and I am glad to see that someone managed to make it work. 
We have a cRIO hosting a webserver. The configuration file of the cRio can be viewed/edited via WebClient interface. Each cRio has a WebService communicating with the application and responding to HTTP GET/POST requests from the WebClient (HTML and JS was done by someone else). This allows the user to view/edit config and have an overview of last measurements. Authentication is via NI-Auth.

 

Since Silverlight is deprecated, we are now thinking of taking advantage of NI-auth but without using Silverlight. I think what you guys did is what we need.
I am aware of the limitations for which only the login is available. Add/remove user can still be done via Silverlight for the moment.


- would you be so kind to create a step-by-step guide that explains what do with the content of the ni-auth-js repository? I know it is a big shot, but i try.
- additionally, a working example to play with would be amazing.
- would this also work with LV2018/2019 or it is somehow customized for LV2016?
Thanks!

0 Kudos
Message 9 of 9
(4,448 Views)