mirror of
https://gitee.com/ThingsGateway/ThingsGateway.git
synced 2025-11-02 08:33:59 +08:00
41 lines
1.0 KiB
C#
41 lines
1.0 KiB
C#
using Microsoft.AspNetCore.Authentication.OAuth;
|
|
|
|
using System.Text.Json;
|
|
|
|
namespace ThingsGateway.Admin.Application;
|
|
|
|
/// <summary>OAuthOptions 配置类</summary>
|
|
public abstract class AdminOAuthOptions : OAuthOptions
|
|
{
|
|
/// <summary>默认构造函数</summary>
|
|
protected AdminOAuthOptions()
|
|
{
|
|
ConfigureClaims();
|
|
this.Events.OnRemoteFailure = context =>
|
|
{
|
|
var redirectUri = string.IsNullOrEmpty(HomePath) ? "/" : HomePath;
|
|
context.Response.Redirect(redirectUri);
|
|
context.HandleResponse();
|
|
return Task.CompletedTask;
|
|
};
|
|
|
|
|
|
}
|
|
|
|
/// <summary>配置 Claims 映射</summary>
|
|
protected virtual void ConfigureClaims()
|
|
{
|
|
|
|
}
|
|
|
|
public virtual string GetName(JsonElement element)
|
|
{
|
|
JsonElement.ObjectEnumerator target = element.EnumerateObject();
|
|
return target.TryGetValue("name");
|
|
}
|
|
|
|
/// <summary>获得/设置 登陆后首页</summary>
|
|
public string HomePath { get; set; } = "/";
|
|
|
|
}
|