C# Password-Based Application (Legacy)

When your client application is a console app or service that does not present a BarTender Cloud sign-in interface to users, you must use password-based authentication. With this type of authentication, you manually grant authorized users the ability to access the BarTender Cloud API by entering their user name and password in your console app or service.

This example demonstrates how to use the sample C# application to connect to BarTender Cloud and to generate the access token that is needed to send API requests to the server.

Note: To use this example, you must have Microsoft Visual Studio 2022 and .NET Core 8.0 installed.

ClosedStep 1: Register a password-based application or service

 Register a console application or service with BarTender Cloud, and then copy the application ID and secret for later use. To do this, follow these steps:

  1. In BarTender Cloud, click BarTender Cloud API the left navigation pane of the Manage Cloud Account view to display the BarTender Cloud API page.

  2. Click Register Application for Password-Based Access.

  3. In the Register Password-Based Access dialog, complete the following fields:

    • Name: Specifies a name for the application or service. This is the "friendly" display name.

    • Description: Specifies an optional description for the application or service.

  4. Click Register. The dialog closes, and your newly registered application or service is listed on the BarTender Cloud API page.

  5. Make a note of the application ID and secret for the application or service. To do this, click , and then click View ID & Secret. Click for each value to copy it to the clipboard, and then paste it into a safe location.

For more information about how to register your application or service, refer to Authentication.

ClosedStep 2: Enable password-based access for your user account

  1. In BarTender Cloud, click Users in the left navigation pane of the Manage Cloud Account view to display the Users page.

  2. Next to the user to whom you want to grant password-based access to the API, click , and then click Edit.

  3. In the user information dialog, select Allow password-based API access, and then click Save.

ClosedStep 3: Download the sample C# application

Download the "PasswordBasedAuthLogon" C# project from the following web page:

https://help.seagullscientific.com/BarTenderCloud/Content/Samples/PasswordBasedSampleApplication/PasswordBasedAuthLogon.zip

This is a simple C# application that you will use to connect to the BarTender Cloud API and generate an access token that you can then use to make API requests.

ClosedStep 4: Run the sample application

  1. In Visual Studio, compile and run the PasswordBasedAuthLogon.csproj project file from the folder that you downloaded.

  2. In the command prompt window, enter the following information to connect to BarTender Cloud:

    • Your BarTender Cloud URL

    • Application ID that you saved previously

    • Application secret that you saved previously

    • User name of the user account that you configured previously

    • Password of the user account that you configured previously

The sample application returns an access token in the command prompt window. Copy this token, and then use it in your script to make an API request.