MCPcopy Index your code
hub / github.com/APIParkLab/APIPark / Valid

Method Valid

module/application-authorization/auth-driver/jwt/jwt.go:64–94  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

62}
63
64func (cfg *Config) Valid() ([]byte, error) {
65 if cfg.Iss == "" {
66 return nil, errors.New("iss is null")
67 }
68 if cfg.Algorithm == "" {
69 return nil, errors.New("algorithm is null")
70 }
71 algorithm := strings.ToUpper(cfg.Algorithm)
72 switch algorithm {
73 case "HS256", "HS384", "HS512":
74 if cfg.Secret == "" {
75 return nil, errors.New("secret is null")
76 }
77 case "RS256", "RS384", "RS512", "ES256", "ES384", "ES512":
78 if cfg.PublicKey == "" {
79 return nil, errors.New("public_key is null")
80 }
81 default:
82 return nil, fmt.Errorf("unsupport algorithm")
83 }
84
85 //校验 校验字段
86 for _, claim := range cfg.ClaimsToVerify {
87 switch claim {
88 case "exp", "nbf":
89 default:
90 return nil, fmt.Errorf("claim key %s is illegal. ", claim)
91 }
92 }
93 return json.Marshal(cfg)
94}
95
96func (cfg *Config) Detail() []application_authorization_dto.DetailItem {
97

Callers

nothing calls this directly

Calls 1

MarshalMethod · 0.80

Tested by

no test coverage detected