Ai
1.1K Star 10.5K Fork 3.2K

GVPyadong.zhang/JustAuth

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
PkceUtil.java 1.26 KB
一键复制 编辑 原始数据 按行查看 历史
yadong.zhang 提交于 2021-03-13 23:10 +08:00 . :egg:添加 amazon 平台
package me.zhyd.oauth.utils;
import java.nio.charset.StandardCharsets;
/**
* 该配置仅用于支持 PKCE 模式的平台,针对无服务应用,不推荐使用隐式授权,推荐使用 PKCE 模式
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0.0
* @since 1.0.0
*/
public class PkceUtil {
public static String generateCodeVerifier() {
String randomStr = RandomUtil.randomString(50);
return Base64Utils.encodeUrlSafe(randomStr);
}
/**
* 适用于 OAuth 2.0 PKCE 增强协议
*
* @param codeChallengeMethod s256 / plain
* @param codeVerifier 客户端生产的校验码
* @return code challenge
*/
public static String generateCodeChallenge(String codeChallengeMethod, String codeVerifier) {
if ("S256".equalsIgnoreCase(codeChallengeMethod)) {
// https://tools.ietf.org/html/rfc7636#section-4.2
// code_challenge = BASE64URL-ENCODE(SHA256(ASCII(code_verifier)))
return newStringUsAscii(Base64Utils.encodeUrlSafe(Sha256.digest(codeVerifier), true));
} else {
return codeVerifier;
}
}
public static String newStringUsAscii(byte[] bytes) {
return new String(bytes, StandardCharsets.US_ASCII);
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/yadong.zhang/JustAuth.git
git@gitee.com:yadong.zhang/JustAuth.git
yadong.zhang
JustAuth
JustAuth
master

搜索帮助