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

feat: Telegram Widget Login #957

Closed
wants to merge 1 commit into from
Closed

Conversation

dysf888
Copy link
Member

@dysf888 dysf888 commented Jan 14, 2025

No description provided.

@dysf888 dysf888 requested a review from uubulb January 14, 2025 11:40
@uubulb
Copy link
Contributor

uubulb commented Jan 14, 2025

Thanks!
Adding Telegram authorization would be appreciated, but it may lead to confusion as Telegram does not use standard OAuth 2.0 protocol.
@naiba What's your opinion on this?

@@ -52,7 +56,10 @@ func oauth2redirect(c *gin.Context) (*model.Oauth2LoginResponse, error) {
return nil, singleton.Localizer.ErrorT("provider not found")
}
o2conf := o2confRaw.Setup(getRedirectURL(c))

if provider == "Telegram" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the configuration name shouldn't be used to determine the behavior.
Maybe we can consider a more reliable way like a option in the config.

}

// 验证 Telegram Hash数据
if valid, err := verifyTelegramAuth(queryParams, o2confRaw.ClientID); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the err here is always nil, so returning a single bool value would be sufficient.

@@ -117,6 +124,69 @@ func unbindOauth2(c *gin.Context) (any, error) {
// @Router /api/v1/oauth2/callback [get]
func oauth2callback(jwtConfig *jwt.GinJWTMiddleware) func(c *gin.Context) (any, error) {
return func(c *gin.Context) (any, error) {
// 通过判断请求参数来确定是否是 Telegram 回调
if c.Query("id") != "" && c.Query("auth_date") != "" && c.Query("hash") != "" {
queryParams := make(map[string]string)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can directly access the specific query values here and store them in a string slice, as using the Query here would require extra maintenance like filtering and sorting.

c.Redirect(http.StatusFound, "/dashboard/login?oauth2=true")
}

return nil, errNoop
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should move the Telegram authorization code to another handler instead of the OAuth 2.0 one, as they use different values and steps.

@naiba
Copy link
Member

naiba commented Jan 19, 2025

单独弄一下好点

@naiba naiba marked this pull request as draft January 19, 2025 13:20
@uubulb
Copy link
Contributor

uubulb commented Jan 23, 2025

还准备做吗?现在我感觉对于软件来说直接集成 Telegram 验证不是太好,可以自己 fork 搞下 或者搞个代理
毕竟这块功能也不是核心,支持一个通用的 OAuth 2.0 应该足够了,而 TG 用的自己的协议 做进去不可避免地增加复杂度

@dysf888
Copy link
Member Author

dysf888 commented Jan 23, 2025

还准备做吗?现在我感觉对于软件来说直接集成 Telegram 验证不是太好,可以自己 fork 搞下 或者搞个代理 毕竟这块功能也不是核心,支持一个通用的 OAuth 2.0 应该足够了,而 TG 用的自己的协议 做进去不可避免地增加复杂度

感觉是不太好,得大改,在fork自用,最近比较忙 等以后有需求大了再改吧 :)

@dysf888 dysf888 closed this Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants