|
@@ -1,5 +1,6 @@
|
|
using System.IdentityModel.Tokens.Jwt;
|
|
using System.IdentityModel.Tokens.Jwt;
|
|
using System.Reflection;
|
|
using System.Reflection;
|
|
|
|
+using System.Text;
|
|
using CallCenter.Api.Exceptions;
|
|
using CallCenter.Api.Exceptions;
|
|
using CallCenter.Api.Filters;
|
|
using CallCenter.Api.Filters;
|
|
using CallCenter.Api.Realtimes;
|
|
using CallCenter.Api.Realtimes;
|
|
@@ -22,6 +23,7 @@ using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
using Microsoft.IdentityModel.Tokens;
|
|
using Microsoft.IdentityModel.Tokens;
|
|
using Serilog;
|
|
using Serilog;
|
|
using CallCenter.Calls;
|
|
using CallCenter.Calls;
|
|
|
|
+using XF.Domain.Options;
|
|
|
|
|
|
namespace CallCenter.Api;
|
|
namespace CallCenter.Api;
|
|
|
|
|
|
@@ -60,22 +62,45 @@ internal static class StartupExtensions
|
|
// d.ClientScope = "identity.admin_api";
|
|
// d.ClientScope = "identity.admin_api";
|
|
// });
|
|
// });
|
|
|
|
|
|
- //JwtSecurityTokenHandler.DefaultMapInboundClaims = false;
|
|
|
|
- //services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
|
|
|
- // .AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, d =>
|
|
|
|
- // {
|
|
|
|
- // d.Authority = "http://identity.fengwo.com"; //todo
|
|
|
|
- // d.RequireHttpsMetadata = false;
|
|
|
|
- // d.TokenValidationParameters = new TokenValidationParameters
|
|
|
|
- // {
|
|
|
|
- // ValidateAudience = false
|
|
|
|
- // };
|
|
|
|
- // })
|
|
|
|
- // ;
|
|
|
|
|
|
+ services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
|
|
|
+ .AddJwtBearer(d =>
|
|
|
|
+ {
|
|
|
|
+ var jwtOptions = configuration.GetSection("IdentityConfiguration").Get<IdentityConfiguration>().Jwt;
|
|
|
|
+ byte[] bytes = Encoding.UTF8.GetBytes(jwtOptions.SecretKey);
|
|
|
|
+ var secKey = new SymmetricSecurityKey(bytes);
|
|
|
|
+ d.TokenValidationParameters = new()
|
|
|
|
+ {
|
|
|
|
+ ValidateIssuer = false,
|
|
|
|
+ ValidateAudience = false,
|
|
|
|
+ ValidateLifetime = true,
|
|
|
|
+ ValidateIssuerSigningKey = true,
|
|
|
|
+ IssuerSigningKey = secKey,
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ //d.Audience = "hotline_api";
|
|
|
|
+ d.Events = new JwtBearerEvents
|
|
|
|
+ {
|
|
|
|
+ OnMessageReceived = context =>
|
|
|
|
+ {
|
|
|
|
+ var accessToken = context.Request.Query["access_token"];
|
|
|
|
+
|
|
|
|
+ // If the request is for our hub...
|
|
|
|
+ var path = context.HttpContext.Request.Path;
|
|
|
|
+ if (!string.IsNullOrEmpty(accessToken) &&
|
|
|
|
+ (path.StartsWithSegments("/hubs/callcenter")))
|
|
|
|
+ {
|
|
|
|
+ // Read the token out of the query string
|
|
|
|
+ context.Token = accessToken;
|
|
|
|
+ }
|
|
|
|
+ return Task.CompletedTask;
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ })
|
|
|
|
+ ;
|
|
|
|
|
|
services.AddControllers(options =>
|
|
services.AddControllers(options =>
|
|
{
|
|
{
|
|
- options.Filters.Add<TempTokenFilter>();
|
|
|
|
|
|
+ //options.Filters.Add<TempTokenFilter>();
|
|
options.Filters.Add<UnifyResponseFilter>();
|
|
options.Filters.Add<UnifyResponseFilter>();
|
|
options.Filters.Add<UserFriendlyExceptionFilter>();
|
|
options.Filters.Add<UserFriendlyExceptionFilter>();
|
|
});
|
|
});
|
|
@@ -182,9 +207,9 @@ internal static class StartupExtensions
|
|
|
|
|
|
app.UseCors(CorsOrigins);
|
|
app.UseCors(CorsOrigins);
|
|
|
|
|
|
- //app.UseAuthentication();
|
|
|
|
|
|
+ app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
app.UseAuthorization();
|
|
- //app.MapHub<CallCenterHub>("/hubs/callcenter");
|
|
|
|
|
|
+ app.MapHub<CallCenterHub>("/hubs/callcenter");
|
|
//app.UseMiddleware<TempTokenMiddleware>();
|
|
//app.UseMiddleware<TempTokenMiddleware>();
|
|
|
|
|
|
app.MapControllers();
|
|
app.MapControllers();
|