mirror of
https://github.com/bitwarden/directory-connector
synced 2025-12-19 09:43:15 +00:00
azure directory service implementation w/ config
This commit is contained in:
33
src/Core/Utilities/AzureAuthenticationProvider.cs
Normal file
33
src/Core/Utilities/AzureAuthenticationProvider.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Bit.Core.Services;
|
||||
using Microsoft.Graph;
|
||||
using Microsoft.IdentityModel.Clients.ActiveDirectory;
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bit.Core.Utilities
|
||||
{
|
||||
public class AzureAuthenticationProvider : IAuthenticationProvider
|
||||
{
|
||||
public async Task AuthenticateRequestAsync(HttpRequestMessage request)
|
||||
{
|
||||
if(SettingsService.Instance.Server?.Azure == null)
|
||||
{
|
||||
throw new ApplicationException("No server configuration.");
|
||||
}
|
||||
|
||||
var authContext = new AuthenticationContext(
|
||||
$"https://login.windows.net/{SettingsService.Instance.Server.Azure.Tenant}/oauth2/token");
|
||||
var creds = new ClientCredential(SettingsService.Instance.Server.Azure.Id,
|
||||
SettingsService.Instance.Server.Azure.Secret.DecryptToString());
|
||||
var authResult = await authContext.AcquireTokenAsync("https://graph.microsoft.com/", creds);
|
||||
request.Headers.Add("Authorization", $"Bearer {authResult.AccessToken}");
|
||||
}
|
||||
|
||||
// ref: https://github.com/AzureAD/azure-activedirectory-library-for-dotnet/issues/511
|
||||
private static void SomeMethodToLinkPlatform()
|
||||
{
|
||||
var creds = new UserPasswordCredential("user", "pass");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user