惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
The Last Watchdog
The Last Watchdog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
T
Tailwind CSS Blog
Engineering at Meta
Engineering at Meta
F
Fortinet All Blogs
Martin Fowler
Martin Fowler
Y
Y Combinator Blog
N
Netflix TechBlog - Medium
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
C
Check Point Blog
Apple Machine Learning Research
Apple Machine Learning Research
人人都是产品经理
人人都是产品经理
爱范儿
爱范儿
V
V2EX
小众软件
小众软件
T
The Exploit Database - CXSecurity.com
S
Security Affairs
H
Help Net Security
Project Zero
Project Zero
K
Kaspersky official blog
D
DataBreaches.Net
I
Intezer
The Cloudflare Blog
MyScale Blog
MyScale Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Microsoft Azure Blog
Microsoft Azure Blog
L
LangChain Blog
N
News and Events Feed by Topic
TaoSecurity Blog
TaoSecurity Blog
GbyAI
GbyAI
Hacker News - Newest:
Hacker News - Newest: "LLM"
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
P
Palo Alto Networks Blog
Latest news
Latest news
V
Vulnerabilities – Threatpost
Hugging Face - Blog
Hugging Face - Blog
C
Cybersecurity and Infrastructure Security Agency CISA
月光博客
月光博客
The Register - Security
The Register - Security
云风的 BLOG
云风的 BLOG
S
Schneier on Security
阮一峰的网络日志
阮一峰的网络日志
P
Proofpoint News Feed
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
A
About on SuperTechFans
MongoDB | Blog
MongoDB | Blog
aimingoo的专栏
aimingoo的专栏

OAuth

授权码 + PKCE 模式| OIDC & OAuth2.0 认证协议最佳实践系列 [03] - V2EX OIDC & OAuth2.0 协议及其授权模式详解|认证协议最佳实践系列 [1] - V2EX OIDC & OAuth2.0 认证协议最佳实践系列 02 - 授权码模式(Authorization Code)接入 Authing - V2EX 腾讯的网页授权真难申请,微博秒搞定! - V2EX 关于 native 应用程序在使用 OAuth 2.0 的一些问题 如何创建一个 OAuth 服务 - V2EX 在oauth1.0中签名的话必须有consumer_key 与consumer_secret ,这样的话在桌面应用中岂不是这两个都给暴漏了 OAuth.io - V2EX OAuth 2.0 - V2EX weibo的OAuth问题 - V2EX 腾讯微博的OAuth问题...... - V2EX 搞定 OAuth 的感觉实在是太爽了 - V2EX img.ly API
Java 小小写个开源 OAuth 客户端工具 - V2EX
hanbings · 2023-01-06 · via OAuth

目前正在适配常见的国外平台,迟一些会做国内的像 QQ 微信 WB 百度 阿里 什么的

欢迎 Star 跟进! Github:Fluocean

Fluocean

主要特性:

  • 常见的 OAuth 平台适配
  • 支持自定义 State 生成器、自定义 Http 客户端、自定义 Json 解析器
  • 提供通用默认实现以便支持未适配 OAuth 平台
  • 默认 Http 客户端实现支持 Socks 代理
  • 可爱

Github OAuth 示例

洋流提供了许多的重载方法,用于应对不同情况下的请求,有些带自有请求头的,也有要求必须要 Scope 的。

// 创建 OAuth 原始处理器
OAuth<GithubAccess, GithubAccess.Wrong> oauth = new GithubOAuth(
	"id",
	"secret",
	"https://exmaple.com/api/v0/login/oauth/github/callback"
);

// 生成授权 url
String url = oauth.authorize();
// 生成带参数或指定 scope
String spec = oauth.authorize(List.of("email"), Map.of("Accept", "application/json"));
        
//解析回调的 url 并获取 token
// 输入原始 url 自动解析 code 以及 state
oauth.token("url");
// 更改回调地址
oauth.token("url", "redirect");
// 手动指定参数
oauth.token("code", "state", "redirect");
        
// 处理返回值
oauth.token("code", "state", "redirect")
	.succeed(data -> System.out.println(data.accessToken()))
	.fail(wrong -> System.out.println(wrong.errorDescription()))
	.except(throwable -> System.out.println(throwable.getMessage()));
        
// 假设请求成功 直接获取数据
GithubAccess access = oauth.token("code", "state", "redirect").data();

使用 Socks 代理

oauth.proxy(() ->
	new Request.Proxy(
		Proxy.Type.SOCKS,
		"127.0.0.1",
		10086,
		"username",
		"password"
	)
);

更换 State 生成器

默认随机生成 UUID 并设置 300 秒有效期

oauth.state(
    Lazy.of(() -> new OAuthState(300, () -> UUID.randomUUID().toString()))
);

更换 Http 客户端

默认使用 Okhttp 发起请求

// 实现比较繁杂 就不展示啦 x
oauth.request(Lazy.of(OAuthRequest::new));

更换 Json 解析器

默认使用 Gson 作为 Json 解析器

oauth.serialization(
	Lazy.of(() -> new Serialization() {
		final Gson gson = new Gson();

		@Override
		public <T> T object(Class<T> type, String raw) {
			return gson.fromJson(raw, type);
		}

		@Override
		public <K, V> Map<K, V> map(Class<K> key, Class<V> value, String raw) {
			return gson.fromJson(raw, new TypeToken<Map<K, V>>() {
			}.getType());
		}

		@Override
		public <T> List<T> list(Class<T> type, String raw) {
			return gson.fromJson(raw, new TypeToken<List<T>>() {
			}.getType());
		}
	})
);