Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 fix: support webhooks for logto #3774

Merged
merged 6 commits into from
Sep 12, 2024
Merged

Conversation

cy948
Copy link
Contributor

@cy948 cy948 commented Sep 5, 2024

💻 变更类型 | Change Type

  • ✨ feat
  • 🐛 fix
  • ♻️ refactor
  • 💄 style
  • 👷 build
  • ⚡️ perf
  • 📝 docs
  • 🔨 chore

🔀 变更说明 | Description of Change

  • src/app/api/webhooks/logto/validateRequest.ts: 按照Logto文档验证签名
  • src/app/api/webhooks/logto/route.ts: 处理Logto event。目前支持的 event 有:User.Data.Updated
  • src/app/api/webhooks/logto/__tests__/route.test.ts: 添加一个易于本地测试 webhook 的 test case。仅为local dev准备,ci时会跳过该 case。

close #3722

📝 补充信息 | Additional Information

  • 使用了 node:crypto,只能使用 node 环境运行;
  • 目前支持从 Logto Webhook 中读入头像,并不支持其他敏感信息的操作,如:邮箱 email、用户名 username;
  • 使用方式:
    • 从管理员面板/console/webhooks中创建一个webhook
    • 选择所需要的事件,目前支持:User.Data.Update
    • 配置 URL 为:https://<your_domain>/api/webhooks/logto
    • 找到 Signing Key,并将内容使用环境变量LOGTO_WEBHOOK_SIGNING_KEY传入
  • Local Dev 测试 Webhook 方式:
    • src/app/api/webhooks/logto/__tests__/route.test.ts: 将 describe.skip 替换为 describe,将userDataUpdatedEvent中的信息替换为测试数据;
    • 运行单元测试:
# Run at project root
pnpm vitest --run --testNamePattern='^ ?Test Logto Webhooks in Local dev'  src/app/api/webhooks/logto/__tests__/route.test.ts

麻烦 @zhuozhiyongde 大佬在文档里补充一下 logto 的webhook接入操作🥺。操作在上面的《使用方式》一栏了。

Copy link

vercel bot commented Sep 5, 2024

@cy948 is attempting to deploy a commit to the LobeHub Pro Team on Vercel.

A member of the Team first needs to authorize it.

@lobehubbot
Copy link
Member

👍 @cy948

Thank you for raising your pull request and contributing to our Community
Please make sure you have followed our contributing guidelines. We will review it as soon as possible.
If you encounter any problems, please feel free to connect with us.
非常感谢您提出拉取请求并为我们的社区做出贡献,请确保您已经遵循了我们的贡献指南,我们会尽快审查它。
如果您遇到任何问题,请随时与我们联系。

@cy948 cy948 marked this pull request as ready for review September 5, 2024 04:52
Copy link

codecov bot commented Sep 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.85%. Comparing base (66ce743) to head (7cd79b6).
Report is 31 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #3774    +/-   ##
========================================
  Coverage   91.85%   91.85%            
========================================
  Files         459      459            
  Lines       30759    30761     +2     
  Branches     2121     2963   +842     
========================================
+ Hits        28254    28256     +2     
  Misses       2505     2505            
Flag Coverage Δ
app 91.85% <100.00%> (+<0.01%) ⬆️
server 97.36% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Sep 5, 2024
@cy948 cy948 marked this pull request as draft September 5, 2024 04:52
@dosubot dosubot bot added the 🌠 Feature Request New feature or request | 特性与建议 label Sep 5, 2024
@Matinal111
Copy link

动作真快🤗

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


It’s so fast 🤗

@ZeroDeng01
Copy link

期待!!!!同时期待拥有一个logto的用户面板功能,没有用户面板的话用户修改密码等操作就无法在lobehub内完成,只能由logto管理员前往logto操作!

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Looking forward to it!!!! Also looking forward to having a logto user panel function. Without the user panel, operations such as changing passwords cannot be completed in lobehub. Logto administrators can only go to logto for operations!

@VectorZhao
Copy link
Contributor

行动确实很快

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Acts really fast

src/server/services/nextauthUser/index.ts Outdated Show resolved Hide resolved
src/server/services/nextauthUser/index.ts Outdated Show resolved Hide resolved
src/app/api/webhooks/logto/validateRequest.ts Show resolved Hide resolved
@arvinxx
Copy link
Contributor

