Laravel 护照;使用 OAuth2 与 Freshdesk 进行 SSO

问题描述

我正在尝试设置从我的 Laravel 8.13 站点到我的相关 Freshdesk 支持门户的 SSO。

我想要的是一个登录到我的网站的用户,然后能够点击一个按钮并无缝登录到我的 Freshdesk 支持门户,以便他们可以查看那里的非公开文档并在需要时提出票.

使用 Laravel Passport 10.1 我可以创建一个令牌(使用 Postman 测试)但在尝试进行身份验证时收到来自 Freshdesk 的错误

An error occurred while attempting to retrieve the userinfo resource: Could not extract response: no 
suitable httpmessageconverter found for response type [java.util.map<java.lang.string,java.lang.object>] and content type [text/html;charset=utf-8]

我之前没有使用过 OAuth 并且遇到了问题。当然,我对 OAuth 的理解可能完全错误,但我发现很难找到有关 Laravel Passport / Freshdesk OAuth 连接的可用文档。

我已经解决了与我发现的一样多的相关 SO 问题,但到目前为止似乎没有完全适合我的问题。

我也收到了 Freshdesk 的公开票,并与 Freshdesk 支持成员进行了在线支持会议,但他们告诉我问题在我这边,他们无法提供进一步帮助。

我本以为要使用的客户端类型是个人访问客户端,但我已经尝试过这种方式以及密码授予客户端,并为两种客户端类型获得了相同的消息(如上)。

就 Freshdesk 上的“用户信息 URL*”字段而言,

Userinfo URL field

我试过了

http://testsite.ngrok.io/oauth/tokens
and
http://testsite.ngrok.io/oauth/personal-access-tokens
and 
http://testsite.ngrok.io/api/user

但没有运气 - 与上述未找到 userinfo 资源的消息相同。

如果我直接浏览

http://testsite.ngrok.io/oauth/personal-access-tokens

我得到以下返回:

[{"id":"e595f342722c1045e061f2f026fa7f07181b3d5c69016e9999c5640f1e65928ff6fe2621565ff666c5","user_id":43128,"client_id":7,"name":null,"scopes":"openid","email","profile"],"revoked":false,"created_at":"2021-01-26 10:16:12","updated_at":"2021-01-26 10:16:12","expires_at":"2022-01-26T10:16:12.000000Z","client": 
{"id":7,"user_id":null,"name":"freshworksPersonalAccessClient","provider":null,"redirect":"https:\/\/testsite.freshworks.com\/sp\/OAUTH\/27402945223480041\/callback","personal_access_client":true,"password_client":false,"created_at":"2021-01-19T23:19:39.000000Z","updated_at":"2021-01-19T23:19:39.000000Z"}}]

因此返回了一些东西,但我不确定这是否与 Freshdesk 正在寻找的东西相近。 Freshdesk支持文档指出:

enter image description here

但我不知道在哪里创建该信息或需要以何种格式将其发送到 Freshdesk。

我查看了 this question 并相信(即使它适用于旧版本)UserRepository.PHP 文件中“getUserEntityByUserCredentials”的代码中可能存在某些内容,但我已将记录器调用放入该函数中它似乎没有被调用

任何帮助都绝对很棒。如果需要任何进一步的信息,请告诉我。

虽然我更愿意将它保留在 Laravel 生态系统中,但我也愿意接受任何其他方式来设置 Freshdesk 的 SSO,而无需使用第三方身份提供商,如 ADFS、OneLogin、Okta、Azure 等。我只需要完成这件事。

解决方法

解决了。基本上我的问题是用户信息 URL 返回的格式和内容。

我为

设置了路线

/用户信息

到 TestController 中的函数。在该函数中,我解码了 Bearer 令牌以获取 user_id,然后使用它来检索用户详细信息。

然后我创建了一个数组和响应如下:

$thisDecodedUser = User::query()->findOrFail($thisDecodedUserId);

if ($thisDecodedUser) {
    $thisDecodedUserFirstName = $thisDecodedUser->first_name;
    $thisDecodedUserLastName = $thisDecodedUser->last_name;
    $thisDecodedUserEmail = $thisDecodedUser->email;
}


$user_info = array();
$user_info['sub'] = "$thisDecodedUserId";
$user_info['id'] = "$thisDecodedUserId";
$user_info['email'] = "$thisDecodedUserEmail";
$user_info['.id'] = "$thisDecodedUserId";
$user_info['.email'] = "$thisDecodedUserEmail";
$user_info['email_verified'] = "true";

return response(json_encode($user_info))
            ->withHeaders([
                'Content-Type' => 'application/json',]);

代码需要重构,但至少现在可以使用。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...