coze-studio/backend/api/handler/coze/bot_open_api_service.go

66 lines
1.8 KiB
Go

/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Code generated by hertz generator.
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"
bot_open_api "github.com/coze-dev/coze-studio/backend/api/model/ocean/cloud/bot_open_api"
)
// OauthAuthorizationCode .
// @router /api/oauth/authorization_code [GET]
func OauthAuthorizationCode(ctx context.Context, c *app.RequestContext) {
var err error
var req bot_open_api.OauthAuthorizationCodeReq
err = c.BindAndValidate(&req)
if err != nil {
invalidParamRequestResponse(c, err.Error())
return
}
if req.Code == "" {
invalidParamRequestResponse(c, "authorization failed, code is required")
return
}
if req.State == "" {
invalidParamRequestResponse(c, "state is required")
return
}
_, err = plugin.PluginApplicationSVC.OauthAuthorizationCode(ctx, &req)
if err != nil {
internalServerErrorResponse(ctx, c, err)
return
}
redirectURL := fmt.Sprintf("%s/information/auth/success", conf.GetServerHost())
c.Redirect(consts.StatusFound, []byte(redirectURL))
c.Abort()
return
}