/// <summary> /// Initializes a new instance of the <see cref="AzureTokenAuthentication"/> class. /// </summary> /// <param name="msiAuth">The msi authentication.</param> /// <param name="azureAppRegistrationAuthority">Optionally specify an Azure App Registration to authenticate against. Defaults to "https://management.azure.com/"</param> public AzureTokenAuthentication(MsiAuth msiAuth, string azureAppRegistrationAuthority = null) { // Validate the certificate. msiAuth.ThrowIfInvalid(); _msiAuth = msiAuth; _azureAppRegistrationAuthority = azureAppRegistrationAuthority; Name = msiAuth.TenantId; }
/// <summary> /// Add an instance of IAuthentication for managed user identity authentication. /// </summary> /// <param name="services">The services to extend.</param> /// <param name="config">The managed identity authentication configuration to initialise with.</param> /// <param name="appRegistrationUrl">Optional parameter for an app registration url to authenticate against.</param> /// <returns>IServiceCollection.</returns> public static IServiceCollection AddAzureAuthSingleton(this IServiceCollection services, MsiAuth config, string appRegistrationUrl = null) { services.AddSingleton <IAuthentication>(new AzureTokenAuthentication(config, appRegistrationUrl)); AddFactoryIfNotAdded(services); return(services); }