question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ClientCredentialsHelper should check if ClientId or ClientSecret are not yet added to request

See original GitHub issue

Hello,

I am using HttpClientTokenRequestExtensions from IdentityModel v3.10.0. For method RequestTokenAsync I am passing clientId and clientSecret by my self like:

var parameters = new Dictionary<string, string>
{
    {"grant_type", "delegation"},
    {"client_id", clientId},
    {"client_secret", clientSecret},
    {"token_hint", userAccessToken},
};

var tokenResponse = await _client
    .RequestTokenAsync(new TokenRequest
    {
        Address = tokensEndpoint,
        ClientId = clientId,
        ClientSecret = clientSecret,
        GrantType = "delegation",
        Parameters = parameters
    }, cancellationToken)
    .ConfigureAwait(false);

I am aware that I am duplicating stuff… however having the code like above will throw exception:

An item with the same key has already been added. Key: client_id

Short investigation showed that ClientCredentialsHelper does not check if parameters are already added which causes this exception: https://github.com/IdentityModel/IdentityModel2/blob/master/src/Internal/ClientCredentialsHelper.cs#L32

However its fine with GranType, which is checked and added in RequestTokenAsync method: https://github.com/IdentityModel/IdentityModel2/blob/master/src/Client/New/HttpClientTokenRequestExtensions.cs#L115

if (!request.Parameters.ContainsKey(OidcConstants.TokenRequest.GrantType))
{
    request.Parameters.AddRequired(OidcConstants.TokenRequest.GrantType, request.GrantType);
}

I guess should be the same also with other arguments.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
leastprivilegecommented, Nov 28, 2018

I am doing a more defensive check now. thanks for reporting.

0reactions
github-actions[bot]commented, Feb 21, 2021

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

missing client_secret in RequestDeviceAuthorizationAsync
ClientCredentialStyle , default to ClientCredentialStyle.PostBody , seems doesn't take any effects. no call of ClientCredentialsHelper.
Read more >
Invalid client secret provided - Microsoft Q&A
Check if the client secret is being referenced correctly in all of your config settings. Ensure that the client secret is being referenced...
Read more >
Invalid client secret provided. - Microsoft Q&A
Ensure the secret being sent in the request is the client secret value, not the client secret ID, for a secret added to...
Read more >
The Client ID and Secret - OAuth 2.0 Simplified
This is the only way to ensure the developer won't accidentally include it in their application. If it doesn't exist, it can't be...
Read more >
The connection test of the OAuth 2.0 integration fails with ...
An incorrect Client ID or Client Secret value was used in the OAuth 2.0 configuration. ... This can happen if the application has...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found