| 62 | } |
| 63 | |
| 64 | func (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 | |
| 96 | func (cfg *Config) Detail() []application_authorization_dto.DetailItem { |
| 97 | |