Authentication 获得;为';重定向uri';无效”;尝试获取访问令牌时出错

Authentication 获得;为';重定向uri';无效”;尝试获取访问令牌时出错,authentication,oauth-2.0,azure-active-directory,outlook-restapi,Authentication,Oauth 2.0,Azure Active Directory,Outlook Restapi,当我尝试获取令牌时,我得到错误: 为“重定向uri”提供的值无效。该值必须与用于获取授权代码的重定向URI完全匹配。 我的重定向uri完全匹配,所以我不明白为什么会发生这种情况 $TOKEN_ENDPOINT = 'https://login.microsoftonline.com/common/oauth2/v2.0/token'; $params = array( 'grant_type' => 'authorization_code'

当我尝试获取令牌时,我得到错误:

为“重定向uri”提供的值无效。该值必须与用于获取授权代码的重定向URI完全匹配。

我的重定向uri完全匹配,所以我不明白为什么会发生这种情况

$TOKEN_ENDPOINT         = 'https://login.microsoftonline.com/common/oauth2/v2.0/token';
$params = array(
    'grant_type'              => 'authorization_code',
    'code'                    => $azureCode,
    'clientId'                => '7c09ab71-***-****-****-53d7c4438112',
    'clientSecret'            => 'bnot*******20*[',
    'redirect_uri'            => 'https://testing.****.com/outlookOauthCallback.php',
    'urlAuthorize'            => $AUTHORIZATION_ENDPOINT,
    'urlAccessToken'          => $TOKEN_ENDPOINT,
    'urlResourceOwnerDetails' => '',
    'scope'                   => 'Calendars.ReadWrite User.Read'
);
$response = $client->getAccessToken($TOKEN_ENDPOINT, 'authorization_code', $params);

(相信我,我变成星星的部分完全一样,因为我复制粘贴)

即使在我返回参数的响应中,也完全相同:

Array
(
    [grant_type] => authorization_code
    [code] => M51b1b*****-daeec54627b2
    [clientId] => 7c09ab71-a*****d7c4438112
    [clientSecret] => bnotxds&*&QB***cVLF20*[
    [redirect_uri] => https://testing.****.com/outlookOauthCallback.php
    [urlAuthorize] => https://login.microsoftonline.com/common/oauth2/v2.0/authorize
    [urlAccessToken] => https://login.microsoftonline.com/common/oauth2/v2.0/token
    [urlResourceOwnerDetails] => 
    [scope] => Calendars.ReadWrite User.Read
)

那它怎么还能给我这个错误呢?这里缺少什么?

您需要在请求url中指定重定向uri。差不多

var href = 'login.microsoftonline.com/common/oauth2/…'; href += client_id + '&resource=webdir.online.lync.com&redirect_uri=' + window.location.href; 

如果确保相同,可以尝试添加尾部斜杠
https://testing.****.com/outlookOauthCallback.php/
。您可以尝试http,***.com/outlookOauthCallback.phpvar href='';href+=client_id+'&resource='+window.location.href;window.location.href=href;请求url中的重定向uri是什么?问题是我没有在请求url中指定重定向uri。谢谢你,如果你将它作为一个答案张贴我会接受it@SinanSamet很高兴听到你的问题已经解决了。我补充了答案。