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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

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.

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.

2 participants