如何为Azure AD多租户应用程序交换access_token的授权代码?

时间:2014-09-12 10:52:17

标签: azure oauth oauth-2.0 microsoft-dynamics

我正在编写一个Web应用程序,它将访问存储在Microsoft Dynamics CRM Online中的客户端数据。我希望允许我的用户使用OAuth授予对其Dynamics帐户的访问权限。

  1. 我在Azure AD中创建了一个多租户应用程序,提供了redirect_uris,生成了一个客户端ID&秘密。 Multi-tennant设置为ON。
  2. 我创建了一个演示Microsoft Dynamics CRM帐户。 “examplecrmaccount.crm4.dynamics.com”。
  3. 我已成功生成授权网址,将用户发送到授权屏幕,并收到应交换为“访问令牌”的“代码”。
  4. 我无法将此“代码”替换为“access_token”。

    $data = array(
        "grant_type" => "authorization_code", 
        "client_id" => urlencode("my_app_azure_ad_client_id"),
        "redirect_uri" => urlencode("https://myapp.com/callback"),
        "client_secret" => urlencode("my_app_azure_ad_client_secret"), 
        "code" => urlencode("code_returned_from_previous_request"),
        "resource" => urlencode("https://examplecrmaccount4.crm4.dynamics.com")
    );
    
    $endpoint = "https://login.windows.net/common/oauth2/token?api-version=1.0";
    
    $response = helpers\Curl::doPOST(
        $endpoint,
        null,    
        array("Content-type: application/x-www-form-urlencoded"),
        $data
    );
    

    服务器响应:

    Status 404
    StatusName Not Found
    {"error":"invalid_request","error_description":"ACS90002: No service namespace named \u0027common\u0027 was found in the data store.\r\nTrace ID: b1025082-3e9b-49d8-bf91-7d998f694162\r\nCorrelation ID: 49d9d1e5-6958-4ffc-91ff-464f078a00f5\r\nTimestamp: 2014-09-12 08:35:59Z","error_codes":[90002],"timestamp":"2014-09-12 08:35:59Z","trace_id":"b1025082-3e9b-49d8-bf91-7d998f694162","correlation_id":"49d9d1e5-6958-4ffc-91ff-464f078a00f5"}
    

1 个答案:

答案 0 :(得分:2)

删除“api-version = 1.0”查询参数,它应该可以工作。这是我们的文档和Azure门户中的一个错误,它告诉您在使用授权代码流时添加它。

相关问题