I am trying to create a C# application to access Device IDs from IOTCentral. How can I authenticate the user of the application?

Duncan Groenewald

I am currently looking at these examples here but can't get the Example to work as it complains about some invalid format.

The Preview example works find but requires me to have logged in via the azure CLI. I need the users of the application to be able to log in to the application wherever it is to authenticate to IOTCentral.

What API is used to do that - the Azure examples seem to either not work or rely on the az CLI to handle the log in.

Error from Example System.ArgumentException: ''authority' should be in URI format. Arg_ParamName_Name'

PreviewExample

namespace PreviewExamples {
    internal class Program
    {        
        private static void Main(string[] args)
        {
            // Using 'az login' first, and using 'az account set -s subscription'
            var credential = new DefaultAzureCredential();

            var subdomain = "app-name";

            // Users example
            // UserRoleOrgsExample.Run(subdomain, credential);

            DeviceExample.Run(subdomain, credential);
        }
    }
}
Matthijs van der Veer

Quick C# sample where you have the user log in through a browser popup:

using var httpClient = new HttpClient();
var cred = new InteractiveBrowserCredential();
var token = await cred.GetTokenAsync(new TokenRequestContext(new[] {"https://apps.azureiotcentral.com/.default"}), CancellationToken.None);

httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Token);

using var centralClient = new AzureIoTCentral(httpClient, true);
centralClient.Subdomain = Constants.AppName;
centralClient.ApiVersion = Constants.ApiVersion;

var devices = await centralClient.Devices.ListAsync();

Or if you want to use an API key, like Roman suggested:

using var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("Authorization", $"SharedAccessSignature sr=stuffnotfortheinternet");

using var centralClient = new AzureIoTCentral(httpClient, true);
centralClient.Subdomain = Constants.AppName;
centralClient.ApiVersion = Constants.ApiVersion;

var devices = await centralClient.Devices.ListAsync();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I authenticate a Windows Domain user from a .NET Core application running on Linux

How can I access a DDC/CI Display Dependent Device from a Windows application?

I have an appointment scheduling application I am trying to create

How I can access to menubar and sub ment on another application from my c# application?

How can I restore Nativescript application code from android device?

How can I access files inside My User folder from the application?

How can I re-authenticate a user already signed in under an Okta application using Java?

i am trying to create a simple hibernate application.It gives following error.how to solve that error

How can I prevent the user from using the application on his device even if he re-installed the app multiple times

How can I prevent an application (or user) from changing the screen resolution?

How can Wordpress to authenticate a user in a existing application?

How Can I Access To SolidBrush In Console Application C#

How can I create output from a CFFUNCTION with type "application/json"?

How can I create a android app from laravel web application?

how can I create a deb package from click qml application?

When I am adding fragment to my view pager (in nested scroll view), I can not exit from application with device back button

How can i access the Windows Explorer context menu from a C# application?

How can I limit or restrict access to an application?

How can I create a MERN Stack application?

I am trying to build a CRUD application In Vue.Js i cannot insert user

How can I access the application manifest of the running application?

How can I access VO in one application module from a VO in another application module?

How can I connect to Memgraph from my C# application?

Can I use Service Principal to authenticate an application that is not hosted in Azure using role-based access control?

How can I deploy and execute an application on a device connected to a remote system?

How can I switch an application to a different playback device on Windows 10

How can I start android application on device boot?

How can I deploy an iPhone application from Xcode to a real iPhone device?

How can I change the audio input from one device to another in web application using MVC?