arvinxx commented Sep 6, 2024

期待!!!!同时期待拥有一个logto的用户面板功能,没有用户面板的话用户修改密码等操作就无法在lobehub内完成,只能由logto管理员前往logto操作!

这个得看下 logto 有没有这个 UI 组件了

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Looking forward to it!!!! Also looking forward to having a logto user panel function. Without the user panel, operations such as changing passwords cannot be completed in lobehub. Logto administrators can only go to logto for operations!

This depends on whether logto has this UI component.

@cy948 cy948 marked this pull request as ready for review September 10, 2024 09:50
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Sep 10, 2024
@cy948 cy948 force-pushed the feat/logto-webhooks branch from 9c82fdd to 975ad53 Compare September 10, 2024 09:52
Copy link

vercel bot commented Sep 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lobe-chat-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 10, 2024 5:07pm

@Matinal111
Copy link

这个 PR 我看已经合并了,可以应用了吗

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


I see this PR has been merged. Can it be applied?

@arvinxx arvinxx changed the title ✨ feat: support webhooks for logto 🐛 fix: support webhooks for logto Sep 12, 2024
@arvinxx arvinxx merged commit 0cfee6b into lobehub:main Sep 12, 2024
5 of 7 checks passed
@lobehubbot
Copy link
Member

❤️ Great PR @cy948 ❤️

The growth of project is inseparable from user feedback and contribution, thanks for your contribution! If you are interesting with the lobehub developer community, please join our discord and then dm @arvinxx or @canisminor1990. They will invite you to our private developer channel. We are talking about the lobe-chat development or sharing ai newsletter around the world.
项目的成长离不开用户反馈和贡献,感谢您的贡献! 如果您对 LobeHub 开发者社区感兴趣,请加入我们的 discord,然后私信 @arvinxx@canisminor1990。他们会邀请您加入我们的私密开发者频道。我们将会讨论关于 Lobe Chat 的开发,分享和讨论全球范围内的 AI 消息。

github-actions bot pushed a commit that referenced this pull request Sep 12, 2024
### [Version&nbsp;1.16.11](v1.16.10...v1.16.11)
<sup>Released on **2024-09-12**</sup>

#### 🐛 Bug Fixes

- **misc**: Support webhooks for logto.

#### 💄 Styles

- **misc**: Default disable mistral provider useless models.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's fixed

