| @@ -9,20 +9,21 @@ namespace Diligent.WebAPI.Business.Services | |||
| /// </summary> | |||
| public class Emailer : IEmailer | |||
| { | |||
| private readonly AuthorizationSettings _settings; | |||
| private readonly MailSettings _settings; | |||
| public Emailer() | |||
| public Emailer(IOptions<MailSettings> mailSettings) | |||
| { | |||
| _settings = new AuthorizationSettings | |||
| { | |||
| SmtpServer = "smtp.mailtrap.io", | |||
| SmtpPort = 2525, | |||
| SmtpUseSSL = true, | |||
| SmtpUsername = "460e3c49f02e37", | |||
| SmtpPassword = "66443869eaad55", | |||
| SmtpFrom = "noreply@hrcenter.net", | |||
| SmtpFromName = "HRCenter Team" | |||
| }; | |||
| _settings = mailSettings.Value; | |||
| //_settings = new AuthorizationSettings | |||
| //{ | |||
| // SmtpServer = "smtp.mailtrap.io", | |||
| // SmtpPort = 2525, | |||
| // SmtpUseSSL = true, | |||
| // SmtpUsername = "460e3c49f02e37", | |||
| // SmtpPassword = "66443869eaad55", | |||
| // SmtpFrom = "noreply@hrcenter.net", | |||
| // SmtpFromName = "HRCenter Team" | |||
| //}; | |||
| } | |||
| /// <summary> | |||
| @@ -19,6 +19,8 @@ namespace Diligent.WebAPI.Business.Services | |||
| private readonly DatabaseContext _databaseContext; | |||
| private readonly IEmailer _emailer; | |||
| private readonly ILogger<UserService> _logger; | |||
| private const string GoogleApiTokenInfoUrl = "https://www.googleapis.com/oauth2/v3/tokeninfo?id_token={0}"; | |||
| private string[] SupportedClientsIds = { "" }; | |||
| public UserService(IOptions<AuthorizationSettings> authSettings, UserManager<User> userManager, IMapper mapper, DatabaseContext databaseContext, IEmailer emailer, ILogger<UserService> logger) | |||
| { | |||
| @@ -43,8 +45,6 @@ namespace Diligent.WebAPI.Business.Services | |||
| await _userManager.CreateAsync(user, model.Password); | |||
| } | |||
| private const string GoogleApiTokenInfoUrl = "https://www.googleapis.com/oauth2/v3/tokeninfo?id_token={0}"; | |||
| private string[] SupportedClientsIds = { "734219382849-nvnulsu7ibfl4bk3n164bgb7c1h5dgca.apps.googleusercontent.com" }; | |||
| private bool IsTokenValid(string providerToken) | |||
| { | |||
| var httpClient = new HttpClient(); | |||
| @@ -68,7 +68,8 @@ namespace Diligent.WebAPI.Business.Services | |||
| var response = httpResponseMessage.Content.ReadAsStringAsync().Result; | |||
| var googleApiTokenInfo = JsonConvert.DeserializeObject<GoogleApiTokenInfo>(response); | |||
| if (!SupportedClientsIds.Contains(googleApiTokenInfo.aud)) | |||
| //if (!SupportedClientsIds.Contains(googleApiTokenInfo.aud)) | |||
| if(googleApiTokenInfo.aud != _authSettings.GoogleClientId) | |||
| { | |||
| return false; | |||
| } | |||
| @@ -5,17 +5,8 @@ namespace Diligent.WebAPI.Business.Settings | |||
| public class AuthorizationSettings | |||
| { | |||
| public string Secret { get; set; } | |||
| public int JwtExpiredTime { get; set; } | |||
| public int JwtRefreshExpiredTime { get; set; } | |||
| public string SmtpFrom { get; set; } | |||
| public string SmtpFromName { get; set; } | |||
| public string SmtpServer { get; set; } | |||
| public int SmtpPort { get; set; } | |||
| public bool SmtpUseSSL { get; set; } | |||
| public string SmtpUsername { get; set; } | |||
| public string SmtpPassword { get; set; } | |||
| public string ResetPasswordUrl { get; set; } | |||
| public string GoogleClientId { get; set; } | |||
| } | |||
| } | |||
| @@ -0,0 +1,14 @@ | |||
| namespace Diligent.WebAPI.Business.Settings | |||
| { | |||
| public class MailSettings | |||
| { | |||
| public string SmtpFrom { get; set; } | |||
| public string SmtpFromName { get; set; } | |||
| public string SmtpServer { get; set; } | |||
| public int SmtpPort { get; set; } | |||
| public bool SmtpUseSSL { get; set; } | |||
| public string SmtpUsername { get; set; } | |||
| public string SmtpPassword { get; set; } | |||
| public string ResetPasswordUrl { get; set; } | |||
| } | |||
| } | |||
| @@ -7,5 +7,4 @@ | |||
| builder.Services.Configure<AuthorizationSettings>(builder.Configuration.GetSection("Authorization")); | |||
| builder.Services.AddScoped<IUserService, UserService>(); | |||
| } | |||
| } | |||
| } | |||
| }} | |||
| @@ -8,6 +8,7 @@ | |||
| public static void ConfigureHost(this WebApplicationBuilder builder) | |||
| { | |||
| builder.ConfigureCors(); | |||
| builder.ConfigureMailServer(); | |||
| builder.ConfigureAuth(); | |||
| builder.ConfigureIdentity(); | |||
| builder.ConfigureValidationMiddleware(); | |||
| @@ -0,0 +1,10 @@ | |||
| namespace Diligent.WebAPI.Host.Extensions | |||
| { | |||
| public static class MailServerConfigurationExtension | |||
| { | |||
| public static void ConfigureMailServer(this WebApplicationBuilder builder) | |||
| { | |||
| builder.Services.Configure<MailSettings>(builder.Configuration.GetSection("Mail")); | |||
| } | |||
| } | |||
| } | |||
| @@ -6,6 +6,9 @@ | |||
| "JwtExpiredTime": "5", | |||
| "JwtRefreshExpiredTime": "30", | |||
| "Secret": "SECRET_ASKGFH#$_#((Y)#I%EWJGDSJTGKEOS@$SAF", | |||
| "GoogleClientId": "734219382849-nvnulsu7ibfl4bk3n164bgb7c1h5dgca.apps.googleusercontent.com" | |||
| }, | |||
| "Mail": { | |||
| "SmtpServer": "smtp.mailtrap.io", | |||
| "SmtpPort": 2525, | |||
| "SmtpUseSSL": true, | |||
| @@ -5,6 +5,16 @@ | |||
| "Authorization": { | |||
| "JwtExpiredTime": "5", | |||
| "JwtRefreshExpiredTime": "30", | |||
| "Secret": "SECRET_ASKGFH#$_#((Y)#I%EWJGDSJTGKEOS@$SAF" | |||
| "Secret": "SECRET_ASKGFH#$_#((Y)#I%EWJGDSJTGKEOS@$SAF", | |||
| "GoogleClientId": "734219382849-nvnulsu7ibfl4bk3n164bgb7c1h5dgca.apps.googleusercontent.com" | |||
| }, | |||
| "Mail": { | |||
| "SmtpServer": "smtp.mailtrap.io", | |||
| "SmtpPort": 2525, | |||
| "SmtpUseSSL": true, | |||
| "SmtpUsername": "460e3c49f02e37", | |||
| "SmtpPassword": "66443869eaad55", | |||
| "SmtpFrom": "noreply@hrcenter.net", | |||
| "SmtpFromName": "HRCenter Team" | |||
| } | |||
| } | |||