0

我需要创建架构扩展。如何代表用户使用appid连接azure广告?

遵循如下: https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/schemaextension_post_schemaextensions

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; 
    } 

令牌:

"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: 请求体必须包含以下参数: 'client_secret或client_assertion'

回答

0

你没有得到,因为你的委托权限正在使用客户端凭据授权进行身份验证。您本质上是应用程序的身份验证,因此没有用户参与。

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

尤其是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); 
+0

尝试过,获得跟随错误请求主体必须继续ain以下参数: 'client_secret或client_assertion' –

相关问题