justauth/JustAuth · error · UnsupportedOperationException

不支持获取授权 url,请使用小程序内置函数 qq.login() 登录获取 code

Error message

不支持获取授权 url,请使用小程序内置函数 qq.login() 登录获取 code

What it means

QQ_MINI_PROGRAM.authorize() throws UnsupportedOperationException telling you to use the mini-program built-in qq.login() to get the code. QQ mini programs have no OAuth authorize URL; the code comes from qq.login() on the client and is exchanged server-side via https://api.q.qq.com/sns/jscode2session (this source's accessToken()).

Source

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

        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");
        }

        @Override
        public String accessToken() {
            // 参见 https://q.qq.com/wiki/develop/miniprogram/server/open_port/port_login.html 文档
            // 获取 openid, unionId , session_key 等字段
            return "https://api.q.qq.com/sns/jscode2session";
        }

        @Override
        public String userInfo() {
            // 参见 https://q.qq.com/wiki/develop/miniprogram/API/open_port/port_userinfo.html 文档
            throw new UnsupportedOperationException("不支持获取用户信息 url,请使用小程序内置函数 qq.getUserInfo() 获取用户信息");
        }

        @Override
        public Class<? extends AuthDefaultRequest> getTargetClass() {
            return null;

View on GitHub (pinned to 694bbf1b01)

Solutions

  1. Call qq.login() in the mini-program client and send the code to your server, then hit the jscode2session endpoint yourself (or via a custom AuthSource).
  2. Exclude QQ_MINI_PROGRAM from authorize-URL generation branches.
  3. Because getTargetClass() is null, do not route this source through AuthRequestBuilder.build(); implement a custom AuthSource with a real target class if you need the standard request API.

Example fix

// before
String url = request.authorize(state); // UnsupportedOperationException for QQ_MINI_PROGRAM

// after
// client: qq.login({ success: r => POST /auth/qq-mini?code=r.code })
// server: GET https://api.q.qq.com/sns/jscode2session?appid=..&secret=..&js_code=..&grant_type=authorization_code
Defensive patterns

Strategy: validation

Validate before calling

if ("qq_mini_program".equalsIgnoreCase(sourceName)) {
    // no authorize URL and getTargetClass() is null: call jscode2session yourself
    return qqMiniLogin(code); // GET https://api.q.qq.com/sns/jscode2session?...
}

Type guard

boolean isMiniProgramSource(AuthSource s) {
    try { s.authorize(); return false; }
    catch (UnsupportedOperationException e) { return true; }
}

Try / catch

catch (UnsupportedOperationException e) { /* QQ mini program: use qq.login() code + jscode2session directly */ }

Prevention

When it happens

Trigger: Calling authorize(state) / getAuthorizeUrl(...) on a request built for QQ_MINI_PROGRAM; a generic provider-iteration login page that generates authorize URLs for every configured source.

Common situations: Copy-pasting the WeChat web-OAuth flow for QQ mini programs; shared login controllers that do not special-case mini-program sources. Note also that QQ_MINI_PROGRAM.getTargetClass() returns null, so building an AuthRequest via AuthRequestBuilder for it fails separately (error 2).

Related errors


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