APP端苹果登录java后端校验

主要校验苹果授权登录token 是否正确

主要方法

public RSAPublicKeySpec build(final String n, final String e) {

final BigInteger modulus = new BigInteger(1, Base64.decodeBase64(n));

final BigInteger publicExponent = new BigInteger(1, Base64.decodeBase64(e));

return new RSAPublicKeySpec(modulus, publicExponent);

}

public int verify(final PublicKey key, final String jwt, final String audience, final String subject) {

final JwtParser jwtParser = Jwts.parser().setSigningKey(key);

jwtParser.requireIssuer("https://appleid.apple.com");

jwtParser.requireAudience(audience);

jwtParser.requireSubject(subject);

try {

final Jws claim = jwtParser.parseClaimsJws(jwt);

if (claim != null && claim.getBody().containsKey("auth_time")) {

claims = claim;

log.info("[Apple登录解密结果]header:{},body:{},signature:{}", claim.getHeader(), claim.getBody(),

claim.getSignature());

return 1;

}

return 0;

} catch (final ExpiredJwtException e) {

log.error("apple identityToken expired");

return -1;

} catch (final Exception e) {

log.error("apple identityToken illegal");

return -2;

}

}

/**

* 从hex string生成公钥

*

* @param stringN

* @param stringE

* @return 构造好的公钥

* @throws NoSuchAlgorithmException

* @throws InvalidKeySpecException

*/

public static PublicKey createPublicKey(final String stringN, final String stringE)

throws NoSuchAlgorithmException, InvalidKeySpecException {

try {

// BigInteger N = new BigInteger(stringN, 16); // hex base

// BigInteger E = new BigInteger(stringE, 16); // hex base

final BigInteger modulus = new BigInteger(1, Base64.decodeBase64(stringN));

final BigInteger publicExponent = new BigInteger(1, Base64.decodeBase64(stringE));

final RSAPublicKeySpec spec = new RSAPublicKeySpec(modulus, publicExponent);

final KeyFactory kf = KeyFactory.getInstance("RSA");

return kf.generatePublic(spec);

} catch (final Exception e) {

e.printStackTrace();

}

return null;

}

需要引用到的pom包

io.jsonwebtoken

jjwt

0.9.1

com.alibaba

fastjson

1.2.30

org.apache.httpcomponents

httpclient

com.javabase64

javabase64

1.3.1

commons-lang

commons-lang

2.6

Java Apple_GitHub - izhaorui/AppleLogin-java: 苹果登录 Sign in with Apple 服务端校验相关推荐

  1. ios 登录 java 后台,IOS苹果登录sign in with apple后端校验

    IOS苹果登录sign in with apple后端校验 最近新开发的app在IOS平台app store connent提审的时候,被拒了,原因是app上如果有接第三方登陆(比如微信,微博,fac ...

  2. iOS 苹果登录 Sign in with apple Swift

    iOS 苹果登录 Sign in with apple Swift 话不多说,直接看功能类,解释代码里有 import UIKit import AuthenticationServices @ava ...

  3. 最新苹果服务器认证,iOS 苹果登录Sign in with Apple 和 服务端验证(nodejs 版)

    Sign in with Apple 服务端要做的其实很简单 nodejs需要装三个东西 npm install node-rsa npm install axios npm install json ...

  4. 【iOS】苹果登录Sign in with Apple

    在iOS13中,如果苹果开发者提供任何其他第三方登录,就必须提供"苹果登录"选项.也就是说,如果软件要求"微信登录"或是"QQ登录"时,必须 ...

  5. 苹果登录 Sign In with Apple

    <?php /*** Sign in with Apple 示例* composer安装: composer require griffinledingham/php-apple-signin* ...

  6. IONIC4 苹果登录-Sign In With Apple Id

    最近上架APP被苹果拒绝,理由是使用第三方登录需加上苹果登录,否则不给上架,所以在这分享一下ionic4的苹果登录 首先安装cordova插件,获取系统版本插件 ionic cordova plugi ...

  7. 苹果授权登录Sign In With Apple亲测通过版[100%成功]

    苹果授权登录Sign In With Apple后台代码实现JAVA版本亲测通过版 废话不多说,直接复制把自己的包名写上就可以用了 有个别的小坑,HttpUtil自己写,没附上 Base64一定要用o ...

  8. Uniapp苹果登录sign in Apple

    Uniapp苹果登录sign in Apple 前提:软件内,如果已经实现第三方登录,必须也有sign in Apple功能,否则审核会不通过 准备工作:uniapp自带sign in Apple必须 ...

  9. Java 生成二维码 zxing生成二维码 条形码 服务端生成二维码 Java生成条形码

    Java 生成二维码 zxing生成二维码 条形码 服务端生成二维码 Java生成条形码 一.关于ZXing 1.ZXing是谷歌开源的支持二维码.条形码 等图形的生成类库:支持生成.和解码功能. G ...

最新文章

  1. python使用matplotlib可视化3D线框图、线框图可以将数据投影到指定的三维表面上,并输出可视化程度较高的三维效果图
  2. java-mybaits-00101-基础安装配制
  3. 如何检测出定制服务器中预装的恶意软件?
  4. python使用笔记(一)——遍历文件夹下的所有子目录
  5. 上传本地代码到gitHub过程详解
  6. python编程基础怎么学英语_英语不行而且从没碰过编程,如何0基础学python?
  7. c语言编程思维训练50题,c语言逻辑思维训练题一
  8. RabbitMQ(六):回调队列callback queue、关联标识correlation id、实现简单的RPC系统
  9. Vue014_ vue  项目的打包与发布
  10. 【leetcode dp】629. K Inverse Pairs Array
  11. Python学习日记(3)Python内建函数map()、filter()和匿名函数表达式
  12. web mysql数据库的持久连接_JavaWeb连接数据库MySQL的操作技巧
  13. 总算知道怎样从ImageMagick生成的数据转换成HICON: MagickGetImageBlob LookupIconIdFromDirectoryEx...
  14. JQuery:JQuery遍历详解
  15. POSIX:可移植操作系统接口(Portable Operating System Interface of UNIX,缩写为 POSIX )
  16. layui遇见的问题
  17. virtualenv -p python3 venv报错
  18. handler回调主线程_Handler源码和9个常见问题的解答,这些你都掌握了吗?
  19. linux 文件系统的简单操作
  20. clickhouse 新增列_# 记录一次clickhouse表新增字段遇到的问题

热门文章

  1. Logistic回归和SVM的异同
  2. LCD显示屏原理与应用
  3. nginx1.10.2源码安装配置参数参考
  4. HTML 5 input placeholder 属性
  5. 怀念一下过去的人和事
  6. iphone开发之C++和Objective-C混编
  7. select * 排除字段_编写 SQL 的排除联接
  8. python自带的编辑器怎么换行_Python3基础 print 自带换行功能
  9. as模拟器文件夹路径_EGG Switch手机模拟器怎么用?中文教程来了......
  10. wrf 嵌套网格作用_在网格系统中使用响应列,嵌套列和偏移列 引导程序