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

时间:2017-07-15 10:53:52

标签: azure azure-active-directory microsoft-graph adal azure-ad-b2c

我需要创建架构扩展。

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

enter image description here

代码是:

ggplot(dfr,aes(x,y))+
  geom_point()+
  theme(axis.title=element_blank(),
        axis.ticks=element_blank(),
        axis.text.x=element_text(margin = margin(t = 20)),
        axis.text.y=element_text(margin = margin(r = 20)))

令牌:

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

未获取:Directory.AccessAsUser.All

用户凭据:

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

错误:

AADSTS70002: 请求正文必须包含以下参数: ' client_secret或client_assertion'

2 个答案:

答案 0 :(得分:0)

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

您需要使用其他方式进行身份验证。在GitHub上查看this sample

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

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
    <title>Word</title>
</head>
<body>

<form method="post" action="">

<?php
include("connect.php");
mysqli_query($link,"SET NAMES UTF8");


$select="SELECT * FROM students_info WHERE  bash='A'";

$result=mysqli_query($link,$select) or die(mysql_error());

while($row=mysqli_fetch_array($result))
{

    echo $row['Name']."<input type='text' name='warzy1'>"."<br>";
} 

?>

<input type="submit" name="submit" value="Save">

</form>

</body>
</html>

<?php
include("connect.php");
mysqli_query($link,"SET NAMES UTF8");

$warzy1=@$_POST['warzy1'];
$warz=implode(",",(array)$warzy1);

$insert="INSERT INTO word (Warzy_Yakam) VALUES ('$warz')";

mysqli_query($link,$insert) or die(mysqli_error($link));

?>

答案 1 :(得分:0)

找到解决方案如下:

How to authenticate Azure Service Management Requests via AAD

在Azure门户中创建应用程序时,应将“应用程序类型”更改为“NATIVE CLIENT APPLICATION”