简体   繁体   English

尝试获取访问令牌请求Azure AD时为invalid_grant

[英]invalid_grant while trying to get the Access token request Azure AD

I am trying to get the access token from Azure Ad as explained the below link. 我正在尝试从Azure广告获取访问令牌,如下面的链接所述。 I need to use the office 365 REST API. 我需要使用Office 365 REST API。

msdn.microsoft.com/en-us/library/azure/dn645542.aspx

Authorization code request is successfull and i am getting the code in return URL. 授权代码请求成功,我正在返回URL中获取代码。 But the Access token request is failing and the response i am getting as below. 但是访问令牌请求失败,响应如下。

stdClass Object
(
    [error] => invalid_grant
    [error_description] => AADSTS70002: Error validating credentials. AADSTS70000: The provided access grant is invalid or malformed.
Trace ID: baf9f98a-655d-48e1-bc30-021a7d57effa
Correlation ID: 5030b57f-42e2-403a-ab3c-cfc970d886e2
Timestamp: 2015-04-21 12:58:00Z
    [error_codes] => Array
        (
            [0] => 70002
            [1] => 70000
        )

    [timestamp] => 2015-04-21 12:58:00Z
    [trace_id] => baf9f98a-655d-48e1-bc30-021a7d57effa
    [correlation_id] => 5030b57f-42e2-403a-ab3c-cfc970d886e2
    [submit_url] => 
    [context] => 
)

Below is my code: 下面是我的代码:

$url = "https://login.windows.net/<tenant-id>/oauth2/token";
            $postUrlData = "grant_type=authorization_code&client_id=$clientId&code=$authCode&redirect_uri=$redirectUri&client_secret=$secretKey";
            $headers = array(
                'Content-type: application/x-www-form-urlencoded',
                'Content-length: '. strlen($postUrlData)
            );
            //echo $postUrlData;die;
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS , $postUrlData);
            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            $result = curl_exec($ch);            
            $res = json_decode($result);            
            curl_close($ch);

Can you please tell me what am i doing wrong? 你能告诉我我在做什么错吗?

Take a look at this PHP sample: https://github.com/jasonjoh/php-calendar . 看一下这个PHP示例: https : //github.com/jasonjoh/php-calendar Specifically, look at the getTokenFromAuthCode function in https://github.com/jasonjoh/php-calendar/blob/master/o365/Office365Service.php . 具体来说,请查看https://github.com/jasonjoh/php-calendar/blob/master/o365/Office365Service.php中的getTokenFromAuthCode函数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 invalid_grant试图从PayPal获取OpenID Connect令牌 - invalid_grant trying to get OpenID Connect token from PayPal Docusign PHP 在尝试获取令牌时获取“invalid_grant: unsupported_grant_type”(JWT 身份验证) - Docusign PHP getting “invalid_grant: unsupported_grant_type” when trying to get token (JWT auth) 错误“invalid_grant / 无效的 JWT 签名”。 使用 Oauth 获取访问令牌 - Error "invalid_grant / Invalid JWT Signature." to get the access token using Oauth 无法使用php sdk获取soundcloud access_token。 invalid_grant错误 - Can't get soundcloud access_token using php sdk. invalid_grant error PHP Google API OAuth2 JWT 对新访问令牌的请求显示“invalid_grant” - PHP Google API OAuth2 JWT request for new acces token says “invalid_grant” 消息“获取OAuth2访问令牌时出错,消息:&#39;invalid_grant”的未捕获异常&#39;apiAuthException&#39; - Uncaught exception 'apiAuthException' with message 'Error fetching OAuth2 access token, message: 'invalid_grant'' Google_Auth_Exception&#39;,消息为&#39;获取 OAuth2 访问令牌时出错,消息:&#39;invalid_grant&#39; - Google_Auth_Exception' with message 'Error fetching OAuth2 access token, message: 'invalid_grant' “错误”:“invalid_grant”,“error_description”:“错误请求”当我尝试使用 gmail 登录时 - "error": "invalid_grant", "error_description": "Bad Request" when i am trying to login with gmail 尝试获取eBay用户访问令牌时出现“无效请求”。 没有给出具体的错误号 - “Invalid Request” while trying to get eBay user Access Token. No specific error number given Google异常错误,刷新令牌错误:invalid_grant - Google exception error refreshing token error : invalid_grant
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM