mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-10 13:45:44 +08:00
Go: fix auth issue in hybrid mode (#14611)
### What problem does this PR solve? Since secret key get and set logic is updated, the go server also need to update. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --------- Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@@ -148,9 +148,9 @@ func (h *ChatSessionHandler) RemoveChatSessions(c *gin.Context) {
|
||||
// @Tags chat_session
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param dialog_id query string true "dialog ID"
|
||||
// @Param chat_id query string true "chat ID"
|
||||
// @Success 200 {object} service.ListChatSessionsResponse
|
||||
// @Router /v1/conversation/list [get]
|
||||
// @Router /api/v1/chats/<chat_id>/sessions [get]
|
||||
func (h *ChatSessionHandler) ListChatSessions(c *gin.Context) {
|
||||
user, errorCode, errorMessage := GetUser(c)
|
||||
if errorCode != common.CodeSuccess {
|
||||
@@ -159,18 +159,18 @@ func (h *ChatSessionHandler) ListChatSessions(c *gin.Context) {
|
||||
}
|
||||
userID := user.ID
|
||||
|
||||
// Get dialog_id from query parameter
|
||||
dialogID := c.Query("dialog_id")
|
||||
if dialogID == "" {
|
||||
// Get chat_id from query parameter
|
||||
chatID := c.Param("chat_id")
|
||||
if chatID == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"code": 400,
|
||||
"message": "dialog_id is required",
|
||||
"message": "chat_id is required",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// Call service to list chat sessions
|
||||
result, err := h.chatSessionService.ListChatSessions(userID, dialogID)
|
||||
result, err := h.chatSessionService.ListChatSessions(userID, chatID)
|
||||
if err != nil {
|
||||
// Check if it's an authorization error
|
||||
if err.Error() == "Only owner of dialog authorized for this operation" {
|
||||
|
||||
@@ -19,6 +19,7 @@ package handler
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"ragflow/internal/cache"
|
||||
"ragflow/internal/common"
|
||||
"ragflow/internal/server"
|
||||
"ragflow/internal/server/local"
|
||||
@@ -72,8 +73,15 @@ func (h *UserHandler) Register(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
variables := server.GetVariables()
|
||||
secretKey := variables.SecretKey
|
||||
secretKey, err := server.GetSecretKey(cache.Get())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": common.CodeServerError,
|
||||
"message": fmt.Sprintf("Failed to get secret key: %s", err.Error()),
|
||||
"data": false,
|
||||
})
|
||||
return
|
||||
}
|
||||
authToken, err := utility.DumpAccessToken(*user.AccessToken, secretKey)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
@@ -129,8 +137,15 @@ func (h *UserHandler) Login(c *gin.Context) {
|
||||
}
|
||||
|
||||
// Sign the access_token using itsdangerous (compatible with Python)
|
||||
variables := server.GetVariables()
|
||||
secretKey := variables.SecretKey
|
||||
secretKey, err := server.GetSecretKey(cache.Get())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": common.CodeServerError,
|
||||
"message": fmt.Sprintf("Failed to get secret key: %s", err.Error()),
|
||||
"data": false,
|
||||
})
|
||||
return
|
||||
}
|
||||
authToken, err := utility.DumpAccessToken(*user.AccessToken, secretKey)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
@@ -197,8 +212,15 @@ func (h *UserHandler) LoginByEmail(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
variables := server.GetVariables()
|
||||
secretKey := variables.SecretKey
|
||||
secretKey, err := server.GetSecretKey(cache.Get())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": common.CodeServerError,
|
||||
"message": fmt.Sprintf("Failed to get secret key: %s", err.Error()),
|
||||
"data": false,
|
||||
})
|
||||
return
|
||||
}
|
||||
authToken, err := utility.DumpAccessToken(*user.AccessToken, secretKey)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
|
||||
Reference in New Issue
Block a user