gpt4 book ai didi

azure - 无法使用 OpenIDConnect 从 AAD 的 HttpContext 获取访问 token

转载 作者:行者123 更新时间:2023-12-03 00:06:28 25 4
gpt4 key购买 nike

我已使用 Azure AD 配置 Open ID Connect。我希望从 AAD 检索 access_token。目前我只能检索 id_token。我已将我的 Azure Active Directory 应用程序注册配置为包含 access_token 和 id_token。

我已将我的 Azure Active Directory 应用程序注册配置为包含 access_token 和 id_token。我也尝试过从 header 中检索 token ,但没有任何运气。

Startup.cs

services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
.AddAzureAD(options => Configuration.Bind("AzureAD", options));
services.Configure<OpenIdConnectOptions>(AzureADDefaults.OpenIdScheme, options =>
{
options.Authority = options.Authority + "/v2.0/";
options.TokenValidationParameters.ValidateIssuer = true;
options.ResponseType = OpenIdConnectResponseType.CodeIdToken;
options.SaveTokens = true;
});

MyController.cs

if(User.Identity.IsAuthenticated)
{
string accessToken = await HttpContext.GetTokenAsync("access_token");
string idToken = await HttpContext.GetTokenAsync("id_token");
}

appsettings.json

"AzureAd": {
"Instance": "https://login.microsoftonline.com/",
"Domain": "mydomain",
"TenantId": "organizations",
"ClientId": "myclientid",
"ClientSecret": "myclientsecret",
"CallbackPath": "/signin-oidc",
"SignedOutCallbackPath ": "/signout-callback-oidc"
}

最佳答案

根据 documentation,您将需要使用 CodeIdTokenToken 响应类型。

options.ResponseType = OpenIdConnectResponseType.CodeIdTokenToken;

关于azure - 无法使用 OpenIDConnect 从 AAD 的 HttpContext 获取访问 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56904800/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com