mirror of
https://github.com/APIParkLab/APIPark.git
synced 2026-06-12 18:11:34 +08:00
Fix: Issue with invalid apikey parameter in service MCP path
This commit is contained in:
@@ -3,7 +3,7 @@ package auth_driver
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
|
||||
application_authorization_dto "github.com/APIParkLab/APIPark/module/application-authorization/dto"
|
||||
)
|
||||
|
||||
@@ -83,6 +83,6 @@ func generateStruct[T any](cfg interface{}) (*T, error) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ package oauth2
|
||||
import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
|
||||
|
||||
auth_driver "github.com/APIParkLab/APIPark/module/application-authorization/auth-driver"
|
||||
|
||||
|
||||
application_authorization_dto "github.com/APIParkLab/APIPark/module/application-authorization/dto"
|
||||
)
|
||||
|
||||
@@ -33,7 +33,7 @@ func (cfg *Config) ID() string {
|
||||
}
|
||||
|
||||
func (cfg *Config) Valid() ([]byte, error) {
|
||||
|
||||
|
||||
if cfg.HashSecret && !cfg.Hashed {
|
||||
// 未加密
|
||||
secret, err := hashSecret([]byte(cfg.ClientSecret), 0, 0, 0)
|
||||
@@ -48,9 +48,9 @@ func (cfg *Config) Valid() ([]byte, error) {
|
||||
}
|
||||
|
||||
func (cfg *Config) Detail() []application_authorization_dto.DetailItem {
|
||||
|
||||
|
||||
redirectURLs, _ := json.Marshal(cfg.RedirectUrls)
|
||||
|
||||
|
||||
return []application_authorization_dto.DetailItem{
|
||||
{Key: "客户端ID", Value: cfg.ClientId},
|
||||
{Key: "客户端密钥", Value: cfg.ClientSecret},
|
||||
|
||||
@@ -2,9 +2,10 @@ package application_authorization
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/APIParkLab/APIPark/module/system"
|
||||
"reflect"
|
||||
|
||||
"github.com/APIParkLab/APIPark/module/system"
|
||||
|
||||
application_authorization_dto "github.com/APIParkLab/APIPark/module/application-authorization/dto"
|
||||
|
||||
"github.com/APIParkLab/APIPark/gateway"
|
||||
@@ -31,6 +32,9 @@ type IAuthorizationModule interface {
|
||||
Detail(ctx context.Context, appId string, aid string) ([]application_authorization_dto.DetailItem, error)
|
||||
// Info 获取项目鉴权详情
|
||||
Info(ctx context.Context, appId string, aid string) (*application_authorization_dto.Authorization, error)
|
||||
|
||||
CheckAPIKeyAuthorization(ctx context.Context, serviceId string, apikey string) (bool, error)
|
||||
|
||||
//ExportAll(ctx context.Context) ([]*application_authorization_dto.ExportAuthorization, error)
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/APIParkLab/APIPark/service/subscribe"
|
||||
|
||||
application_authorization "github.com/APIParkLab/APIPark/service/application-authorization"
|
||||
|
||||
"github.com/eolinker/eosc/log"
|
||||
@@ -36,11 +38,80 @@ var (
|
||||
|
||||
type imlAuthorizationModule struct {
|
||||
serviceService service.IServiceService `autowired:""`
|
||||
subscribeService subscribe.ISubscribeService `autowired:""`
|
||||
authorizationService application_authorization.IAuthorizationService `autowired:""`
|
||||
clusterService cluster.IClusterService `autowired:""`
|
||||
transaction store.ITransaction `autowired:""`
|
||||
}
|
||||
|
||||
func (i *imlAuthorizationModule) CheckAPIKeyAuthorization(ctx context.Context, serviceId string, apikey string) (bool, error) {
|
||||
list, err := i.subscribeService.ListBySubscribeStatus(ctx, serviceId, subscribe.ApplyStatusSubscribe)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if len(list) < 1 {
|
||||
return false, fmt.Errorf("no application found")
|
||||
}
|
||||
appIds := utils.SliceToSlice(list, func(s *subscribe.Subscribe) string {
|
||||
return s.Application
|
||||
})
|
||||
authorizations, err := i.authorizationService.ListByApp(ctx, appIds...)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
for _, a := range authorizations {
|
||||
if a.Type != "apikey" {
|
||||
continue
|
||||
}
|
||||
cfg := make(map[string]interface{})
|
||||
if a.Config != "" {
|
||||
json.Unmarshal([]byte(a.Config), &cfg)
|
||||
}
|
||||
if cfg["apikey"] == apikey {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func (i *imlAuthorizationModule) AuthorizationsByService(ctx context.Context, serviceId string, authorizationType string) ([]*application_authorization_dto.Authorization, error) {
|
||||
list, err := i.subscribeService.ListBySubscribeStatus(ctx, serviceId, subscribe.ApplyStatusSubscribe)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(list) < 1 {
|
||||
return nil, fmt.Errorf("no application found")
|
||||
}
|
||||
appIds := utils.SliceToSlice(list, func(s *subscribe.Subscribe) string {
|
||||
return s.Application
|
||||
})
|
||||
authorizations, err := i.authorizationService.ListByApp(ctx, appIds...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := make([]*application_authorization_dto.Authorization, 0, len(authorizations))
|
||||
for _, a := range authorizations {
|
||||
if authorizationType != "" && a.Type != authorizationType {
|
||||
continue
|
||||
}
|
||||
cfg := make(map[string]interface{})
|
||||
if a.Config != "" {
|
||||
json.Unmarshal([]byte(a.Config), &cfg)
|
||||
}
|
||||
result = append(result, &application_authorization_dto.Authorization{
|
||||
UUID: a.UUID,
|
||||
Name: a.Name,
|
||||
Driver: a.Type,
|
||||
Position: a.Position,
|
||||
TokenName: a.TokenName,
|
||||
Config: cfg,
|
||||
ExpireTime: a.ExpireTime,
|
||||
HideCredential: a.HideCredential,
|
||||
})
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (i *imlAuthorizationModule) ExportAll(ctx context.Context) ([]*application_authorization_dto.ExportAuthorization, error) {
|
||||
list, err := i.authorizationService.List(ctx)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user