mirror of
https://github.com/bitwarden/android.git
synced 2024-12-25 10:28:28 +03:00
Client & Version headers (#1757)
This commit is contained in:
parent
10fafaf8c8
commit
427ff09af0
5 changed files with 48 additions and 6 deletions
|
@ -116,7 +116,7 @@ namespace Bit.App.Pages
|
|||
var redirectUri = "bitwarden://sso-callback";
|
||||
|
||||
var url = _apiService.IdentityBaseUrl + "/connect/authorize?" +
|
||||
"client_id=" + _platformUtilsService.IdentityClientId + "&" +
|
||||
"client_id=" + _platformUtilsService.GetClientType().GetString() + "&" +
|
||||
"redirect_uri=" + Uri.EscapeDataString(redirectUri) + "&" +
|
||||
"response_type=code&scope=api%20offline_access&" +
|
||||
"state=" + state + "&code_challenge=" + codeChallenge + "&" +
|
||||
|
|
|
@ -5,6 +5,7 @@ using Bit.App.Abstractions;
|
|||
using Bit.App.Models;
|
||||
using Bit.App.Resources;
|
||||
using Bit.Core.Abstractions;
|
||||
using Bit.Core.Enums;
|
||||
using Plugin.Fingerprint;
|
||||
using Plugin.Fingerprint.Abstractions;
|
||||
using Xamarin.Essentials;
|
||||
|
@ -35,8 +36,6 @@ namespace Bit.App.Services
|
|||
_broadcasterService = broadcasterService;
|
||||
}
|
||||
|
||||
public string IdentityClientId => "mobile";
|
||||
|
||||
public void Init()
|
||||
{
|
||||
_broadcasterService.Subscribe(nameof(MobilePlatformUtilsService), (message) =>
|
||||
|
@ -80,6 +79,11 @@ namespace Bit.App.Services
|
|||
return DeviceInfo.Model;
|
||||
}
|
||||
|
||||
public ClientType GetClientType()
|
||||
{
|
||||
return ClientType.Mobile;
|
||||
}
|
||||
|
||||
public bool IsViewOpen()
|
||||
{
|
||||
return false;
|
||||
|
|
|
@ -7,11 +7,10 @@ namespace Bit.Core.Abstractions
|
|||
{
|
||||
public interface IPlatformUtilsService
|
||||
{
|
||||
string IdentityClientId { get; }
|
||||
|
||||
string GetApplicationVersion();
|
||||
DeviceType GetDevice();
|
||||
string GetDeviceString();
|
||||
ClientType GetClientType();
|
||||
bool IsDev();
|
||||
bool IsSelfHost();
|
||||
bool IsViewOpen();
|
||||
|
|
36
src/Core/Enums/ClientType.cs
Normal file
36
src/Core/Enums/ClientType.cs
Normal file
|
@ -0,0 +1,36 @@
|
|||
namespace Bit.Core.Enums
|
||||
{
|
||||
public enum ClientType: byte
|
||||
{
|
||||
Web = 1,
|
||||
Browser = 2,
|
||||
Desktop = 3,
|
||||
Mobile = 4,
|
||||
Cli = 5,
|
||||
DirectoryConnector = 6,
|
||||
}
|
||||
|
||||
public static class ClientTypeExtensions
|
||||
{
|
||||
public static string GetString(this ClientType me)
|
||||
{
|
||||
switch (me)
|
||||
{
|
||||
case ClientType.Web:
|
||||
return "web";
|
||||
case ClientType.Browser:
|
||||
return "browser";
|
||||
case ClientType.Desktop:
|
||||
return "desktop";
|
||||
case ClientType.Mobile:
|
||||
return "mobile";
|
||||
case ClientType.Cli:
|
||||
return "cli";
|
||||
case ClientType.DirectoryConnector:
|
||||
return "connector";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
using Bit.Core.Abstractions;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Exceptions;
|
||||
using Bit.Core.Models.Domain;
|
||||
using Bit.Core.Models.Request;
|
||||
|
@ -37,6 +38,8 @@ namespace Bit.Core.Services
|
|||
_logoutCallbackAsync = logoutCallbackAsync;
|
||||
var device = (int)_platformUtilsService.GetDevice();
|
||||
_httpClient.DefaultRequestHeaders.Add("Device-Type", device.ToString());
|
||||
_httpClient.DefaultRequestHeaders.Add("Bitwarden-Client-Name", _platformUtilsService.GetClientType().GetString());
|
||||
_httpClient.DefaultRequestHeaders.Add("Bitwarden-Client-Version", _platformUtilsService.GetApplicationVersion());
|
||||
if (!string.IsNullOrWhiteSpace(customUserAgent))
|
||||
{
|
||||
_httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(customUserAgent);
|
||||
|
@ -87,7 +90,7 @@ namespace Bit.Core.Services
|
|||
Version = new Version(1, 0),
|
||||
RequestUri = new Uri(string.Concat(IdentityBaseUrl, "/connect/token")),
|
||||
Method = HttpMethod.Post,
|
||||
Content = new FormUrlEncodedContent(request.ToIdentityToken(_platformUtilsService.IdentityClientId))
|
||||
Content = new FormUrlEncodedContent(request.ToIdentityToken(_platformUtilsService.GetClientType().GetString()))
|
||||
};
|
||||
requestMessage.Headers.Add("Accept", "application/json");
|
||||
request.AlterIdentityTokenHeaders(requestMessage.Headers);
|
||||
|
|
Loading…
Reference in a new issue