['client_credentials', 'authorization_code', 'refresh_token']], // 客户端凭证验证 ['client_id', 'required', 'when' => function($data) { return in_array($data['grant_type'] ?? '', ['client_credentials', 'authorization_code']); }], ['client_secret', 'required', 'when' => function($data) { return in_array($data['grant_type'] ?? '', ['client_credentials', 'authorization_code']); }], // 授权码验证 ['code', 'required', 'when' => function($data) { return ($data['grant_type'] ?? '') === 'authorization_code'; }], // 刷新令牌验证 ['refresh_token', 'required', 'when' => function($data) { return ($data['grant_type'] ?? '') === 'refresh_token'; }], // 业务验证(按顺序执行) [ 'client_id', new AppExistenceValidator($this, ['client_secret', 'app']), 'msg' => '应用不存在或密钥错误', 'when' => function($data) { return isset($data['client_id']) && isset($data['client_secret']); } ], [ 'client_id', new AppStatusValidator($this, ['app']), 'msg' => '应用状态异常', 'when' => function($data) { return isset($data['client_id']); } ], [ 'scope', new ScopePermissionValidator($this, ['app', 'scopes']), 'msg' => '权限范围验证失败', 'when' => function($data) { return isset($data['scope']) && isset($data['client_id']); } ], ]; } /** * 默认值 */ public function default(): array { return [ 'scope' => '', ]; } }