fix(plugin): authorization code redirect to static url (#191)

This commit is contained in:
mrh997
2025-08-07 12:24:18 +08:00
committed by GitHub
parent efbc82e8b3
commit e2b1f6e381
12 changed files with 79 additions and 63 deletions

View File

@@ -20,12 +20,14 @@ package coze
import (
"context"
"fmt"
"github.com/coze-dev/coze-studio/backend/application/plugin"
"github.com/coze-dev/coze-studio/backend/domain/plugin/conf"
"github.com/cloudwego/hertz/pkg/app"
"github.com/cloudwego/hertz/pkg/protocol/consts"
"github.com/coze-dev/coze-studio/backend/application/plugin"
bot_open_api "github.com/coze-dev/coze-studio/backend/api/model/ocean/cloud/bot_open_api"
)
@@ -41,7 +43,7 @@ func OauthAuthorizationCode(ctx context.Context, c *app.RequestContext) {
}
if req.Code == "" {
invalidParamRequestResponse(c, "code is required")
invalidParamRequestResponse(c, "authorization failed, code is required")
return
}
if req.State == "" {
@@ -49,11 +51,15 @@ func OauthAuthorizationCode(ctx context.Context, c *app.RequestContext) {
return
}
resp, err := plugin.PluginApplicationSVC.OauthAuthorizationCode(ctx, &req)
_, err = plugin.PluginApplicationSVC.OauthAuthorizationCode(ctx, &req)
if err != nil {
internalServerErrorResponse(ctx, c, err)
return
}
c.JSON(consts.StatusOK, resp)
redirectURL := fmt.Sprintf("%s/information/auth/success", conf.GetServerHost())
c.Redirect(consts.StatusFound, []byte(redirectURL))
c.Abort()
return
}

View File

@@ -61,9 +61,13 @@ func isStaticFile(ctx *app.RequestContext) bool {
return true
}
if strings.HasPrefix(string(path), "/static/") ||
strings.HasPrefix(string(path), "/explore/") ||
strings.HasPrefix(string(path), "/space/") {
if strings.HasPrefix(path, "/static/") ||
strings.HasPrefix(path, "/explore/") ||
strings.HasPrefix(path, "/space/") {
return true
}
if path == "/information/auth/success" {
return true
}

View File

@@ -23,7 +23,7 @@ import (
"strings"
api "github.com/coze-dev/coze-studio/backend/api/model/plugin_develop_common"
"github.com/coze-dev/coze-studio/backend/domain/plugin/utils"
"github.com/coze-dev/coze-studio/backend/domain/plugin/encrypt"
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
"github.com/coze-dev/coze-studio/backend/types/errno"
@@ -75,12 +75,12 @@ func (mf *PluginManifest) EncryptAuthPayload() (*PluginManifest, error) {
return mf_, nil
}
secret := os.Getenv(utils.AuthSecretEnv)
secret := os.Getenv(encrypt.AuthSecretEnv)
if secret == "" {
secret = utils.DefaultAuthSecret
secret = encrypt.DefaultAuthSecret
}
payload_, err := utils.EncryptByAES([]byte(mf_.Auth.Payload), secret)
payload_, err := encrypt.EncryptByAES([]byte(mf_.Auth.Payload), secret)
if err != nil {
return nil, err
}
@@ -363,12 +363,12 @@ func (au *AuthV2) UnmarshalJSON(data []byte) error {
}
if auth.Payload != "" {
secret := os.Getenv(utils.AuthSecretEnv)
secret := os.Getenv(encrypt.AuthSecretEnv)
if secret == "" {
secret = utils.DefaultAuthSecret
secret = encrypt.DefaultAuthSecret
}
payload_, err := utils.DecryptByAES(auth.Payload, secret)
payload_, err := encrypt.DecryptByAES(auth.Payload, secret)
if err == nil {
auth.Payload = string(payload_)
}