diff --git a/Core.Thalos.Provider/Providers/BaseProvider.cs b/Core.Thalos.Provider/Providers/BaseProvider.cs deleted file mode 100644 index a8e7bd6..0000000 --- a/Core.Thalos.Provider/Providers/BaseProvider.cs +++ /dev/null @@ -1,16 +0,0 @@ -using MongoDB.Driver; - -namespace Core.Thalos.Provider.Providers -{ - public class BaseProvider - { - private readonly IMongoDatabase _database; - - public BaseProvider(IMongoDatabase database) - { - _database = database ?? throw new ArgumentNullException(nameof(database)); - } - - protected IMongoDatabase Database => _database; - } -} \ No newline at end of file diff --git a/Core.Thalos.Provider/Providers/HeathOidcCallback.cs b/Core.Thalos.Provider/Providers/HeathOidcCallback.cs deleted file mode 100644 index ecd46f0..0000000 --- a/Core.Thalos.Provider/Providers/HeathOidcCallback.cs +++ /dev/null @@ -1,99 +0,0 @@ -using Azure.Core; -using Azure.Identity; -using Core.Thalos.Adapters.Common.Constants; -using MongoDB.Driver.Authentication.Oidc; - -namespace Core.Thalos.Provider.Providers -{ - public class HeathOidcCallback : IOidcCallback - { - private readonly string _audience; - private readonly string _environment; - public HeathOidcCallback(string audience) - { - _audience = audience; - _environment = Environment.GetEnvironmentVariable(EnvironmentVariables.Stage) ?? string.Empty; - } - - public OidcAccessToken GetOidcAccessToken(OidcCallbackParameters parameters, CancellationToken cancellationToken) - { - try - { - AccessToken token; - - TokenRequestContext tokenRequestContext = - new TokenRequestContext( - new[] { _audience } - ); - - if (_environment == "Local") - { - token = - new ChainedTokenCredential( - new ManagedIdentityCredential(), - new VisualStudioCredential(), - new VisualStudioCodeCredential(), - new SharedTokenCacheCredential() - ) - .GetToken( - tokenRequestContext - ); - } - else - { - token = - new ManagedIdentityCredential() - .GetToken( - tokenRequestContext - ); - } - - return new(token.Token, expiresIn: null); - } - catch (Exception ex) - { - - throw new Exception($"An error ocurred while trying to get the OIDC token to connect to the database, ERROR: {ex.Message}"); - } - } - - public async Task GetOidcAccessTokenAsync(OidcCallbackParameters parameters, CancellationToken cancellationToken) - { - try - { - TokenRequestContext tokenRequestContext = - new TokenRequestContext( - new[] { _audience } - ); - - AccessToken token; - - if (_environment == "Local") - { - token = await new ChainedTokenCredential( - new ManagedIdentityCredential(), - new VisualStudioCredential(), - new VisualStudioCodeCredential(), - new SharedTokenCacheCredential() - ) - .GetTokenAsync( - tokenRequestContext, cancellationToken - ).ConfigureAwait(false); - } - else - { - token = await new ManagedIdentityCredential() - .GetTokenAsync( - tokenRequestContext, cancellationToken - ).ConfigureAwait(false); - } - - return new(token.Token, expiresIn: null); - } - catch (Exception ex) - { - throw new Exception($"An error ocurred while trying to get the OIDC token to connect to the database, ERROR: {ex.Message}"); - } - } - } -}