justauth/JustAuth · error · UnsupportedOperationException

不支持获取用户信息 url,请使用小程序内置函数 wx.getUserProfile() 获取用户信息

Error message

不支持获取用户信息 url,请使用小程序内置函数 wx.getUserProfile() 获取用户信息

What it means

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.

Source

Thrown at src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java:1460

    WECHAT_MINI_PROGRAM {

        @Override
        public String authorize() {
            // 参见 https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/login.html 文档
            throw new UnsupportedOperationException("不支持获取授权 url,请使用小程序内置函数 wx.login() 登录获取 code");
        }

        @Override
        public String accessToken() {
            // 参见 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html 文档
            // 获取 openid, unionId , session_key 等字段
            return "https://api.weixin.qq.com/sns/jscode2session";
        }

        @Override
        public String userInfo() {
            // 参见 https://developers.weixin.qq.com/miniprogram/dev/api/open-api/user-info/wx.getUserProfile.html 文档
            throw new UnsupportedOperationException("不支持获取用户信息 url,请使用小程序内置函数 wx.getUserProfile() 获取用户信息");
        }

        @Override
        public Class<? extends AuthDefaultRequest> getTargetClass() {
            return AuthWechatMiniProgramRequest.class;
        }
    },

    /**
     * QQ小程序授权登录
     */
    QQ_MINI_PROGRAM {
        @Override
        public String authorize() {
            // 参见 https://q.qq.com/wiki/develop/miniprogram/frame/open_ability/open_userinfo.html 文档
            throw new UnsupportedOperationException("不支持获取授权 url,请使用小程序内置函数 qq.login() 登录获取 code");
        }

View on GitHub (pinned to 694bbf1b01)

Solutions

  1. Use the jscode2session result (openid/unionid/session_key) from getAccessToken as the identity; do not call getUserInfo.
  2. Collect nickname/avatar in the client with wx.getUserProfile() and send them to your backend in your own DTO.
  3. Branch by source before calling getUserInfo in shared login code.

Example fix

// before
AuthUser user = request.getUserInfo(token); // throws UnsupportedOperationException

// after
AuthToken session = request.getAccessToken(AuthCallback.builder().code(code).build());
// client sends profile obtained via wx.getUserProfile() alongside the code; build AuthUser from your own payload
Defensive patterns

Strategy: validation

Validate before calling

if ("wechat_mini_program".equalsIgnoreCase(sourceName)) {
    AuthToken session = request.getAccessToken(cb); // openid/unionid/session_key
    return userFromSessionAndClientProfile(session, clientProfile); // profile posted by client
}

Type guard

boolean supportsServerUserInfo(AuthSource s) {
    try { s.userInfo(); return true; }
    catch (UnsupportedOperationException | AuthException e) { return false; }
}

Try / catch

catch (UnsupportedOperationException e) { /* skip server-side userInfo; use jscode2session identity + client wx.getUserProfile payload */ }

Prevention

When it happens

Trigger: Calling getUserInfo(authToken) on an AuthWechatMiniProgramRequest, or a generic post-token step that invokes source.userInfo() for this source.

Common situations: 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.

Related errors


AI-assisted analysis of justauth/JustAuth@694bbf1b01 (2026-08-14). Data as JSON: /api/errors/f5dbfa69d6b9b6b0. Report an issue: GitHub.