|
@@ -227,6 +227,20 @@ builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
|
ClockSkew = TimeSpan.FromSeconds(30), //过期时间容错值,解决服务器端时间不同步问题(秒)
|
|
ClockSkew = TimeSpan.FromSeconds(30), //过期时间容错值,解决服务器端时间不同步问题(秒)
|
|
RequireExpirationTime = true,
|
|
RequireExpirationTime = true,
|
|
};
|
|
};
|
|
|
|
+ options.Events = new JwtBearerEvents
|
|
|
|
+ {
|
|
|
|
+ OnMessageReceived = context =>
|
|
|
|
+ {
|
|
|
|
+ // 当我们收到消息时,去获取请求中的access_token字段
|
|
|
|
+ var accessToken = context.Request.Query["access_token"];
|
|
|
|
+ // 如果没有就去头上找,找到了就放入我们context.token中
|
|
|
|
+ if (!string.IsNullOrEmpty(accessToken))
|
|
|
|
+ {
|
|
|
|
+ context.Token = accessToken;
|
|
|
|
+ }
|
|
|
|
+ return Task.CompletedTask;
|
|
|
|
+ }
|
|
|
|
+ };
|
|
});
|
|
});
|
|
#endregion
|
|
#endregion
|
|
|
|
|