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' –

相關問題