<commit_before>﻿/*
 * Copyright (c) <NAME>, <NAME>.  All rights reserved.
 * see LICENSE
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;

namespace Thinktecture.IdentityModel.Client
{
	public class OAuth2Client
	{
		protected HttpClient _client;
		protected ClientAuthenticationStyle _authenticationStyle;
		protected Uri _address;
		protected string _clientId;
		protected string _clientSecret;

		public enum ClientAuthenticationStyle
		{
			BasicAuthentication,
			PostValues,
			None
		};

		public OAuth2Client(Uri address)
		{
			_client = new HttpClient
			{
				BaseAddress = address
			};
			
			_address = address;
			_authenticationStyle = ClientAuthenticationStyle.None;
		}

		public OAuth2Client(Uri address, string clientId, string clientSecret, ClientAuthenticationStyle style = ClientAuthenticationStyle.BasicAuthentication)
			: this(address)
		{
			if (style == ClientAuthenticationStyle.BasicAuthentication)
			{
				_client.DefaultRequestHeaders.Authorization = new BasicAuthenticationHeaderValue(clientId, clientSecret);
			}
			else if (style == ClientAuthenticationStyle.PostValues)
			{
				_clientId = clientId;
				_clientSecret = clientSecret;
			}
		}

		public string CreateCodeFlowUrl(string clientId, string scope = null, string redirectUri = null, string state = null, Dictionary<string, string> additionalValues = null)
		{
			return CreateAuthorizeUrl(
				clientId,<commit_msg>added new constructor to allow passing in an inner HttpMessageHandler for the HttpClient instance being used by the OAuth2Client<commit_after>﻿/*
 * Copyright (c) <NAME>, <NAME>.  All rights reserved.
 * see LICENSE
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;

namespace Thinktecture.IdentityModel.Client
{
	public class OAuth2Client
	{
		protected HttpClient _client;
		protected ClientAuthenticationStyle _authenticationStyle;
		protected Uri _address;
		protected string _clientId;
		protected string _clientSecret;

		public enum ClientAuthenticationStyle
		{
			BasicAuthentication,
			PostValues,
			None
		};

        public OAuth2Client(Uri address) : this(address, new HttpClientHandler())
        {
        }

		public OAuth2Client(Uri address, HttpMessageHandler innerHttpClientHandler)
		{
            if (innerHttpClientHandler == null)
            {
                throw new ArgumentNullException("innerHttpClientHandler");
            }

			_client = new HttpClient(innerHttpClientHandler)
			{
				BaseAddress = address
			};
			
			_address = address;
			_authenticationStyle = ClientAuthenticationStyle.None;
		}

		public OAuth2Client(Uri address, string clientId, string clientSecret, ClientAuthenticationStyle style = ClientAuthenticationStyle.BasicAuthentication)
			: this(address)
		{
			if (style == ClientAuthenticationStyle.BasicAuthentication)
			{
				_client.DefaultRequestHeaders.Authorization = new BasicAuthenticationHeaderValue(clientId, clientSecret);
			}
			else if (style == ClientAuthenticationStyle.PostValues)
			{
				_clientId = clientId;
				_clientSecret = clientSecret;
			}
		}

		public string CreateCodeFlowUrl(string clientId, string scope = null, string redirectUri = null, string state = null, Dictionary<string, string> additionalValues = null)
		{
			return CreateAuthorizeUrl(
				clientId,
{'fraction_non_alphanumeric': 0.07298001737619461, 'fraction_numerical': 0.0023168259484506225, 'mean_word_length': 4.193984962406015, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2765265', 'n_tokens_mistral': 1051, 'n_tokens_neox': 911, 'n_words': 243}