* **misc**: Support webhooks for logto, closes [#3774](#3774) ([0cfee6b](0cfee6b))

#### Styles

* **misc**: Default disable mistral provider useless models, closes [#3922](#3922) ([bdbc647](bdbc647))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
@lobehubbot
Copy link
Member

🎉 This PR is included in version 1.16.11 🎉

The release is available on:

Your semantic-release bot 📦🚀

@cy948 cy948 deleted the feat/logto-webhooks branch September 12, 2024 14:29
@VectorZhao
Copy link
Contributor

具体如何使用,readme更新了吗

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


How to use it specifically? Has the readme been updated?

@cy948
Copy link
Contributor Author

cy948 commented Sep 12, 2024

@VectorZhao 简单文档在pr描述那里,图文的readme要等 @zhuozhiyongde 大佬有空再做。

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@VectorZhao The simple document is in the PR description, and the readme with pictures and text will have to wait until @zhuozhiyongde is free.

@VectorZhao
Copy link
Contributor

VectorZhao commented Sep 12, 2024

@VectorZhao 简单文档在pr描述那里,图文的readme要等 @zhuozhiyongde 大佬有空再做。

谢谢,试了一下,.env增加环境变量LOGTO_WEBHOOK_SIGNING_KEY

lobe web 中 退出账号,然后登录。logto的webhook的请求次数还是0.
image

@cy948
Copy link
Contributor Author

cy948 commented Sep 12, 2024

@VectorZhao 你说的这个hook不在实现范围内,目前只实现了用户信息更新。

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@VectorZhao The hook you mentioned is not within the scope of implementation. Currently, only user information update is implemented.

@VectorZhao
Copy link
Contributor

logto中创建了一个用户,lobe登录。logto修改了该用户的用户名,然后lobe退出再登录。目前的webhooks会更新用户名吗?我试了下lobe 退出再登录还是之前的用户名,没有更新成logto修改后的用户名

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


A user is created in logto, lobe logs in. logto modifies the user's username, then lobe logs out and logs in again. Will the current webhooks update the username? I tried lobe to log out and log in again, it was still the previous username, but it was not updated to the username modified by logto.

@cy948
Copy link
Contributor Author

cy948 commented Sep 12, 2024

@VectorZhao 只有 name email avatar 会更新,username 不在范围内。

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@VectorZhao Only name email avatar will be updated, username is not in the scope.

@VectorZhao
Copy link
Contributor

@VectorZhao 只有 name email avatar 会更新,username 不在范围内。

谢谢耐心解答,了解了

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@VectorZhao Only name email avatar will be updated, username is not in the range.

Thank you for your patience in answering, I understand.

github-actions bot pushed a commit to bentwnghk/lobe-chat that referenced this pull request Sep 13, 2024
## [Version&nbsp;1.60.0](v1.59.4...v1.60.0)
<sup>Released on **2024-09-13**</sup>

#### ♻ Code Refactoring

- **misc**: Support Environment Variable Inference For NextAuth.

#### ✨ Features

- **misc**: Support openai new OpenAI o1-preview/o1-mini models.

#### 🐛 Bug Fixes

- **misc**: Qwen model param error, support webhooks for logto.

#### 💄 Styles

- **model**: Remove `OpenAI` deprecated model.
- **misc**: Default disable mistral provider useless models, Remove brackets from model names with dates in OpenAI, Support Google Model List, Update siliconcloud model.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### Code refactoring

* **misc**: Support Environment Variable Inference For NextAuth, closes [lobehub#3701](https://github.com/bentwnghk/lobe-chat/issues/3701) ([b956755](b956755))

#### What's improved

* **misc**: Support openai new OpenAI o1-preview/o1-mini models, closes [lobehub#3943](https://github.com/bentwnghk/lobe-chat/issues/3943) ([61bfeb2](61bfeb2))

#### What's fixed

* **misc**: Qwen model param error, closes [lobehub#3902](https://github.com/bentwnghk/lobe-chat/issues/3902) ([c9f00e5](c9f00e5))
* **misc**: Support webhooks for logto, closes [lobehub#3774](https://github.com/bentwnghk/lobe-chat/issues/3774) ([0cfee6b](0cfee6b))

#### Styles

* **model**: Remove `OpenAI` deprecated model, closes [lobehub#3465](https://github.com/bentwnghk/lobe-chat/issues/3465) ([68a4fb2](68a4fb2))
* **misc**: Default disable mistral provider useless models, closes [lobehub#3922](https://github.com/bentwnghk/lobe-chat/issues/3922) ([bdbc647](bdbc647))
* **misc**: Remove brackets from model names with dates in OpenAI, closes [lobehub#3927](https://github.com/bentwnghk/lobe-chat/issues/3927) ([2a937bc](2a937bc))
* **misc**: Support Google Model List, closes [lobehub#3938](https://github.com/bentwnghk/lobe-chat/issues/3938) ([be4efc7](be4efc7))
* **misc**: Update siliconcloud model, closes [lobehub#3935](https://github.com/bentwnghk/lobe-chat/issues/3935) ([882e981](882e981))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
cy948 added a commit to cy948/lobe-chat that referenced this pull request Sep 21, 2024
* ✨ feat: support webhooks for logto

* :sparles: feat: update more info

* ♻️ refactor: allow edit more info by webhook

* ♻️ refactor: rename `nextauthUser` to `nextAuthUser`

* 🧪 test: + webhooks trigger

---------

Co-authored-by: Arvin Xu <arvinx@foxmail.com>
cy948 pushed a commit to cy948/lobe-chat that referenced this pull request Sep 21, 2024
### [Version&nbsp;1.16.11](lobehub/lobe-chat@v1.16.10...v1.16.11)
<sup>Released on **2024-09-12**</sup>

#### 🐛 Bug Fixes

- **misc**: Support webhooks for logto.

#### 💄 Styles

- **misc**: Default disable mistral provider useless models.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's fixed

* **misc**: Support webhooks for logto, closes [lobehub#3774](lobehub#3774) ([0cfee6b](lobehub@0cfee6b))

#### Styles

* **misc**: Default disable mistral provider useless models, closes [lobehub#3922](lobehub#3922) ([bdbc647](lobehub@bdbc647))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌠 Feature Request New feature or request | 特性与建议 released size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Request] Logto 是否可以配置 Webhook
6 participants