justauth/JustAuth · error · AuthException

5001

5001

Error message

Not Implemented

What it means

AuthRequestBuilder.build() throws AuthException with code 5001 (Not Implemented) when either the source name or the AuthConfig was never set on the builder. The library cannot construct an AuthRequest without knowing which provider to target and its configuration. Despite the name 'Not Implemented', it is really a builder-usage error: a required builder parameter is missing.

Source

Thrown at src/main/java/me/zhyd/oauth/AuthRequestBuilder.java:65

    public AuthRequestBuilder authConfig(Function<String, AuthConfig> authConfig) {
        this.authConfig = authConfig.apply(this.source);
        return this;
    }

    public AuthRequestBuilder authStateCache(AuthStateCache authStateCache) {
        this.authStateCache = authStateCache;
        return this;
    }

    public AuthRequestBuilder extendSource(AuthSource... extendSource) {
        this.extendSource = extendSource;
        return this;
    }

    public AuthRequest build() {
        if (StringUtils.isEmpty(this.source) || null == this.authConfig) {
            throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
        }
        // 合并 JustAuth 默认的 AuthDefaultSource 和 开发者自定义的 AuthSource
        AuthSource[] sources = this.concat(AuthDefaultSource.values(), extendSource);
        // 筛选符合条件的 AuthSource
        AuthSource source = Arrays.stream(sources).distinct()
            .filter(authSource -> authSource.getName().equalsIgnoreCase(this.source))
            .findAny()
            .orElseThrow(() -> new AuthException(AuthResponseStatus.NOT_IMPLEMENTED));

        Class<? extends AuthDefaultRequest> targetClass = source.getTargetClass();
        if (null == targetClass) {
            throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
        }
        try {
            if (this.authStateCache == null) {
                return targetClass.getDeclaredConstructor(AuthConfig.class).newInstance(this.authConfig);
            } else {
                return targetClass.getDeclaredConstructor(AuthConfig.class, AuthStateCache.class).newInstance(this.authConfig, this.authStateCache);

View on GitHub (pinned to 694bbf1b01)

Solutions

  1. Always chain .source(...) and .authConfig(...) before .build(): AuthRequest request = AuthRequestBuilder.create().source("gitee").authConfig(config).build();
  2. If config comes from a file/env, assert non-null/non-blank values before building (fail fast with your own clear message).
  3. If you need a state cache, also pass .authStateCache(cache) so the two-arg constructor path is used.

Example fix

// before
AuthRequest request = AuthRequestBuilder.create().source("gitee").build(); // 5001: authConfig null

// after
AuthConfig config = AuthConfig.builder().clientId(id).clientSecret(secret).redirectUri(uri).build();
AuthRequest request = AuthRequestBuilder.create().source("gitee").authConfig(config).build();
Defensive patterns

Strategy: validation

Validate before calling

if (StringUtils.isBlank(sourceName) || authConfig == null) {
    throw new IllegalArgumentException("source and authConfig are required before build()");
}
AuthRequest req = AuthRequestBuilder.create().source(sourceName).authConfig(authConfig).build();

Prevention

When it happens

Trigger: Calling AuthRequestBuilder.create().build() directly, or calling .source("gitee") without .authConfig(config) (or vice versa) before .build(). StringUtils.isEmpty(this.source) || null == this.authConfig is the exact condition.

Common situations: Copy-pasting JustAuth sample code and deleting the authConfig step; building the request from a properties/yaml file where the source key is misspelled so it reads back null; refactoring that splits builder calls across methods and drops one.

Related errors


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