-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
base: master
Are you sure you want to change the base?
Conversation
Thanks! |
@@ -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" { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
No description provided.