public EmailService(HttpClient httpClient, ILogger <EmailService> logger, ILoginConfig config) { _logger = logger; var notificationsApiClientConfiguration = new NotificationsApiClientConfiguration() { ApiBaseUrl = config.NotificationsApiClientConfiguration.ApiBaseUrl, #pragma warning disable 618 ClientToken = config.NotificationsApiClientConfiguration.ClientToken, #pragma warning restore 618 ClientId = config.NotificationsApiClientConfiguration.ClientId, ClientSecret = config.NotificationsApiClientConfiguration.ClientSecret, IdentifierUri = config.NotificationsApiClientConfiguration.IdentifierUri, Tenant = config.NotificationsApiClientConfiguration.Tenant, }; if (string.IsNullOrWhiteSpace(config.NotificationsApiClientConfiguration.ClientId)) { httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", config.NotificationsApiClientConfiguration.ClientToken); } else { var azureAdToken = new AzureADBearerTokenGenerator(notificationsApiClientConfiguration).Generate().Result; httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", azureAdToken); } _notificationApi = new NotificationsApi(httpClient, notificationsApiClientConfiguration); }
private static void RegisterDasNotifications(IServiceCollection services, IConfiguration configuration) { var notificationsConfig = new NotificationsApiClientConfiguration(); configuration.GetSection(nameof(NotificationsApiClientConfiguration)).Bind(notificationsConfig); var jwtToken = new JwtBearerTokenGenerator(notificationsConfig); var httpClient = new HttpClientBuilder() .WithBearerAuthorisationHeader(jwtToken) .WithDefaultHeaders() .Build(); services.AddTransient <INotificationsApi>(sp => new NotificationsApi(httpClient, notificationsConfig)); }
private static void SendEmail() { //var apiBaseUrl = "https://at-notifications.apprenticeships.sfa.bis.gov.uk/"; var apiBaseUrl = Configuration.NotificationsApiClientConfiguration.ApiBaseUrl; //var token = "<your token>"; var token = Configuration.NotificationsApiClientConfiguration.ClientToken; var config = new NotificationsApiClientConfiguration { ApiBaseUrl = apiBaseUrl, ClientToken = token }; IGenerateBearerToken jwtToken = new JwtBearerTokenGenerator(config); var httpClient = new HttpClientBuilder() .WithBearerAuthorisationHeader(jwtToken) .WithDefaultHeaders() .Build(); var apiClient = new NotificationsApi(httpClient, config); var recipients = Configuration.DefaultEmailAddress; var sender = Configuration.DefaultEmailSenderAddress; var replyTo = Configuration.DefaultEmailReplyToAddress; var customFields = new Dictionary <string, string> { { "UserEmailAddress", sender }, { "UserFullName", "Test User" }, { "UserEnquiry", "I have a question" }, { "UserEnquiryDetails", "Wanted to have different appSettings for debug and release when building your app ? " } }; var c = new Email { Tokens = customFields, RecipientsAddress = recipients, ReplyToAddress = replyTo, SystemId = "xyz", TemplateId = "VacancyService_CandidateContactUsMessage", Subject = "hello" }; apiClient.SendEmail(c).Wait(); }
public NotificationsRegistry() { var configuration = ConfigurationHelper.GetConfiguration(); INotificationsApiClientConfiguration clientConfiguration = new NotificationsApiClientConfiguration { ApiBaseUrl = configuration.NotificationsApiClientConfiguration.ApiBaseUrl, #pragma warning disable 618 ClientToken = configuration.NotificationsApiClientConfiguration.ClientToken, #pragma warning restore 618 ClientId = "", ClientSecret = "", IdentifierUri = "", Tenant = "" }; var httpClient = string.IsNullOrWhiteSpace(clientConfiguration.ClientId) ? new HttpClientBuilder().WithBearerAuthorisationHeader(new JwtBearerTokenGenerator(clientConfiguration)).Build() : new HttpClientBuilder().WithBearerAuthorisationHeader(new AzureADBearerTokenGenerator(clientConfiguration)).Build(); For <INotificationsApi>().Use <NotificationsApi>().Ctor <HttpClient>().Is(httpClient); For <INotificationsApiClientConfiguration>().Use(clientConfiguration); }
public NotificationsRegistry() { var configuration = ConfigurationHelper.GetConfiguration(); INotificationsApiClientConfiguration clientConfiguration = new NotificationsApiClientConfiguration { ApiBaseUrl = configuration.NotificationsApiClientConfiguration.ApiBaseUrl, ClientToken = configuration.NotificationsApiClientConfiguration.ClientToken, ClientId = "", ClientSecret = "", IdentifierUri = "", Tenant = "" }; //var config = ConfigurationHelper.GetConfiguration<Domain.Configuration.NotificationsApiClientConfiguration>($"{Constants.ServiceName}.Notifications"); var httpClient = string.IsNullOrWhiteSpace(clientConfiguration.ClientId) ? new HttpClientBuilder().WithBearerAuthorisationHeader(new JwtBearerTokenGenerator(clientConfiguration)).Build() : new HttpClientBuilder().WithBearerAuthorisationHeader(new AzureADBearerTokenGenerator(clientConfiguration)).Build(); For <INotificationsApi>().Use <NotificationsApi>().Ctor <HttpClient>().Is(httpClient); For <INotificationsApiClientConfiguration>().Use(clientConfiguration); }