Simplify Social Logins with JustAuth: A Complete Java Integration Guide
This article introduces JustAuth, a lightweight open‑source Java library that streamlines third‑party social logins by supporting dozens of platforms, explains its benefits for users and developers, and provides step‑by‑step Maven setup, HTTP client selection, and code examples for basic, builder‑pattern, and custom authentication flows.
As major apps like WeChat and Alipay become ubiquitous, many applications and websites now offer third‑party login to reduce registration friction.
Third‑party login lowers user registration cost for apps and provides users with quick access, shared profiles, and reduced password management.
JustAuth is an open‑source, lightweight Java library that supports a wide range of platforms for OAuth‑style authentication.
Supported platforms include GitHub, Gitee, Weibo, DingTalk, Baidu, Coding, Tencent Cloud, OSChina, Alipay, QQ, WeChat, Taobao, Google, Facebook, TikTok, LinkedIn, Xiaomi, Microsoft, Toutiao, Teambition, StackOverflow, Pinterest, Huawei, Enterprise WeChat, Kujiale, GitLab, Meituan, Ele.me, Twitter, Feishu, JD, Alibaba Cloud, Himalaya, Amazon, Slack, Line, and more.
The library abstracts away the complexity of individual SDKs, offering a simple API for developers.
To start, add the Maven dependency:
<dependency>
<groupId>me.zhyd.oauth</groupId>
<artifactId>JustAuth</artifactId>
<version>{latest-version}</version>
</dependency>Choose an HTTP client dependency such as hutool‑http, httpclient, or okhttp, and include the corresponding Maven coordinates.
Basic usage
// Create an AuthRequest for Gitee
AuthRequest authRequest = new AuthGiteeRequest(AuthConfig.builder()
.clientId("clientId")
.clientSecret("clientSecret")
.redirectUri("redirectUri")
.build());
// Generate the authorization URL
authRequest.authorize("state");
// Perform login
authRequest.login(callback);Builder pattern – static AuthConfig
AuthRequest authRequest = AuthRequestBuilder.builder()
.source("github")
.authConfig(AuthConfig.builder()
.clientId("clientId")
.clientSecret("clientSecret")
.redirectUri("redirectUri")
.build())
.build();
authRequest.authorize("state");
authRequest.login(callback);Builder pattern – dynamic AuthConfig
AuthRequest authRequest = AuthRequestBuilder.builder()
.source("gitee")
.authConfig(source -> {
// Retrieve configuration dynamically, e.g., from DB
return AuthConfig.builder()
.clientId("clientId")
.clientSecret("clientSecret")
.redirectUri("redirectUri")
.build();
})
.build();Custom platform extension
AuthRequest authRequest = AuthRequestBuilder.builder()
.extendSource(AuthExtendSource.values())
.source("other")
.build();JustAuth continues to add new platforms, and developers can contribute to its growth.
Programmer DD
A tinkering programmer and author of "Spring Cloud Microservices in Action"
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
