Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AADSTS70002: Error validating credentials. AADSTS50012: Invalid client secret is provided

When I am trying to create an authentication header using the below code. I am getting an error saying "AADSTS70002: Error validating credentials. AADSTS50012: Invalid client secret is provided." Now, I am sure, that the secret which I used in the code is not matching with the one used in my AAD app registration. Can anybody help me on how to get the client secret, from my app registrations or how to add a new application identifier in my O365 account directory.

private string GetAuthenticationHeader(AuthenticationInformation authenticationInformation){
    try{
        return RetryHelper.InvokeWithRetries(() =>
        {
            var clientCredential = new ClientCredential(authenticationInformation.ClientId, authenticationInformation.AppSecret);
            var ac = new AuthenticationContext(authenticationInformation.Authority);
            AuthenticationResult ar = ac.AcquireToken(authenticationInformation.Resource, clientCredential);
            return ar.CreateAuthorizationHeader();
        });
    }
    catch (Exception ex){
        return ex.Message;
    }
}
like image 575
Venkata V Avatar asked Aug 15 '17 08:08

Venkata V


1 Answers

To add a secret key for your web application's credentials, click the "Keys" section from the Settings blade of your Azure AD App in Azure Portal :

  • Add a description for your key and select either a 1 or 2 or year duration(or never expires).
  • The right-most column will contain the key value, after you save the configuration changes. Be sure to come back to this section and copy it after you hit save, so you will have it for use in your client application during authentication at run-time.

Please click here for more details about how to register and update your application with your Azure Active Directory tenant .

like image 165
Nan Yu Avatar answered Sep 19 '22 15:09

Nan Yu