gpt4 book ai didi

azure - 如何代表用户使用 appid 连接 Azure 广告?

转载 作者:行者123 更新时间:2023-12-03 04:24:37 27 4
gpt4 key购买 nike

我需要创建架构扩展。

如下: Create schemaExtension - Microsoft Graph v1.0 | Microsoft Docs

enter image description here

代码是:

  var authenticationContext = new AuthenticationContext(authString, false);     
ClientCredential clientCred = new ClientCredential(clientId, clientSecret);
AuthenticationResult authenticationResult = await authenticationContext.AcquireTokenAsync(resourceId, clientCred);
string token = authenticationResult.AccessToken;
var responseString = String.Empty;

using (var client = new HttpClient())
{

string requestUrl = "https://graph.microsoft.com/beta/schemaExtensions";
string postJson = "{\"id\":\"graphlearn_courses\",\"description\": \"Graph Learn training courses extensions\", \"targetTypes\":[\"Group\"], \"properties\": [{ \"name\": \"courseId\",\"type\": \"Integer\"}, {\"name\": \"courseName\",\"type\": \"String\"}, {\"name\": \"courseType\", \"type\": \"String\"}]}";

HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, requestUrl);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
request.Content = new StringContent(postJson, Encoding.UTF8, "application/json");
Debug.WriteLine(request.ToString());

HttpResponseMessage response = client.SendAsync(request).Result;
responseString = response.Content.ReadAsStringAsync().Result;
}

token :

"roles": [
"User.ReadWrite.All",
"Group.Read.All",
"Directory.ReadWrite.All",
"User.Read.All"
],

未获取:Directory.AccessAsUser.All

用户凭据:

  UserPasswordCredential userCred = new UserPasswordCredential(userId, userPassword);
var authenticationContext = new AuthenticationContext(authString, false);
ClientCredential clientCred = new ClientCredential(clientId, clientSecret);
AuthenticationResult authenticationResult = await authenticationContext.AcquireTokenAsync(resourceId, clientId, userCred);
string token = authenticationResult.AccessToken;

错误:

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

关于如何代表用户将 Azure 广告与 appid 连接有什么想法吗?

最佳答案

您没有获得委派权限,因为您正在使用客户端凭据授予进行身份验证。您本质上是作为应用程序进行身份验证,因此不涉及用户。

您将需要使用不同的方式进行身份验证。查看this sample在 GitHub 上。

特别是 AuthenticationHelper 类,它使用以下方式进行身份验证:

AuthenticationContext authenticationContext = new AuthenticationContext(UserModeConstants.AuthString, false);
AuthenticationResult userAuthnResult = await authenticationContext.AcquireTokenAsync(GlobalConstants.ResourceUrl,
UserModeConstants.ClientId, redirectUri, new PlatformParameters(PromptBehavior.RefreshSession));
TokenForUser = userAuthnResult.AccessToken;
Console.WriteLine("\n Welcome " + userAuthnResult.UserInfo.GivenName + " " +
userAuthnResult.UserInfo.FamilyName);

关于azure - 如何代表用户使用 appid 连接 Azure 广告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45117358/

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