{"record":{"id":"eef00c0d30f31e8d","repo":"dromara/Sa-Token","slug":"30142","errorCode":"30142","errorMessage":"应用暂未开放此授权模式","messagePattern":"应用暂未开放此授权模式","errorType":"exception","errorClass":"SaOAuth2Exception","httpStatus":null,"severity":"error","filePath":"sa-token-plugin/sa-token-oauth2/src/main/java/cn/dev33/satoken/oauth2/processor/SaOAuth2ServerProcessor.java","lineNumber":392,"sourceCode":"\t\t}\n\t\t// 其它\n\t\telse {\n\t\t\tthrow new SaOAuth2Exception(\"无效 response_type: \" + responseType).setCode(SaOAuth2ErrorCode.CODE_30125);\n\t\t}\n\t}\n\n\t/**\n\t * 系统未开放此授权模式时抛出异常\n\t */\n\tpublic void throwErrorSystemNotEnableModel() {\n\t\tthrow new SaOAuth2Exception(\"系统暂未开放此授权模式\").setCode(SaOAuth2ErrorCode.CODE_30141);\n\t}\n\n\t/**\n\t * 应用未开放此授权模式时抛出异常\n\t */\n\tpublic void throwErrorClientNotEnableModel() {\n\t\tthrow new SaOAuth2Exception(\"应用暂未开放此授权模式\").setCode(SaOAuth2ErrorCode.CODE_30142);\n\t}\n\n}\n","sourceCodeStart":374,"sourceCodeEnd":396,"githubUrl":"https://github.com/dromara/Sa-Token/blob/ac2c7f6e94a78573cf0bcb932dd8b04e68fad189/sa-token-plugin/sa-token-oauth2/src/main/java/cn/dev33/satoken/oauth2/processor/SaOAuth2ServerProcessor.java#L374-L396","documentation":"Thrown by throwErrorClientNotEnableModel() when the mode is enabled globally but the specific client is not allowed to use it: the client's registered allowGrantTypes list does not contain the requested grant type. Error code 30142.","triggerScenarios":"A SaClientModel registered with allowGrantTypes=[authorization_code] receiving a password or client_credentials request; client record updated in the data store but the cached/duplicated registration still has the old list.","commonSituations":"Newly added integration reuses an existing client_id that was registered for web-server flow only; the client was provisioned via config copy-paste and allowGrantTypes was never widened; multi-instance deployments where only one node reloaded the client registry.","solutions":["Add the grant type to the client's allowGrantTypes when registering the SaClientModel (e.g. Arrays.asList(\"authorization_code\", \"password\", \"client_credentials\"))","Verify the client record actually in use (right client_id, right environment/data loader) — not a stale duplicate","Ensure the mode is also enabled at server level, otherwise 30141 fires next"],"exampleFix":"// before\nnew SaClientModel().setClientId(\"1001\")\n    .setAllowGrantTypes(Arrays.asList(\"authorization_code\"));\n\n// after\nnew SaClientModel().setClientId(\"1001\")\n    .setAllowGrantTypes(Arrays.asList(\"authorization_code\", \"password\", \"client_credentials\"));","handlingStrategy":"validation","validationCode":"SaClientModel cm = oauth2Template.getClientModel(clientId);\nif(cm == null || !cm.getAllowGrantTypes().contains(neededGrantType)) {\n    throw new IllegalStateException(\"client not allowed to use \" + neededGrantType);\n}","typeGuard":null,"tryCatchPattern":"catch(SaOAuth2Exception e) { if(\"30142\".equals(e.getCode())) return 403 \"client not permitted for this grant type\"; }","preventionTips":["Keep allowGrantTypes in the client registry in sync with the integrations that use each client_id","Add a startup check that every client's allowGrantTypes is a subset of the globally enabled modes"],"tags":["oauth2","grant-type","client-registration","sa-token"],"backgroundTag":null,"analyzedSha":"ac2c7f6e94a78573cf0bcb932dd8b04e68fad189","analyzedAt":"2026-08-14T14:36:10.271Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}