zhaolei
8 days ago 4a2e5b9a21940f11757be37d99f0944e240e908b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using Prow.TencentAuth;
using Microsoft.AspNetCore.Authentication;
using Microsoft.Extensions.Configuration;
using System;
 
namespace Microsoft.Extensions.DependencyInjection
{
    /// <summary>
    /// Gitee 授权认证服务扩展类
    /// </summary>
    public static class TencentExtensions
    {
        /// <summary>
        /// 添加 Gitee 认证授权服务
        /// </summary>
        /// <param name="builder">认证实例</param>
        /// <param name="configureOptions">GiteeAuthenticationOptions 权限配置项回调方法</param>
        /// <returns>AuthenticationBuilder 实例</returns>
        public static AuthenticationBuilder AddTencent(this AuthenticationBuilder builder, Action<TencentOptions>? configureOptions = null) => builder.AddTencent(TencentDefaults.AuthenticationScheme, TencentDefaults.DisplayName, configureOptions);
 
        /// <summary>
        /// 添加 Gitee 认证授权服务
        /// </summary>
        /// <param name="builder">认证实例</param>
        /// <param name="authenticationScheme">Gitee 认证架构名称 默认值为 Gitee</param>
        /// <param name="configureOptions">GiteeAuthenticationOptions 权限配置项回调方法</param>
        /// <returns>AuthenticationBuilder 实例</returns>
        public static AuthenticationBuilder AddTencent(this AuthenticationBuilder builder, string authenticationScheme, Action<TencentOptions>? configureOptions = null) => builder.AddTencent(authenticationScheme, TencentDefaults.DisplayName, configureOptions);
 
        /// <summary>
        /// 添加 Gitee 认证授权服务
        /// </summary>
        /// <param name="builder">认证实例</param>
        /// <param name="authenticationScheme">Gitee 认证架构名称 默认值为 Gitee</param>
        /// <param name="displayName">Gitee 显示名称 默认值为 Gitee</param>
        /// <param name="configureOptions">GiteeAuthenticationOptions 权限配置项回调方法</param>
        /// <returns>AuthenticationBuilder 实例</returns>
        public static AuthenticationBuilder AddTencent(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action<TencentOptions>? configureOptions)
        {
            var config = builder.Services.BuildServiceProvider().GetRequiredService<IConfiguration>();
            builder.Services.Configure<TencentOptions>(authenticationScheme, config.GetSection(nameof(TencentOptions)));
            return OAuthExtensions.AddOAuth<TencentOptions, TencentHandler>(builder, authenticationScheme, displayName, configureOptions);
        }
    }
}