AWS无服务器Lambda上的.NetCore3.1中的OktaSDK错误
创始人
2024-09-27 20:30:43
0

在 AWS 无服务器 Lambda 上,使用 .Net Core 3.1 时,如果在代码中使用了 Okta SDK,可能会出现以下错误消息:System.TypeInitializationException: The type initializer for 'System.Net.Http.CurlHandler' threw an exception. 这是因为在 .Net Core 3.1 上,不再使用 curl 库,但 Okta SDK 还在使用它。因此,需要手动设置 Okta SDK 的 HttpClient,以使用 dotnetty-transport 对 curl 库进行兼容处理。

以下是解决方法的代码示例:

在 Startup.cs 中注册 OktaConfiguration:

services.AddSingleton(new OktaConfiguration() { BaseUrl = configuration["Okta:Domain"], ApiToken = configuration["Okta:ApiToken"], UseClientCredentialsGrantType = true });

更改 Okta 的 HttpClient:

public class OktaHttpClientFactory : IOktaHttpClientFactory { private readonly ILogger _logger;

public OktaHttpClientFactory(ILogger logger)
{
    _logger = logger;
}

public HttpClient GetHttpClient(IOktaConfiguration configuration)
{
    var httpClientHandler = new SocketsHttpHandler()
    {
        EnableMultipleHttp2Connections = true
    };

    var httpClient = new HttpClient(httpClientHandler)
    {
        BaseAddress = new Uri(configuration.BaseUrl),
        Timeout = TimeSpan.FromSeconds(30)
    };

    httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", configuration.ApiToken);

    return httpClient;
}

}

在 ConfigureServices 方法中,注册 OktaHttpClientFactory:

services.AddSingleton();

在使用 Okta SDK 的类中,注入 IOktaHttpClientFactory,并使用它来创建 OktaClient:

public class OktaClientTest { private readonly IOktaHttpClientFactory _httpClientFactory;

public OktaClientTest(IOktaHttpClientFactory httpClientFactory)
{
    _httpClientFactory = httpClientFactory;
}

public async Task Test()
{
    var configuration = new OktaConfiguration()
    {
        BaseUrl = "https://your-tenant.okta.com",
        ApiToken = "your-api-token",
        UseClient

相关内容

热门资讯

玩家必看分享!wepoker透... 玩家必看分享!wepoker透视挂底牌(辅助挂)果然是真的有挂(真的有挂辅助app)1、在插件功能辅...
安装程序教程!wepoker私... 安装程序教程!wepoker私人局辅助挂(辅助挂)确实有挂(有挂辅助辅助教程)1、让任何用户在无需安...
玩家爆料!拱趴大菠萝万能辅助器... 玩家爆料!拱趴大菠萝万能辅助器(辅助挂)本来是有挂(有挂规律辅助攻略)1、很好的工具软件,可以解锁游...
今日头条!wepokerplu... 今日头条!wepokerplus外挂(辅助挂)确实有挂(有挂技巧辅助脚本)1、完成辅助器v3.3的残...
记者发布!fishpoker透... 记者发布!fishpoker透视底牌(辅助挂)切实是真的有挂(有挂方法辅助教程)1. 选牌创建新账号...
查到实测!aapoker脚本怎... 查到实测!aapoker脚本怎么用(辅助挂)果然是有挂(揭秘有挂辅助技巧)1. 选牌创建新账号,点击...
传递经验!wepoker轻量版... 传递经验!wepoker轻量版透视系统(辅助挂)其实存在有挂(有挂功能辅助软件)1、下载好正确养号方...
查到实测!红龙poker辅助器... 查到实测!红龙poker辅助器免费观看(辅助挂)都是是有挂(确实有挂辅助攻略)1、下载好脚本下载之后...
重大消息!wepoker怎么设... 重大消息!wepoker怎么设置房间(辅助挂)都是存在有挂(有挂秘笈辅助教程)1、不需要AI权限,帮...
必看攻略!wepoker私人局... 必看攻略!wepoker私人局辅助挂(辅助挂)确实有挂(有挂实锤辅助器)1、公共底牌简单,透视插件操...