简体   繁体   中英

Retrieve Authentication Info Azure AD

How can I retrieve Authentication Contact Info (Phone Number used for registration) from Azure AD using php? New to Azure API's,need a brief on it?

You can make a call to Graph API to get the User details info using this endpoint:

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

Here is a sample PHP which you can use:

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

?>

For the complete API documentation and samples see below link:

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

You can use Azure AD Graph API which exposes REST endpoints that you send HTTP requests to in order to perform operations.

To perform operations with the Graph API, you send HTTP requests to an endpoint that targets the service, a resource collection, an individual resource, a navigation property of a resource, or a function or action exposed by the service. Endpoints are expressed as URLs:

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

The following components comprise the URL:

  • Service Root: The service root for all Graph API requests is https://graph.windows.net .
  • Tenant Identifier {tenant_id}: The identifier for the tenant that the request targets.
  • Resource path {resource_path}: The path to the resource -- for example, a user or a group -- that the request targets.
  • Graph API Version {api_version}: The version of the Graph API targeted by the request. This is expressed as a query parameter and is required.

Refer to Azure AD Graph API operations overview .

As for how to deal with HTTP request in PHP, PHP buildin file_get_contents , the third-party lib cURL and PECL_HTTP are often used.

@Aram has provided an example with PECL_HTTP and you can google the other two.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM