【问题标题】:Retrieve Authentication Info Azure AD检索身份验证信息 Azure AD
【发布时间】:2016-03-07 17:30:08
【问题描述】:

如何使用 php 从 Azure AD 检索身份验证联系信息(用于注册的电话号码)? 刚接触 Azure API,需要简要介绍吗?

【问题讨论】:

标签: php azure active-directory ms-office office365


【解决方案1】:

您可以使用 Azure AD Graph API,它会公开您发送 HTTP 请求以执行操作的 REST 端点。

要使用 Graph API 执行操作,您需要向以服务、资源集合、单个资源、资源的导航属性或服务公开的函数或操作为目标的端点发送 HTTP 请求。端点表示为 URL:

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

以下组件构成 URL:

  • 服务根:所有 Graph API 请求的服务根是 https://graph.windows.net
  • 租户标识符 {tenant_id}: 请求所针对的租户的标识符。
  • 资源路径{resource_path}:请求所针对的资源路径(例如,用户或组)。
  • Graph API 版本 {api_version}: 请求所针对的 Graph API 的版本。这表示为查询参数并且是必需的。

请参阅Azure AD Graph API operations overview

关于PHP中如何处理HTTP请求,PHP内置file_get_contents,第三方库cURLPECL_HTTP常用。

@Aram 提供了一个带有PECL_HTTP 的示例,您可以搜索其他两个示例。

【讨论】:

    【解决方案2】:

    您可以使用此端点调用 Graph 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

    【讨论】:

    • 嗨@Aram,我也可以从中检索身份验证信息吗?
    • @PushpenderSharma 你所说的身份验证信息是什么意思?您将获得租户中保存的用户信息的详细信息。
    猜你喜欢
    • 1970-01-01
    • 2019-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-26
    • 2019-10-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多