繁体   English   中英

Azure AD 身份验证问题 - 承载令牌仅返回应用程序信息

[英]Problem with Azure AD authentication - Bearer token returns only app information

我在为我的网站实施 Azure AD SSO 时遇到问题。

Azure AD 配置使用证书而不是机密。 一切看起来都正常,但https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token返回一个只包含应用程序信息的不记名令牌,我正在尝试获取用户的用户信息谁登录了。

谁能给我一些信息和提示如何获取用户信息?

获取 Bearer 令牌的代码:

public function getAccessToken(){
    $link = "https://login.microsoftonline.com/{$this->tenantId}/oauth2/v2.0/token";
    $request_headers = array(
        'Accept: application/x-www-form-urlencoded'
    );
    $post_data = array(
        "client_id" => $this->clientId,
        "grant_type" => "client_credentials",
        "client_assertion_type" => "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
        "client_assertion" => $this->jwToken,
        "scope" => "https://graph.microsoft.com/.default",
        "code" => $this->responseCode,
        "redirect_uri" => $this->redirectUri,
    );
    $curlResponse = $this->sendCURLRequest($link, $request_headers, $post_data);
    var_export($curlResponse);
}

正如@juunas 建议的那样,您应该使用授权代码流而不是客户端凭据流

现在您已经从请求授权代码中获得了code ,接下来您需要为访问令牌兑换代码

POST /{tenant}/oauth2/v2.0/token HTTP/1.1
Host: https://login.microsoftonline.com
Content-Type: application/x-www-form-urlencoded

client_id=6731de76-14a6-49ae-97bc-6eba6914391e
&scope=https%3A%2F%2Fgraph.microsoft.com%2Fmail.read
&code=OAAABAAAAiL9Kn2Z27UubvWFPbm0gLWQJVzCTE9UkP3pSx1aXxUjq3n8b2JRLk4OxVXr...
&redirect_uri=http%3A%2F%2Flocalhost%2Fmyapp%2F
&grant_type=authorization_code
&code_verifier=ThisIsntRandomButItNeedsToBe43CharactersLong 
&client_secret=JqQX2PNo9bpM0uEihUPzyrh    // NOTE: Only required for web apps. This secret needs to be URL-Encoded.

您使用的是Client credentials flow get token ,您不需要code

暂无
暂无

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

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