u
This commit is contained in:
@@ -4,6 +4,7 @@ using FrontOffice.BFF.Infrastructure.Services;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
|
||||
namespace Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
@@ -12,6 +13,7 @@ public static class ConfigureServices
|
||||
public static IServiceCollection AddInfrastructureServices(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
services.AddSingleton<IApplicationContractContext, ApplicationContractContext>();
|
||||
services.AddSingleton<IKavenegarService, KavenegarService>();
|
||||
services.AddInfrastructureGrpcServices(configuration);
|
||||
#region AddAuthentication
|
||||
|
||||
@@ -19,11 +21,24 @@ public static class ConfigureServices
|
||||
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||
.AddJwtBearer(jwtBearerOptions =>
|
||||
{
|
||||
jwtBearerOptions.Authority = configuration["Authentication:Authority"];
|
||||
jwtBearerOptions.Audience = configuration["Authentication:Audience"];
|
||||
jwtBearerOptions.TokenValidationParameters.ValidateAudience = false;
|
||||
jwtBearerOptions.TokenValidationParameters.ValidateIssuer = true;
|
||||
jwtBearerOptions.TokenValidationParameters.ValidateIssuerSigningKey = false;
|
||||
//jwtBearerOptions.Authority = configuration["Authentication:Authority"];
|
||||
//jwtBearerOptions.Audience = configuration["Authentication:Audience"];
|
||||
//jwtBearerOptions.TokenValidationParameters.ValidateAudience = false;
|
||||
//jwtBearerOptions.TokenValidationParameters.ValidateIssuer = true;
|
||||
//jwtBearerOptions.TokenValidationParameters.ValidateIssuerSigningKey = false;
|
||||
|
||||
jwtBearerOptions.SaveToken = true;
|
||||
jwtBearerOptions.RequireHttpsMetadata = false;
|
||||
jwtBearerOptions.TokenValidationParameters = new TokenValidationParameters
|
||||
{
|
||||
ValidateIssuer = true,
|
||||
ValidateAudience = true,
|
||||
ValidateLifetime = true,
|
||||
ValidateIssuerSigningKey = true,
|
||||
ValidIssuer = configuration["JwtIssuer"],
|
||||
ValidAudience = configuration["JwtAudience"],
|
||||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["JwtSecurityKey"]))
|
||||
};
|
||||
try
|
||||
{
|
||||
jwtBearerOptions.Events = new JwtBearerEvents
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.54.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.0" />
|
||||
<PackageReference Include="KavenegarDotNetCore" Version="1.0.7" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
using CMSMicroservice.Protobuf.Protos.OtpToken;
|
||||
using CMSMicroservice.Protobuf.Protos.Package;
|
||||
using CMSMicroservice.Protobuf.Protos.User;
|
||||
using CMSMicroservice.Protobuf.Protos.UserAddress;
|
||||
using CMSMicroservice.Protobuf.Protos.UserOrder;
|
||||
using FrontOffice.BFF.Application.Common.Interfaces;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
@@ -7,7 +12,7 @@ public class ApplicationContractContext : IApplicationContractContext
|
||||
{
|
||||
#region members
|
||||
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -33,4 +38,15 @@ public class ApplicationContractContext : IApplicationContractContext
|
||||
|
||||
#endregion
|
||||
|
||||
#region CMS
|
||||
public PackageContract.PackageContractClient Package => GetService<PackageContract.PackageContractClient>();
|
||||
|
||||
public UserContract.UserContractClient User => GetService<UserContract.UserContractClient>();
|
||||
|
||||
public UserAddressContract.UserAddressContractClient UserAddress => GetService<UserAddressContract.UserAddressContractClient>();
|
||||
|
||||
public UserOrderContract.UserOrderContractClient UserOrder => GetService<UserOrderContract.UserOrderContractClient>();
|
||||
|
||||
public OtpTokenContract.OtpTokenContractClient OtpToken => GetService<OtpTokenContract.OtpTokenContractClient>();
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using FrontOffice.BFF.Application.Common.Interfaces;
|
||||
|
||||
namespace FrontOffice.BFF.Infrastructure.Services;
|
||||
public class KavenegarService : IKavenegarService
|
||||
{
|
||||
private Kavenegar.KavenegarApi _kavenegarApi;
|
||||
public KavenegarService()
|
||||
{
|
||||
_kavenegarApi = new Kavenegar.KavenegarApi("497263626F32626A48685A6137524C4F78575A766E4C74694A556B79317648424964655030682B554545413D");
|
||||
}
|
||||
public async Task Send(string mobile, string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _kavenegarApi.Send(sender: "1000001110100", receptor: mobile, message: message);
|
||||
}
|
||||
catch (Kavenegar.Core.Exceptions.ApiException ex)
|
||||
{
|
||||
// در صورتی که خروجی وب سرویس 200 نباشد این خطارخ می دهد.
|
||||
Console.Write("Message : " + ex.Message);
|
||||
}
|
||||
catch (Kavenegar.Core.Exceptions.HttpException ex)
|
||||
{
|
||||
// در زمانی که مشکلی در برقرای ارتباط با وب سرویس وجود داشته باشد این خطا رخ می دهد
|
||||
Console.Write("Message : " + ex.Message);
|
||||
}
|
||||
}
|
||||
public async Task VerifyLookup(string mobile, string token)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _kavenegarApi.VerifyLookup(receptor: mobile, token: token, template: "Afrino");
|
||||
}
|
||||
catch (Kavenegar.Core.Exceptions.ApiException ex)
|
||||
{
|
||||
// در صورتی که خروجی وب سرویس 200 نباشد این خطارخ می دهد.
|
||||
Console.Write("Message : " + ex.Message);
|
||||
}
|
||||
catch (Kavenegar.Core.Exceptions.HttpException ex)
|
||||
{
|
||||
// در زمانی که مشکلی در برقرای ارتباط با وب سرویس وجود داشته باشد این خطا رخ می دهد
|
||||
Console.Write("Message : " + ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user