Uses of client secret in production environment is not advisable.
Microsoft recommend to use SSL Certificate in production environment.
Here are the steps to use it.
- Register the app in azure ad.
- give the app permission as per your need.
- Get SSL certificate or Self Signed Certificate with key protected.
- Go to certificates & secrets section and upload it the certification. after this step you will get thumbprint.
- Go to authentication section - add platform as website and add redirect URL of app.
After this -- Your code should acquire the token using certificate.
here are the steps for this.
Store your App ID, Tenant ID, Thumbprint in app config or azure key vault if you want more security.
Read the configurable from app config file or Azure Key Vault.
for configuration and use of Azure key vault use below link
configure azure key vault
- How to validate and read the certificate from Local machine or Azure.
• define the scope,
> // “/.default” indicate that _api permission is already defined in azure ad
> var scopes = new string[] { "https://yourdomail.sharepoint.com/.default" };
• here is code to acquire the token.
internal static async Task<string> GetApplicationAuthenticatedClient(string clientId, string certThumprint, string[] scopes, string tenantId)
{
X509Certificate2 certificate = GetAppOnlyCertificate(certThumprint);
IConfidentialClientApplication clientApp = ConfidentialClientApplicationBuilder
.Create(clientId)
.WithCertificate(certificate)
.WithTenantId(tenantId)
.Build();
AuthenticationResult authResult = await clientApp.AcquireTokenForClient(scopes).ExecuteAsync();
string accessToken = authResult.AccessToken;
return accessToken;
}
You can refer this link for more details.
Configure SSL Certificate in code
You can refer below link how to Add a TLS/SSL certificate in Azure App Service.
TLS/SSL certificate in Azure App Service
Now coming to your questions.
Even if thumbprint is compromised or known to another person. He cannot use it or do any operation as he or she will require to install this certificate at his/her location with key. As Thumbprint is installed on server with private key and uploaded in azure ad which is much more secure.
Please accept the answer and upvote it if you are satisfied.