mirror of
https://github.com/bitwarden/mobile
synced 2025-12-28 06:03:40 +00:00
identity server client for auth
This commit is contained in:
29
src/App/Utilities/IdentityHttpClient.cs
Normal file
29
src/App/Utilities/IdentityHttpClient.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System.Net.Http;
|
||||
using System;
|
||||
using System.Net.Http.Headers;
|
||||
|
||||
namespace Bit.App
|
||||
{
|
||||
public class IdentityHttpClient : HttpClient
|
||||
{
|
||||
public IdentityHttpClient()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
public IdentityHttpClient(HttpMessageHandler handler)
|
||||
: base(handler)
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
private void Init()
|
||||
{
|
||||
//BaseAddress = new Uri("http://169.254.80.80:33656"); // Desktop from VS Android Emulator
|
||||
//BaseAddress = new Uri("http://192.168.1.8:33656"); // Desktop
|
||||
//BaseAddress = new Uri("https://identity-api.bitwarden.com"); // Preview
|
||||
BaseAddress = new Uri("https://api.bitwarden.com"); // Production
|
||||
DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,9 +12,23 @@ namespace Bit.App
|
||||
{
|
||||
var tokenService = Resolver.Resolve<ITokenService>();
|
||||
var appIdService = Resolver.Resolve<IAppIdService>();
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(tokenService.Token))
|
||||
{
|
||||
Headers.Add("Authorization", $"Bearer2 {tokenService.Token}");
|
||||
var httpService = Resolver.Resolve<IHttpService>();
|
||||
|
||||
var bearerString = "Bearer";
|
||||
var tokenIssuer = tokenService.TokenIssuer;
|
||||
if(tokenIssuer == httpService.ApiClient.BaseAddress.OriginalString)
|
||||
{
|
||||
bearerString = string.Concat(bearerString, "2");
|
||||
}
|
||||
else if(tokenIssuer == httpService.IdentityClient.BaseAddress.OriginalString)
|
||||
{
|
||||
bearerString = string.Concat(bearerString, "3");
|
||||
}
|
||||
|
||||
Headers.Add("Authorization", $"{bearerString} {tokenService.Token}");
|
||||
}
|
||||
if(!string.IsNullOrWhiteSpace(appIdService.AppId))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user