<commit_before>﻿using IdentityModel.Client;
using System;
using System.Net.Http;

namespace IdentityModel.Internal
{
    internal static class ClientCredentialsHelper
    {
        internal static void PopulateClientCredentials(
            ProtocolRequest request,
            HttpRequestMessage httpRequest)
        {
            if (request.ClientId.IsPresent())
            {
                if (request.ClientCredentialStyle == ClientCredentialStyle.AuthorizationHeader)
                {
                    if (request.AuthorizationHeaderStyle == BasicAuthenticationHeaderStyle.Rfc6749)
                    {
                        httpRequest.SetBasicAuthenticationOAuth(request.ClientId, request.ClientSecret ?? "");
                    }
                    else if (request.AuthorizationHeaderStyle == BasicAuthenticationHeaderStyle.Rfc2617)
                    {
                        httpRequest.SetBasicAuthentication(request.ClientId, request.ClientSecret ?? "");
                    }
                    else
                    {
                        throw new InvalidOperationException("Unsupported basic authentication header style");
                    }
                }
                else if (request.ClientCredentialStyle == ClientCredentialStyle.PostBody)
                {
                    request.Parameters.AddRequired(OidcConstants.TokenRequest.ClientId, request.ClientId);
                    request.Parameters.AddOptional(OidcConstants.TokenRequest.ClientSecret, request.ClientSecret);
                }
                else
                {
                    throw new InvalidOperationException("Unsupported client credential style");
                }
            }

            if (request.ClientAssertion != null)
            {
                request.Parameters.AddOptional(OidcConstants.TokenRequest.ClientAssertionType, request.ClientAssertion.Type);
                request.Parameters.AddOptional(OidcConstants.TokenRequest.ClientAssertion, request.ClientAssertion.Value);
            }
        }
    }
}<commit_msg>more null checking<commit_after>﻿using IdentityModel.Client;
using System;
using System.Net.Http;

namespace IdentityModel.Internal
{
    internal static class ClientCredentialsHelper
    {
        internal static void PopulateClientCredentials(
            ProtocolRequest request,
            HttpRequestMessage httpRequest)
        {
            if (request.ClientId.IsPresent())
            {
                if (request.ClientCredentialStyle == ClientCredentialStyle.AuthorizationHeader)
                {
                    if (request.AuthorizationHeaderStyle == BasicAuthenticationHeaderStyle.Rfc6749)
                    {
                        httpRequest.SetBasicAuthenticationOAuth(request.ClientId, request.ClientSecret ?? "");
                    }
                    else if (request.AuthorizationHeaderStyle == BasicAuthenticationHeaderStyle.Rfc2617)
                    {
                        httpRequest.SetBasicAuthentication(request.ClientId, request.ClientSecret ?? "");
                    }
                    else
                    {
                        throw new InvalidOperationException("Unsupported basic authentication header style");
                    }
                }
                else if (request.ClientCredentialStyle == ClientCredentialStyle.PostBody)
                {
                    request.Parameters.AddRequired(OidcConstants.TokenRequest.ClientId, request.ClientId);
                    request.Parameters.AddOptional(OidcConstants.TokenRequest.ClientSecret, request.ClientSecret);
                }
                else
                {
                    throw new InvalidOperationException("Unsupported client credential style");
                }
            }

            if (request.ClientAssertion != null)
            {
                if (request.ClientAssertion.Type != null && request.ClientAssertion.Value != null)
                {
                    request.Parameters.AddOptional(OidcConstants.TokenRequest.ClientAssertionType, request.ClientAssertion.Type);
                    request.Parameters.AddOptional(OidcConstants.TokenRequest.ClientAssertion, request.ClientAssertion.Value);
                }
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.06896551724137931, 'fraction_numerical': 0.003727865796831314, 'mean_word_length': 1.6915360501567398, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6425259', 'n_tokens_mistral': 940, 'n_tokens_neox': 891, 'n_words': 139}