mirror of
https://github.com/bitwarden/server.git
synced 2025-04-06 21:48:12 -05:00

* Revert "Add git blame entry (#2226)" This reverts commit 239286737d15cb84a893703ee5a8b33a2d67ad3d. * Revert "Turn on file scoped namespaces (#2225)" This reverts commit 34fb4cca2aa78deb84d4cbc359992a7c6bba7ea5.
47 lines
1.9 KiB
C#
47 lines
1.9 KiB
C#
using System.Net.Http.Json;
|
|
using System.Text.Json;
|
|
using Bit.Core.Enums;
|
|
using Bit.Core.Models.Api.Request.Accounts;
|
|
using Bit.Core.Utilities;
|
|
using Bit.Identity;
|
|
using Bit.Test.Common.Helpers;
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
namespace Bit.IntegrationTestCommon.Factories
|
|
{
|
|
public class IdentityApplicationFactory : WebApplicationFactoryBase<Startup>
|
|
{
|
|
public const string DefaultDeviceIdentifier = "92b9d953-b9b6-4eaf-9d3e-11d57144dfeb";
|
|
|
|
public async Task<HttpContext> RegisterAsync(RegisterRequestModel model)
|
|
{
|
|
return await Server.PostAsync("/accounts/register", JsonContent.Create(model));
|
|
}
|
|
|
|
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());
|
|
}
|
|
}
|
|
}
|