<commit_before>﻿using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using EncompassREST.Exceptions;
using EncompassREST.HelperClasses;
using Newtonsoft.Json;

namespace EncompassREST
{
    public class AccessToken
    {
        private const string _accessTokenUrlV2 = "https://api.elliemae.com/oauth2/v1/";

        private readonly HttpClient _authClient;
        private readonly string _clientId;
        private readonly string _clientSecret;
        private readonly string _instanceId;
        private readonly string _basicAuthValue;

        private TokenResponse _token;

        #region Properties
        public Session Session { get; }

        public string Token => _token.AccessToken;

        public string Type => _token.TokenType;

        public string AuthenticationString => $"{Type} {Token}";
        #endregion

        public AccessToken(string clientId, string clientSecret, string instanceId, Session session)
        {
            Session = session;
            _authClient = new HttpClient()
            {
                BaseAddress = new Uri(_accessTokenUrlV2)
            };
            _basicAuthValue = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes($"{clientId}:{clientSecret}"));
            _authClient.DefaultRequestHeaders.Add("Authorization", _basicAuthValue);

            _clientId = clientId;
            _clientSecret = clientSecret;
            _instanceId = instanceId;
        }
<commit_msg>Update to add URL Encode of _clientSecret<commit_after>﻿using System;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using EncompassREST.Exceptions;
using EncompassREST.HelperClasses;
using Newtonsoft.Json;

namespace EncompassREST
{
    public class AccessToken
    {
        private const string _accessTokenUrlV2 = "https://api.elliemae.com/oauth2/v1/";

        private readonly HttpClient _authClient;
        private readonly string _clientId;
        private readonly string _clientSecret;
        private readonly string _instanceId;
        private readonly string _basicAuthValue;

        private TokenResponse _token;

        #region Properties
        public Session Session { get; }

        public string Token => _token.AccessToken;

        public string Type => _token.TokenType;

        public string AuthenticationString => $"{Type} {Token}";
        #endregion

        public AccessToken(string clientId, string clientSecret, string instanceId, Session session)
        {
            Session = session;
            _clientSecret = WebUtility.UrlEncode(clientSecret);
            _authClient = new HttpClient()
            {
                BaseAddress = new Uri(_accessTokenUrlV2)
            };
            _basicAuthValue = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes($"{clientId}:{_clientSecret}"));
            _authClient.DefaultRequestHeaders.Add("Authorization", _basicAuthValue);

            _clientId = clientId;
            _instanceId = instanceId;
        }

{'fraction_non_alphanumeric': 0.07786752827140549, 'fraction_numerical': 0.004523424878836834, 'mean_word_length': 2.7077844311377244, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 2, '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': '7521306', 'n_tokens_mistral': 805, 'n_tokens_neox': 783, 'n_words': 202}