<commit_before>using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using Xamarin.Auth;
using System.Security.Policy;

namespace Auth0.SDK
{
	/// <summary>
	/// A simple client to Authenticate Users with Auth0.
	/// </summary>
	public partial class Auth0Client
	{
		protected string Domain { get; set; }
		protected string ClientId { get; set; }

		public Auth0Client (string domain, string clientId)
		{
			this.Domain = domain;
			this.ClientId = clientId;
			this.DeviceIdProvider = new DeviceIdProvider();
		}

		public Auth0User CurrentUser { get; protected set; }

		/// <summary>
		/// The component used to generate the device's unique id
		/// </summary>
		public IDeviceIdProvider DeviceIdProvider { get; set; }

		public string CallbackUrl
		{
			get
			{
                return string.Format(Auth0Constants.DefaultCallback, this.Domain);
			}
		}

		/// <summary>
		///  Log a user into an Auth0 application given an user name and password.
		/// </summary>
		/// <returns>Task that will complete when the user has finished authentication.</returns>
		/// <param name="connection" type="string">The name of the connection to use in Auth0. Connection defines an Identity Provider.</param>
		/// <param name="userName" type="string">User name.</param>
		/// <param name="password type="string""><PASSWORD>.</param>
		public Task<Auth0User> LoginAsync(string connection, 
			string userName, 
			string password, 
			bool withRefreshToken = false,
			string scope = "openid")
		{

            var endpoint = string.Format(Auth0Constants.ResourceOwnerEndpoint, this.Domain);
			var parameters = new Dictionary<string, string> 
			{
				{ "client_id", this.ClientId },
				{ "connection", connection },
				{ "username", userName },
				{ "password", password },
				{ "grant_type", "password" },
				{ "scope",  IncreaseScopeWithOfflineAccess(withRefreshToken, scope) }
			};

			var request = new Request ("POST", new Uri(endpoint), parameters);
			return request.GetResponseAsync ().ContinueWith<Auth0User>(t => 
			{
				try
				{
					var text = t.Result.GetResponseText();
					var data = JObject.Parse(text).ToObject<Dictionary<string, string>>();

					if (data.ContainsKey ("error")) 
					{
						throw new AuthException ("Error authenticating: " + data["error"]);
					} 
					else if (data.ContainsKey ("access_token"))<commit_msg>Add `device` parameter for `/ro` calls.<commit_after>using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using Xamarin.Auth;
using System.Security.Policy;

namespace Auth0.SDK
{
	/// <summary>
	/// A simple client to Authenticate Users with Auth0.
	/// </summary>
	public partial class Auth0Client
	{
		protected string Domain { get; set; }
		protected string ClientId { get; set; }

		public Auth0Client (string domain, string clientId)
		{
			this.Domain = domain;
			this.ClientId = clientId;
			this.DeviceIdProvider = new DeviceIdProvider();
		}

		public Auth0User CurrentUser { get; protected set; }

		/// <summary>
		/// The component used to generate the device's unique id
		/// </summary>
		public IDeviceIdProvider DeviceIdProvider { get; set; }

		public string CallbackUrl
		{
			get
			{
                return string.Format(Auth0Constants.DefaultCallback, this.Domain);
			}
		}

		/// <summary>
		///  Log a user into an Auth0 application given an user name and password.
		/// </summary>
		/// <returns>Task that will complete when the user has finished authentication.</returns>
		/// <param name="connection" type="string">The name of the connection to use in Auth0. Connection defines an Identity Provider.</param>
		/// <param name="userName" type="string">User name.</param>
		/// <param name="password type="string"">User password.</param>
		public Task<Auth0User> LoginAsync(string connection, 
			string userName, 
			string password, 
			bool withRefreshToken = false,
			string scope = "openid")
		{

            var endpoint = string.Format(Auth0Constants.ResourceOwnerEndpoint, this.Domain);
			var scopeParameter = IncreaseScopeWithOfflineAccess (withRefreshToken, scope);
			var parameters = new Dictionary<string, string> 
			{
				{ "client_id", this.ClientId },
				{ "connection", connection },
				{ "username", userName },
				{ "password", password },
				{ "grant_type", "password" },
				{ "scope",  scopeParameter }
			};

			if (ScopeHasOfflineAccess (scopeParameter)) {
				var deviceId = this.DeviceIdProvider.GetDeviceId ().Result;
				parameters ["device"] = deviceId;
			}
				
			var request = new Request ("POST", new Uri(endpoint), parameters);
			return request.GetResponseAsync ().ContinueWith<Auth0User>(t => 
			{
				try
				{
					var text = t.Result.GetResponseText();
					var data = JObject.Parse(text).ToObject<Dictionary<string, string>>();

					if (data.ContainsKey ("error")) 
					{
						throw new AuthException ("Error authenticating: " + data["error"]);
					} 
					else if (data.ContainsKey ("access_token"))
{'fraction_non_alphanumeric': 0.124297071941051, 'fraction_numerical': 0.0042660461508629045, 'mean_word_length': 3.4198800342759212, 'pattern_counts': {'":': 0, '<': 42, '<?xml version=': 0, '>': 44, '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': '7366821', 'n_tokens_mistral': 1729, 'n_tokens_neox': 1470, 'n_words': 423}