26 lines
901 B
C#
26 lines
901 B
C#
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace Brizco.Identity.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"];
|
|
if (!string.IsNullOrEmpty(accessToken))
|
|
{
|
|
context.Token = accessToken;
|
|
}
|
|
}
|
|
};
|
|
}
|
|
}
|
|
} |