we are developing public client desktop application using uno-platform and we have a requirement to call one of our WEBAPI which is protected with Azure AD.
Using Client credential flow for generating the access token in public client application and the same is being passed in headers as a Bearer token to call WEPAPI.
Code used for generating Token in PublicClient Application:
string authority = String.Format("https://login.microsoftonline.com/xxxxxxbf-86f1-xxxx-xxxx-2d7cd011db47");
string secret = "xxxxxxxx7eCXUMxxxF7GIxxxxxxxvSQkIcxxxxx";
Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext authContext = new Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext(authority);
Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential clientCredential = new Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential("xxxxxxx-7974-xxxx-xxxx-9dd621fxxxxx", secret);
Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationResult authResult = await authContext.AcquireTokenAsync("dd543eda-xxxx-xxxx-xxxx-58ddd58565db", clientCredential);
string token = authResult.AccessToken;
Am able to acquire the token and call my protected webapi successfully.
However, since this going to be public client desktop application , what is the best way to secure my secret ? i cant put it in appsettings.json coz it will be exposed . I cant put in keyvault as well coz i need some other cred to access keyvault.
Any help would be greatly appreciated. thanks