2016-03-07 180 views
1

如何從Azure AD使用php檢索身份驗證聯繫信息(用於註冊的電話號碼)? Azure API的新手,需要簡單介紹一下嗎?檢索身份驗證信息Azure AD

+0

你是什麼意思「用於註冊的電話號碼」? Azure AD中用戶的所有屬性都列在https://graph.microsoft.io/en-us/docs/api-reference/v1.0/resources/user,我們需要針對REST API對請求進行身份驗證信息。 –

+0

這裏是一個PHP示例,您可以嘗試按照https://github.com/OfficeDev/O365-PHP-Microsoft-Graph-Connect –

回答

2

您可以使用Azure AD Graph API公開發送HTTP請求的REST端點以執行操作。

要執行使用Graph API的操作,需要將HTTP請求發送到目標服務,資源集合,單個資源,資源的導航屬性或服務公開的函數或操作的端點。端點表示爲網址:

https://graph.windows.net/{tenant_id}/{resource_path}?{api_version}

以下組件構成的網址:

  • 服務根:所有圖形API請求服務根https://graph.windows.net
  • 租戶標識{tenant_id}:請求所針對的租戶的標識。
  • 資源路徑{resource_path}:請求所針對的資源路徑(例如,用戶或組)。
  • 圖形API版本{api_version}:請求所針對的圖形API版本。這被表示爲查詢參數並且是必需的。

請參閱Azure AD Graph API operations overview

至於如何處理PHP中的HTTP請求,經常使用PHP buildin file_get_contents,第三方庫文件cURLPECL_HTTP

@Aram提供了一個例子PECL_HTTP,你可以谷歌其他兩個。

2

您可以撥打電話到圖形API使用此端點,以獲取用戶的細節信息:

https://graph.windows.net/myorganization/users/garthf%40a830edad9050849NDA1.onmicrosoft.com?api-version=1.6 

下面是一個簡單的PHP,你可以使用:

<?php 

// This sample uses the pecl_http package. (for more information: http://pecl.php.net/package/pecl_http) 
require_once 'HTTP/Request2.php'; 
$headers = array(
); 

$query_params = array(
    // Specify values for the following required parameters 
    'api-version' => '1.6', 
); 

$request = new Http_Request2('https://graph.windows.net/myorganization/users/{user_id}'); 
$request->setMethod(HTTP_Request2::METHOD_GET); 
$request->setHeader($headers); 

// OAuth2 is required to access this API. For more information visit: 
// https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks 

$url = $request->getUrl(); 
$url->setQueryVariables($query_params); 

try 
{ 
    $response = $request->send(); 

    echo $response->getBody(); 
} 
catch (HttpException $ex) 
{ 
    echo $ex; 
} 

?> 

有關完整的API文檔和示例見下面的鏈接:

https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#getauser

+0

嗨@Aram,我可以從中檢索身份驗證信息嗎? –

+0

@PushpenderSharma你的認證信息是什麼意思?您將獲得保存在租戶中的用戶信息的詳細信息。 – Aram