2016-03-07 183 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