AspNetCoreMicrosoftGraph icon indicating copy to clipboard operation
AspNetCoreMicrosoftGraph copied to clipboard

Error on missing client secret / certificate

Open bbqchickenrobot opened this issue 3 years ago • 6 comments

MsalClientException: IDW10104: Both client secret and client certificate cannot be null or whitespace, and only ONE must be included in the configuration of the web app when calling a web API. For instance, in the appsettings.json file. Microsoft.Identity.Web.MicrosoftIdentityOptionsValidation.ValidateEitherClientCertificateOrClientSecret(string clientSecret, IEnumerable<CertificateDescription> cert) Microsoft.Identity.Web.TokenAcquisition.BuildConfidentialClientApplicationAsync() Microsoft.Identity.Web.TokenAcquisition.GetOrBuildConfidentialClientApplicationAsync() Microsoft.Identity.Web.TokenAcquisition.AddAccountToCacheFromAuthorizationCodeAsync(AuthorizationCodeReceivedContext context, IEnumerable scopes) Microsoft.Identity.Web.MicrosoftIdentityWebAppAuthenticationBuilder+<>c__DisplayClass11_1+<<WebAppCallsWebApiImplementation>b__1>d.MoveNext() Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler.RunAuthorizationCodeReceivedEventAsync(OpenIdConnectMessage authorizationResponse, ClaimsPrincipal user, AuthenticationProperties properties, JwtSecurityToken jwt) Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler.HandleRemoteAuthenticateAsync()

Any idea what this could be ? I have passed in the client secret.

bbqchickenrobot avatar Mar 29 '21 21:03 bbqchickenrobot

Hi @bbqchickenrobot

You need to create a secret (or certificate) in the Azure App registration and add this to your user secrets

Greetings Damien

damienbod avatar Mar 30 '21 06:03 damienbod

Awesome @damienbod - that worked! Thanks for the tip and the tutorial!

bbqchickenrobot avatar Mar 30 '21 13:03 bbqchickenrobot

Awesome @damienbod - that worked! Thanks for the tip and the tutorial!

I understand the registration of a secret part. But where did you apply the secret?

PontusEkengren avatar Apr 19 '21 20:04 PontusEkengren

In the code in the Starupt.cs and the appsettings.json. Add an "azuread_secret": "my secret". to appsettings and load it during startup

bbqchickenrobot avatar Apr 19 '21 20:04 bbqchickenrobot

Thanks, yes i got it now. If anyone else have the same problem as me: dont forget to add your secrets with colon like dotnet user-secrets set "AzureAd:ClientSecret" "secretGoesHere*********************"

When using a depth in the appsettings.json

PontusEkengren avatar Apr 20 '21 06:04 PontusEkengren

Good to know, I was hoping I could avoid using a secret entirely and use the token for the user, but it would seem it doesn't work this way.

Mr-Technician avatar Jul 14 '21 18:07 Mr-Technician