<commit_before>﻿using System.IO;
using System.Net;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Web;

namespace D2L.Security.AuthTokenValidation.Tests.Utilities {

	internal static class AuthServerInvoker {
		
		public static string AuthenticateAndGetJwt( string clientId, string clientSecret, string scope ) {
			HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create( TestUris.AUTH_TOKEN_PROVISIONING_URI );
			request.Method = "POST";
			request.ContentType = "application/x-www-form-urlencoded";

			string authorizationHeaderValue = HttpUtility.UrlEncode( clientId ) + ":" + HttpUtility.UrlEncode( clientSecret );
			authorizationHeaderValue = authorizationHeaderValue.ToBase64();
			authorizationHeaderValue = "Basic " + authorizationHeaderValue;
			request.Headers["Authorization"] = authorizationHeaderValue;

			string formContents = "grant_type=client_credentials&scope=" + scope;
			using( StreamWriter write = new StreamWriter( request.GetRequestStream() ) ) {
				write.Write( formContents );
			}

			WebResponse response = request.GetResponse();

			DataContractJsonSerializer serializer = new DataContractJsonSerializer( typeof( AuthServerResponse ) );
			AuthServerResponse authServerResponse = (AuthServerResponse)serializer.ReadObject( response.GetResponseStream() );

			return authServerResponse.access_token;
		}<commit_msg>Dispose properly in test helper<commit_after>﻿using System.IO;
using System.Net;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Web;

namespace D2L.Security.AuthTokenValidation.Tests.Utilities {

	internal static class AuthServerInvoker {
		
		public static string AuthenticateAndGetJwt( string clientId, string clientSecret, string scope ) {
			HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create( TestUris.AUTH_TOKEN_PROVISIONING_URI );
			request.Method = "POST";
			request.ContentType = "application/x-www-form-urlencoded";

			string authorizationHeaderValue = HttpUtility.UrlEncode( clientId ) + ":" + HttpUtility.UrlEncode( clientSecret );
			authorizationHeaderValue = authorizationHeaderValue.ToBase64();
			authorizationHeaderValue = "Basic " + authorizationHeaderValue;
			request.Headers["Authorization"] = authorizationHeaderValue;

			string formContents = "grant_type=client_credentials&scope=" + scope;
			using( StreamWriter write = new StreamWriter( request.GetRequestStream() ) ) {
				write.Write( formContents );
			}

			using( WebResponse response = request.GetResponse() ) {
				DataContractJsonSerializer serializer = new DataContractJsonSerializer( typeof( AuthServerResponse ) );
				AuthServerResponse authServerResponse = (AuthServerResponse)serializer.ReadObject( response.GetResponseStream() );

				return authServerResponse.access_token;
			}
		}
{'fraction_non_alphanumeric': 0.09001058948111543, 'fraction_numerical': 0.002117896223085069, 'mean_word_length': 5.912195121951219, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2149583', 'n_tokens_mistral': 827, 'n_tokens_neox': 739, 'n_words': 153}