gpt4 book ai didi

c# - 我正在寻找使用 c# 中的 azure 凭据生成访问 token

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

我正在寻找使用 c# 中的 azure 凭据生成访问 token 。这是我的代码,但它不起作用。有了这个我面临着意外的字符“<”错误。

        var uri = $"https://login.microsoftonline.com/common/oauth2/token";

var parameters = new Dictionary<string, dynamic>()
{
["grant_type"] = "password",
["client_id"] ="Azure client id"
["username"] = "CRM User name",
["password"] = "CRM Passowrd",
["client_secret"] ="Azure Client app scret"
["resource"] = "Your CRM Url",
};
var request = WebRequest.CreateHttp(uri);
request.Method = "POST";
var body = Encoding.ASCII.GetBytes(parameters.UrlEncode());

request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = body.Length;

using (var stream = request.GetRequestStream())
{
stream.Write(body, 0, body.Length);
}

using (var response = request.GetResponse())
using (var stream = response.GetResponseStream())
{
var serializer = new DataContractJsonSerializer(typeof(Token));
return serializer.ReadObject(stream) as Token;
}

最佳答案

以下是如何使用 postman 检索 crm token 的示例 <您可以在您的 C# 代码中应用它。但首先要做好这一点:

Postman token call

还要确保 Azure Active Directory > 应用程序具有上述回复 URL 和已分配的动态安全性(API 权限)。 Api permissions

关于c# - 我正在寻找使用 c# 中的 azure 凭据生成访问 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64532593/

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