gpt4 book ai didi

c# - 如何解决错误 AADSTS7000218 : The request body must contain the following parameter: 'client_secret' or 'client_assertion'

转载 作者:太空狗 更新时间:2023-10-29 18:26:29 26 4
gpt4 key购买 nike

这就是我编写代码并尝试获取输出的方式。

The request body must contain the following parameter: client_secret or client_assertion

 static async Task<AuthenticationResult> getAccessToken()
{
string hardcodedUsername = "";
string hardcodedPassword = "";
string tenantName = "projectwidgets.com";
string authString = "https://login.microsoftonline.com/" + tenantName;
AuthenticationContext authenticationContext = new AuthenticationContext(authString, false);
//Config for OAuth client credentials
string clientId = "as";
string key = "kk";
string authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenantName);
var authContext = new AuthenticationContext(authority);
AuthenticationResult result = null;
try
{
result = await authContext.AcquireTokenAsync("https://pwsnapitazure.azurewebsites.net", clientId, new UserPasswordCredential(hardcodedUsername, hardcodedPassword));
}
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace);
System.Diagnostics.Debug.WriteLine(ex.Message);
}
return result;
}

最佳答案

由于 Azure 应用程序注册 UI 已从旧身份验证更改,您将需要启用一个名为“将应用程序视为公共(public)客户端”的附加设置。在默认客户端类型下,将此设置设置为:

screenshot of AAD App Registration showing "Treat application as a public client" set to "yes" under the 'Default client type' subsection of the 'Advanced Settings' section

Manifest 中,您也可以通过设置来控制它:

"allowPublicClient": true

2022 年更新:

UI 名称更改为 Allow public client flows

enter image description here

关于c# - 如何解决错误 AADSTS7000218 : The request body must contain the following parameter: 'client_secret' or 'client_assertion' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45609432/

26 4 0