{"record":{"id":"f5dbfa69d6b9b6b0","repo":"justauth/JustAuth","slug":"url-wx-getuserprofile","errorCode":null,"errorMessage":"不支持获取用户信息 url，请使用小程序内置函数 wx.getUserProfile() 获取用户信息","messagePattern":"不支持获取用户信息 url，请使用小程序内置函数 wx\\.getUserProfile\\(\\) 获取用户信息","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java","lineNumber":1460,"sourceCode":"    WECHAT_MINI_PROGRAM {\n\n        @Override\n        public String authorize() {\n            // 参见 https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/login.html 文档\n            throw new UnsupportedOperationException(\"不支持获取授权 url，请使用小程序内置函数 wx.login() 登录获取 code\");\n        }\n\n        @Override\n        public String accessToken() {\n            // 参见 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html 文档\n            // 获取 openid, unionId , session_key 等字段\n            return \"https://api.weixin.qq.com/sns/jscode2session\";\n        }\n\n        @Override\n        public String userInfo() {\n            // 参见 https://developers.weixin.qq.com/miniprogram/dev/api/open-api/user-info/wx.getUserProfile.html 文档\n            throw new UnsupportedOperationException(\"不支持获取用户信息 url，请使用小程序内置函数 wx.getUserProfile() 获取用户信息\");\n        }\n\n        @Override\n        public Class<? extends AuthDefaultRequest> getTargetClass() {\n            return AuthWechatMiniProgramRequest.class;\n        }\n    },\n\n    /**\n     * QQ小程序授权登录\n     */\n    QQ_MINI_PROGRAM {\n        @Override\n        public String authorize() {\n            // 参见 https://q.qq.com/wiki/develop/miniprogram/frame/open_ability/open_userinfo.html 文档\n            throw new UnsupportedOperationException(\"不支持获取授权 url，请使用小程序内置函数 qq.login() 登录获取 code\");\n        }\n","sourceCodeStart":1442,"sourceCodeEnd":1478,"githubUrl":"https://github.com/justauth/JustAuth/blob/694bbf1b010d93404e3bfb4824d90e9ddfaebebb/src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java#L1442-L1478","documentation":"WECHAT_MINI_PROGRAM.userInfo() throws UnsupportedOperationException instructing you to use wx.getUserProfile() on the client. There is no server-side user-info URL for WeChat mini programs: profile data must be collected in the mini program via wx.getUserProfile() and passed to your backend yourself.","triggerScenarios":"Calling getUserInfo(authToken) on an AuthWechatMiniProgramRequest, or a generic post-token step that invokes source.userInfo() for this source.","commonSituations":"Reusing a web-OAuth login pipeline (token then getUserInfo) for the mini-program source; after WeChat deprecatedgetUserInfo-in-app, assuming the server can still fetch the profile. The exception is unchecked (not AuthException), so it can escape generic error handlers.","solutions":["Use the jscode2session result (openid/unionid/session_key) from getAccessToken as the identity; do not call getUserInfo.","Collect nickname/avatar in the client with wx.getUserProfile() and send them to your backend in your own DTO.","Branch by source before calling getUserInfo in shared login code."],"exampleFix":"// before\nAuthUser user = request.getUserInfo(token); // throws UnsupportedOperationException\n\n// after\nAuthToken session = request.getAccessToken(AuthCallback.builder().code(code).build());\n// client sends profile obtained via wx.getUserProfile() alongside the code; build AuthUser from your own payload","handlingStrategy":"validation","validationCode":"if (\"wechat_mini_program\".equalsIgnoreCase(sourceName)) {\n    AuthToken session = request.getAccessToken(cb); // openid/unionid/session_key\n    return userFromSessionAndClientProfile(session, clientProfile); // profile posted by client\n}","typeGuard":"boolean supportsServerUserInfo(AuthSource s) {\n    try { s.userInfo(); return true; }\n    catch (UnsupportedOperationException | AuthException e) { return false; }\n}","tryCatchPattern":"catch (UnsupportedOperationException e) { /* skip server-side userInfo; use jscode2session identity + client wx.getUserProfile payload */ }","preventionTips":["Design your login DTO to accept an optional client-side profile block.","Never call getUserInfo for mini-program sources.","Identify users by openid/unionid, not by profile fields."],"tags":["justauth","wechat","mini-program","unsupported-operation","provider-quirk"],"backgroundTag":null,"analyzedSha":"694bbf1b010d93404e3bfb4824d90e9ddfaebebb","analyzedAt":"2026-08-14T15:16:59.945Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}