Backend Development 6 min read

JustAuth: A Simple Java Library for Third‑Party OAuth Login Integration

JustAuth is a Java library that simplifies third‑party OAuth login by providing unified interfaces, customizable state, scopes, HTTP clients, and support for dozens of platforms, with clear code examples for quick integration such as QQ login.

Code Ape Tech Column
Code Ape Tech Column
Code Ape Tech Column
JustAuth: A Simple Java Library for Third‑Party OAuth Login Integration

Hello everyone, I am Chen~

JustAuth, as you can see, is a third‑party authorization login utility library that frees us from cumbersome SDKs and makes login so easy !

JustAuth integrates dozens of domestic and overseas platforms such as GitHub, Gitee, Alipay, Sina Weibo, WeChat, Google, Facebook, Twitter, StackOverflow, etc.

Features

Rich OAuth platforms: Integrated dozens of third‑party platforms for rapid access.

Custom state: Supports custom state and cache strategies, allowing developers to choose any cache plugin.

Custom OAuth: Provides a unified interface to connect any OAuth site, making it easy to adapt your own OAuth service.

Custom HTTP: HTTP tool interface lets developers select the HTTP client that fits their project.

Custom Scope: Supports custom scopes to suit more business scenarios beyond simple login.

Simple code standards: Strictly follows Alibaba Java coding guidelines, with clear structure and simple logic.

Quick Start (using QQ as an example)

Apply for a developer account

If this is your first time, apply for a developer on the "QQ Connect Platform", create an application after approval, and copy three pieces of information: App ID, App Key, and the website callback domain.

Integrate JustAuth

Add the dependency:

<dependency>
    <groupId>me.zhyd.oauth</groupId>
    <artifactId>JustAuth</artifactId>
    <version>{latest-version}</version>
</dependency>

Create a request and add the three pieces of information from the first step:

AuthRequest authRequest = new AuthQqRequest(AuthConfig.builder()
    .clientId("App ID")
    .clientSecret("App Key")
    .redirectUri("Website callback domain")
    .build());

Generate the authorization URL:

// This link can be redirected in the backend or returned to the front end for redirection
String authorizeUrl = authRequest.authorize(AuthStateUtils.createState());

Or generate a static authorization page:

AuthRequest authRequest = AuthRequestBuilder.builder()
    .source("github")
    .authConfig(AuthConfig.builder()
        .clientId("clientId")
        .clientSecret("clientSecret")
        .redirectUri("redirectUri")
        .build())
    .build();
// Generate authorization page
authRequest.authorize("state");
// After login, a code (auth_code for Alipay) and state are returned; since version 1.8.0, AuthCallback can be used as the callback parameter
// Note: JustAuth keeps the state for 3 minutes by default; it will be cleared automatically after expiration.
authRequest.login(callback);

Or generate a dynamic authorization page:

AuthRequest authRequest = AuthRequestBuilder.builder()
    .source("gitee")
    .authConfig((source) -> {
        // Dynamically obtain AuthConfig based on source
        // Config can be fetched from SQL, files, etc.
        return AuthConfig.builder()
            .clientId("clientId")
            .clientSecret("clientSecret")
            .redirectUri("redirectUri")
            .build();
    })
    .build();
Assert.assertTrue(authRequest instanceof AuthGiteeRequest);
System.out.println(authRequest.authorize(AuthStateUtils.createState()));

The JustAuth team continues to add support for more platforms; interested readers can follow the project.

Open‑source address

https://github.com/justauth/JustAuth

Final note (please support)

Each of my articles is carefully crafted; if this one helped or inspired you, please like , view , share , and bookmark . Your support is my biggest motivation!

Additionally, I have a Knowledge Circle that costs 199 CNY, offering extensive resources such as the "Code Monkey Chronic Cloud Management" project, Spring full‑stack series, billion‑scale sharding practice, DDD microservice series, and many more.

More introduction

To join the circle, add my WeChat: special_coder
JavaAuthenticationTutorialthird-party loginOAuthJustAuth
Code Ape Tech Column
Written by

Code Ape Tech Column

Former Ant Group P8 engineer, pure technologist, sharing full‑stack Java, job interview and career advice through a column. Site: java-family.cn

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.