mirror of
https://github.com/bitwarden/directory-connector
synced 2026-01-07 02:53:24 +00:00
auth service and token service setup
This commit is contained in:
30
src/Core/AuthService.cs
Normal file
30
src/Core/AuthService.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bit.Core
|
||||
{
|
||||
public class AuthService
|
||||
{
|
||||
private static AuthService _instance;
|
||||
|
||||
private AuthService() { }
|
||||
|
||||
public static AuthService Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_instance == null)
|
||||
{
|
||||
_instance = new AuthService();
|
||||
}
|
||||
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Authenticated { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,7 @@
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.DirectoryServices" />
|
||||
<Reference Include="System.DirectoryServices.Protocols" />
|
||||
<Reference Include="System.Security" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
@@ -42,6 +43,8 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="TokenService.cs" />
|
||||
<Compile Include="AuthService.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
|
||||
55
src/Core/TokenService.cs
Normal file
55
src/Core/TokenService.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bit.Core
|
||||
{
|
||||
public class TokenService
|
||||
{
|
||||
private static TokenService _instance;
|
||||
|
||||
private TokenService() { }
|
||||
|
||||
public static TokenService Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_instance == null)
|
||||
{
|
||||
_instance = new TokenService();
|
||||
}
|
||||
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
public string AccessToken
|
||||
{
|
||||
get
|
||||
{
|
||||
// TODO: get bytes from disc
|
||||
var encBytes = new byte[0];
|
||||
var bytes = ProtectedData.Unprotect(encBytes, RandomEntropy(), DataProtectionScope.CurrentUser);
|
||||
return Convert.ToBase64String(bytes);
|
||||
}
|
||||
set
|
||||
{
|
||||
var bytes = Convert.FromBase64String(value);
|
||||
var encBytes = ProtectedData.Protect(bytes, RandomEntropy(), DataProtectionScope.CurrentUser);
|
||||
// TODO: store bytes to disc
|
||||
}
|
||||
}
|
||||
|
||||
public string RefreshToken { get; set; }
|
||||
|
||||
private byte[] RandomEntropy()
|
||||
{
|
||||
var entropy = new byte[16];
|
||||
new RNGCryptoServiceProvider().GetBytes(entropy);
|
||||
return entropy;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user