mirror of
https://github.com/bitwarden/directory-connector
synced 2025-12-05 23:53:21 +00:00
get profile api
This commit is contained in:
@@ -49,15 +49,19 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Enums\OrganizationUserType.cs" />
|
||||
<Compile Include="Enums\OrganizationUserStatusType.cs" />
|
||||
<Compile Include="Models\ApiError.cs" />
|
||||
<Compile Include="Models\ApiResult.cs" />
|
||||
<Compile Include="Models\Entry.cs" />
|
||||
<Compile Include="Models\ImportRequest.cs" />
|
||||
<Compile Include="Models\ProfileOrganizationResponse.cs" />
|
||||
<Compile Include="Models\ServerConfiguration.cs" />
|
||||
<Compile Include="Models\LoginResult.cs" />
|
||||
<Compile Include="Models\ErrorResponse.cs" />
|
||||
<Compile Include="Models\EncryptedData.cs" />
|
||||
<Compile Include="Models\TokenRequest.cs" />
|
||||
<Compile Include="Models\ProfileResponse.cs" />
|
||||
<Compile Include="Models\TokenResponse.cs" />
|
||||
<Compile Include="Services\ApiService.cs" />
|
||||
<Compile Include="Services\SettingsService.cs" />
|
||||
|
||||
15
src/Core/Enums/OrganizationUserStatusType.cs
Normal file
15
src/Core/Enums/OrganizationUserStatusType.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bit.Core.Enums
|
||||
{
|
||||
public enum OrganizationUserStatusType : byte
|
||||
{
|
||||
Invited = 0,
|
||||
Accepted = 1,
|
||||
Confirmed = 2
|
||||
}
|
||||
}
|
||||
15
src/Core/Enums/OrganizationUserType.cs
Normal file
15
src/Core/Enums/OrganizationUserType.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bit.Core.Enums
|
||||
{
|
||||
public enum OrganizationUserType : byte
|
||||
{
|
||||
Owner = 0,
|
||||
Admin = 1,
|
||||
User = 2
|
||||
}
|
||||
}
|
||||
20
src/Core/Models/ProfileOrganizationResponse.cs
Normal file
20
src/Core/Models/ProfileOrganizationResponse.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Bit.Core.Enums;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bit.Core.Models
|
||||
{
|
||||
public class ProfileOrganizationResponseModel
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Key { get; set; }
|
||||
public OrganizationUserStatusType Status { get; set; }
|
||||
public OrganizationUserType Type { get; set; }
|
||||
public bool Enabled { get; set; }
|
||||
}
|
||||
}
|
||||
20
src/Core/Models/ProfileResponse.cs
Normal file
20
src/Core/Models/ProfileResponse.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bit.Core.Models
|
||||
{
|
||||
public class ProfileResponse
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Email { get; set; }
|
||||
public string MasterPasswordHint { get; set; }
|
||||
public string Culture { get; set; }
|
||||
public bool TwoFactorEnabled { get; set; }
|
||||
public IEnumerable<ProfileOrganizationResponseModel> Organizations { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -111,7 +111,7 @@ namespace Bit.Core.Services
|
||||
{
|
||||
return await HandleErrorAsync(response).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
|
||||
return ApiResult.Success(response.StatusCode);
|
||||
}
|
||||
catch
|
||||
@@ -120,6 +120,40 @@ namespace Bit.Core.Services
|
||||
}
|
||||
}
|
||||
|
||||
public virtual async Task<ApiResult<ProfileResponse>> GetProfileAsync()
|
||||
{
|
||||
var tokenStateResponse = await HandleTokenStateAsync<ProfileResponse>();
|
||||
if(!tokenStateResponse.Succeeded)
|
||||
{
|
||||
return tokenStateResponse;
|
||||
}
|
||||
|
||||
var requestMessage = new HttpRequestMessage()
|
||||
{
|
||||
Method = HttpMethod.Get,
|
||||
RequestUri = new Uri(ApiClient.BaseAddress, "accounts/profile"),
|
||||
};
|
||||
|
||||
requestMessage.Headers.Add("Authorization", $"Bearer3 {TokenService.Instance.AccessToken}");
|
||||
|
||||
try
|
||||
{
|
||||
var response = await ApiClient.SendAsync(requestMessage).ConfigureAwait(false);
|
||||
if(!response.IsSuccessStatusCode)
|
||||
{
|
||||
return await HandleErrorAsync<ProfileResponse>(response).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||
var responseObj = JsonConvert.DeserializeObject<ProfileResponse>(responseContent);
|
||||
return ApiResult<ProfileResponse>.Success(responseObj, response.StatusCode);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return HandledWebException<ProfileResponse>();
|
||||
}
|
||||
}
|
||||
|
||||
protected ApiResult HandledWebException()
|
||||
{
|
||||
return ApiResult.Failed(HttpStatusCode.BadGateway,
|
||||
|
||||
Reference in New Issue
Block a user