public async Task <(string Token, string RefreshToken)> TokenFromPasswordAsync(string username, string password, string deviceIdentifier = DefaultDeviceIdentifier, string clientId = "web", DeviceType deviceType = DeviceType.FirefoxBrowser, string deviceName = "firefox") { var context = await Server.PostAsync("/connect/token", new FormUrlEncodedContent(new Dictionary <string, string> { { "scope", "api offline_access" }, { "client_id", clientId }, { "deviceType", ((int)deviceType).ToString() }, { "deviceIdentifier", deviceIdentifier }, { "deviceName", deviceName }, { "grant_type", "password" }, { "username", username }, { "password", password }, }), context => context.Request.Headers.Add("Auth-Email", CoreHelpers.Base64UrlEncodeString(username))); using var body = await AssertHelper.AssertResponseTypeIs <JsonDocument>(context); var root = body.RootElement; return(root.GetProperty("access_token").GetString(), root.GetProperty("refresh_token").GetString()); }
public async Task BlockIpAsync(string ipAddress, bool permanentBlock) { await InitAsync(); var now = DateTime.UtcNow; if (_lastBlock != null && _lastBlock.Item1 == ipAddress && _lastBlock.Item2 == permanentBlock && (now - _lastBlock.Item3) < TimeSpan.FromMinutes(1)) { // Already blocked this IP recently. return; } _lastBlock = new Tuple <string, bool, DateTime>(ipAddress, permanentBlock, now); var message = new CloudQueueMessage(CoreHelpers.Base64UrlEncodeString(ipAddress)); await _blockIpQueue.AddMessageAsync(message); if (!permanentBlock) { await _unblockIpQueue.AddMessageAsync(message, null, new TimeSpan(0, 15, 0), null, null); } }
public static HttpContext SetAuthEmail(this HttpContext context, string username) { context.Request.Headers.Add("Auth-Email", CoreHelpers.Base64UrlEncodeString(username)); return(context); }