23 lines
771 B
C#
23 lines
771 B
C#
using Microsoft.Extensions.Options;
|
|
|
|
namespace NetinaShop.Api.WebFramework.Configurations;
|
|
|
|
public class ConfigureJwtBearerOptions : IPostConfigureOptions<JwtBearerOptions>
|
|
{
|
|
public void PostConfigure(string name, JwtBearerOptions options)
|
|
{
|
|
var originalOnMessageReceived = options.Events.OnMessageReceived;
|
|
options.Events.OnMessageReceived = async context =>
|
|
{
|
|
await originalOnMessageReceived(context);
|
|
|
|
if (string.IsNullOrEmpty(context.Token))
|
|
{
|
|
var accessToken = context.Request.Query["access_token"];
|
|
var path = context.HttpContext.Request.Path;
|
|
|
|
if (!string.IsNullOrEmpty(accessToken)) context.Token = accessToken;
|
|
}
|
|
};
|
|
}
|
|
} |