此內容不適用於您所偏好的語言。

此內容已顯示為其他適用語言。 您的瀏覽器可能含有可協助翻譯的套件。

Perform Microsoft OAuth 2.0 Authorization Using LabVIEW

Updated Dec 18, 2023

Reported In

Software

  • LabVIEW

Programming Language

  • C# .NET

Issue Details

I want to protect my application using the Microsoft OAuth2 authorization protocol, so that only authorized users can access my application. Can I do this in LabVIEW?

Solution

You can leverage the Microsoft Azure Active Directory service and the .NET API it exposes to perform the authorization.
Follow these steps:
  1. Install Microsoft.IdentityModel.Clients.ActiveDirectory package using the NuGet.exe CLI. This package contains the binaries of the Active Directory Authentication Library (ADAL). ADAL provides easy to use authentication functionality for your .NET based client (in this case, NI LabVIEW) by taking advantage of Azure Active Directory.
  2. Register the previously installed .NET DLL (Microsoft.IdentityModel.Clients.ActiveDirectory.dll) in the Global Assembly Cache (GAC).
  3. You are now ready to use this library in LabVIEW using Constructor Nodes, Invoke Nodes (.NET), and Property Nodes (.NET)
  4. Register a native app in the azure portal.
  5. Refer to the snippet below to generate a AccessToken.

Figure 1: VI Snippet can directly be dragged and dropped into your block diagram 
 
  1. The AcquireTokenAsync() method generates a prompt asking the user for their credentials as shown below.
Sign in.png
Figure 2: User Credentials Prompt
  1. If the user has access to the Tenant (configured in Azure Portal), they will be able to go ahead and execute rest of their VI and generate access token which can then be used to access other Azure API such as Blob and Queues.
 

Additional Information

Access to Azure Blob and Queues API is available in the NI Cloud Toolkit for Azure.