Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions gateway/apinto/auth/aksk.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package auth

func init() {
b := NewAKSK()
Register(b.Name(), b)
}

func NewAKSK() *AKSK {
return &AKSK{}
}

type AKSK struct {
}

func (a *AKSK) Name() string {
return "aksk"
}

func (a *AKSK) ToPattern(cfg map[string]interface{}) interface{} {
result := make(map[string]interface{})
result["ak"] = cfg["ak"]
result["sk"] = cfg["sk"]
return result
}

func (a *AKSK) ToConfig(cfg map[string]interface{}) interface{} {
return nil
}
35 changes: 35 additions & 0 deletions gateway/apinto/auth/jwt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package auth

func init() {
b := NewJWT()
Register(b.Name(), b)
}

func NewJWT() *JWT {
return &JWT{}
}

type JWT struct {
}

func (J *JWT) Name() string {
return "jwt"
}

func (J *JWT) ToPattern(cfg map[string]interface{}) interface{} {
result := make(map[string]interface{})
result["username"] = cfg["user"]
return result
}

func (J *JWT) ToConfig(cfg map[string]interface{}) interface{} {
result := make(map[string]interface{})
result["iss"] = cfg["iss"]
result["algorithm"] = cfg["algorithm"]
result["secret"] = cfg["secret"]
result["rsa_public_key"] = cfg["publicKey"]
result["path"] = cfg["userPath"]
result["claims_to_verify"] = cfg["claimsToVerify"]
result["signature_is_base_64"] = cfg["signatureIsBase64"]
return result
}
29 changes: 29 additions & 0 deletions gateway/apinto/auth/oauth2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package auth

func init() {
b := NewOAuth2()
Register(b.Name(), b)
}

func NewOAuth2() *OAuth2 {
return &OAuth2{}
}

type OAuth2 struct {
}

func (o *OAuth2) Name() string {
return "oauth2"
}
func (o *OAuth2) ToPattern(cfg map[string]interface{}) interface{} {
result := make(map[string]interface{})
result["client_id"] = cfg["client_id"]
result["client_secret"] = cfg["client_secret"]
result["client_type"] = cfg["client_type"]
result["hash_secret"] = cfg["hash_secret"]
result["redirect_urls"] = cfg["redirect_urls"]
return result
}
func (o *OAuth2) ToConfig(cfg map[string]interface{}) interface{} {
return nil
}
26 changes: 13 additions & 13 deletions module/application-authorization/auth-driver/jwt/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
"fmt"
"strconv"
"strings"

auth_driver "github.com/APIParkLab/APIPark/module/application-authorization/auth-driver"

"github.com/eolinker/go-common/utils"

application_authorization_dto "github.com/APIParkLab/APIPark/module/application-authorization/dto"
)

Expand All @@ -26,12 +26,12 @@ type Config struct {
Iss string `json:"iss"`
Algorithm string `json:"algorithm"`
Secret string `json:"secret"`
PublicKey string `json:"public_key"`
PublicKey string `json:"publicKey"`
User string `json:"user"`
UserPath string `json:"user_path"`
ClaimsToVerify []string `json:"claims_to_verify"`
UserPath string `json:"userPath"`
ClaimsToVerify []string `json:"claimsToVerify"`
Label map[string]string `json:"label"`
SignatureIsBase64 bool `json:"signature_is_base64"`
SignatureIsBase64 bool `json:"signatureIsBase64"`
}

func (cfg *Config) ID() string {
Expand All @@ -46,7 +46,7 @@ func (cfg *Config) ID() string {
for _, claim := range cfg.ClaimsToVerify {
builder.WriteString(strings.TrimSpace(claim))
}

case "RS256", "RS384", "RS512", "ES256", "ES384", "ES512":
builder.WriteString(strings.TrimSpace(cfg.Iss))
builder.WriteString(strings.TrimSpace(cfg.PublicKey))
Expand Down Expand Up @@ -81,7 +81,7 @@ func (cfg *Config) Valid() ([]byte, error) {
default:
return nil, fmt.Errorf("unsupport algorithm")
}

//校验 校验字段
for _, claim := range cfg.ClaimsToVerify {
switch claim {
Expand All @@ -94,26 +94,26 @@ func (cfg *Config) Valid() ([]byte, error) {
}

func (cfg *Config) Detail() []application_authorization_dto.DetailItem {

items := []application_authorization_dto.DetailItem{
{Key: "Iss", Value: cfg.Iss},
{Key: "签名算法", Value: cfg.Algorithm},
{Key: "用户名", Value: cfg.User},
{Key: "用户名JsonPath", Value: cfg.UserPath},
{Key: "校验字段", Value: strings.Join(cfg.ClaimsToVerify, ",")},
}

switch cfg.Algorithm {
case "HS256", "HS384", "HS512":
items = append(items, application_authorization_dto.DetailItem{Key: "Secret", Value: cfg.Secret})
base64 := "false"
if cfg.SignatureIsBase64 {
base64 = "true"
}
items = append(items, application_authorization_dto.DetailItem{Key: "Secret", Value: base64})
items = append(items, application_authorization_dto.DetailItem{Key: "SignatureIsBase64", Value: base64})
default:
items = append(items, application_authorization_dto.DetailItem{Key: "RSA公钥", Value: cfg.PublicKey})
}

return items
}