ClientId is used by default instead of Audience Id in file AzureAdAuthenticationBuilderExtensions.cs in .Net core 2.0
From @jatingandhi28 on September 17, 2018 9:38
File name - AzureAdAuthenticationBuilderExtensions.cs [Note this code has moved here].
public void Configure(string name, JwtBearerOptions options)
{
options.Audience = _azureOptions.ClientId;
options.Authority = $"{_azureOptions.Instance}{_azureOptions.TenantId}";
}
However It should be
public void Configure(string name, JwtBearerOptions options)
{
options.Audience = _azureOptions.AudienceId;
options.Authority = $"{_azureOptions.Instance}{_azureOptions.TenantId}";
}
Copied from original issue: aspnet/Home#3538
Looks like even the 2.0.x templates did the same thing: https://github.com/aspnet/Templating/blob/2.0.3/src/Microsoft.DotNet.Web.ProjectTemplates/content/WebApi-CSharp/Extensions/AzureAdAuthenticationBuilderExtensions.cs#L33
And the new library is largely just a copy of the old template code.
@
@jmprieur - is using the Azure AD "ClientID" as the JWT Bearer "AudienceID" acceptable? Or do you see any issues with this?
@Eilon : this is what ASP.NET Core have been doing for a while, indeed. ASP.NET used to propose the "Application Id URI". Ideally we might want to accept both (audienceId and if it's null clientId?) @brentschmaltz what do you think?
@jmprieur - If you use ClientID then it doesn't get authenticated. I have tested it calling from an APP with clientId and it didn't work.
@jmprieur this is right though it doesn't use client id by default.
@Eilon @jatingandhi28 @dallancarr: sorry if I was not clear: What matters is that the representation of the resource for which you request the access token (I'm assuming you are using ADAL.NET) is exactly the same as the audience. The validation will fail if they are different (even if a / is missing at the end).
For instance the following sample (written before the auth code was included in the library itself) has been using the client ID as the audience: https://github.com/Azure-Samples/active-directory-dotnet-native-aspnetcore/blob/master/TodoListService/Extensions/AzureAdAuthenticationBuilderExtensions.cs#L33, as this is the way the dotnet template unfolded the code. But to make it work, the client had to request a token for the resource expressed as a client ID: https://github.com/Azure-Samples/active-directory-dotnet-native-aspnetcore/blob/master/TodoListClient/MainWindow.xaml.cs#L53
which is set from this config file: https://github.com/Azure-Samples/active-directory-dotnet-native-aspnetcore/blob/master/TodoListClient/App.config#L11
Now ideally, we'd probably want the template to accept both representations, by setting the ValidAudiences property in TokenValidationParameters (it's an array)
https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/blob/master/src/Microsoft.IdentityModel.Tokens/TokenValidationParameters.cs#L655
I imagine somewhere along the line it was decided that the 'clientid' can be used in the sample by adapting AzureAdOptions. So you are right in saying that it is a little suspect.
@dallancarr @jmprieur 'clientId' has multiple aliases (in AzureAD). One is a guid, others are urls. That is one of the reasons for the 'ValidAudiences' property.
All are fine and represent the same service. The issue is, given the guid form, how can the runtime deduce the others? The user should know the others, but I have seen a few people get tripped up by this.
@Tratcher can you follow up with @jmprieur to figure out the course of action?
@Tratcher @jmprieur I think the confusion comes from OAuth and OIDC specs both use the term 'client_id'. Both are sent on the request, but the result is different. @blowdart is AudienceId a new property?
When asking for an id_token (OIDC), the 'aud' claim will equal the 'client_id' sent. When asking for an access_token, the 'aud' claim could be related to the 'scope' in the request. The receiver of the access_token decides if the 'aud' claim is valid.
In the OAuth case, it's unlikely the value of the 'client_id' sent on the request == 'aud'. But the receiver will have set its ClientId and it should match the 'aud' of the received token.
In both cases, the receiver of the token will expect the 'aud' == 'client_id'.
I don't know if we need both ClientId and AudienceId.
@brentschmaltz AudienceId is not an existing property. I think it was a proposed rename.
Moved to https://github.com/aspnet/AADIntegration/issues/50