久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

invalid_client 用于使用蘋果登錄

invalid_client for sign in with apple(invalid_client 用于使用蘋果登錄)
本文介紹了invalid_client 用于使用蘋果登錄的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我想達(dá)到的目標(biāo):

  • iOS 客戶端向后端發(fā)送 JWT 令牌.
  • 后端 (Java) 調(diào)用 https://appleid.apple.com/auth/token驗(yàn)證令牌.

到目前為止我所擁有的:

撥打 Apple 驗(yàn)證電話:

 restTemplate = new RestTemplate();HttpHeaders 標(biāo)頭 = 新的 HttpHeaders();headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);多值映射<字符串,字符串>map = new LinkedMultiValueMap<>();map.add("client_id", clientId);//app_id 像 com.app.id字符串令牌 = generateJWT();//生成的 jwtmap.add("client_secret", token);map.add("grant_type", "authorization_code");map.add("code", authorizationCode);//我們從 iOS 獲得的 JWT 代碼HttpEntity<MultiValueMap<字符串,字符串>>request = new HttpEntity<>(map, headers);最終字符串 appleAuthURL = "https://appleid.apple.com/auth/token";字符串響應(yīng) = restTemplate.postForObject(appleAuthURL, request, String.class);

代幣生成:

 final PrivateKey privateKey = getPrivateKey();最終 int 到期 = 1000 * 60 * 5;字符串令牌 = Jwts.builder().setHeaderParam(JwsHeader.KEY_ID, keyId)//我從 Apple 獲得的密鑰 id.setIssuer(teamId).setAudience("https://appleid.apple.com").setSubject(clientId)//應(yīng)用 id com.app.id.setExpiration(new Date(System.currentTimeMillis() + expire)).setIssuedAt(新日期(System.currentTimeMillis())).signWith(SignatureAlgorithm.ES256, privateKey)//ECDSA 使用 P-256 和 SHA-256.袖珍的();返回令牌;

從文件中獲取我的私鑰:

 final Reader pemReader = new StringReader(getKeyData());最終 PEMParser pemParser = 新 PEMParser(pemReader);最終 JcaPEMKeyConverter 轉(zhuǎn)換器 = 新 JcaPEMKeyConverter();最終 PrivateKeyInfo 對(duì)象 = (PrivateKeyInfo) pemParser.readObject();最終 PrivateKey pKey = converter.getPrivateKey(object);

我確認(rèn)我的 JWT 具有所有必填字段:

<代碼>{"kid": "與我的鑰匙 ID 相同的鑰匙",alg":ES256"}{"iss": "廢話","aud": "https://appleid.apple.com",子":com.app.id",exp":1578513833,iat":1578513533}

解決方案

這行引起了我的注意:

map.add("code", authorizationCode);//我們從 iOS 獲得的 JWT 代碼

authorizationCode 不是 jwt

JSON Web Tokens 由 3 個(gè)部分組成,用點(diǎn)分隔

authorizationCode 有 4 個(gè)部分,如下所示:

text1.text2.0.text3

您可能正在使用 iOS 應(yīng)用程序中的 identityToken 而不是 authorizationCode

這是您檢索它的方式:

let authorizationCode = String(data: appleIDCredential.authorizationCode!, encoding: .utf8)!打印(授權(quán)碼:(授權(quán)碼)")

對(duì)于那些在遇到相同的 invalid_client 錯(cuò)誤后可能來到這里的人來說,記住以下幾點(diǎn)也很好:

<塊引用>

  1. kid 是 developer.apple.com/account/resources/authkeys/list 中私鑰的 ID

  2. keyFile 是保存從 developer.apple.com 下載的私鑰的文件

  3. 登錄developer.apple.com點(diǎn)擊賬號(hào)可以找到teamID,右上角可以看到teamID

  4. aud 中的值應(yīng)該是https://appleid.apple.com

  5. app_id 是應(yīng)用程序的包標(biāo)識(shí)符

如果它可能有幫助,這里有一個(gè)在 python 中創(chuàng)建 client_secret 的可行解決方案:

# $ pip install pyjwt導(dǎo)入 jwt進(jìn)口時(shí)間孩子=myKeyId"keyFile = "/pathToFile/AuthKey.p8";鍵="使用 open(keyFile, 'r') 作為 myFile:鍵 = myFile.read()打印(鍵)timeNow = int(round(time.time()))time3Months = timeNow + 86400*90索賠= {'iss':團(tuán)隊(duì)ID,'iat':時(shí)間現(xiàn)在,'exp': time3Months,'aud': 'https://appleid.apple.com',子":app_id,}秘密= jwt.encode(聲明,密鑰,算法='ES256',標(biāo)題={'kid':kid})打印(秘密:")打印(秘密)client_secret = secret.decode("utf-8")打印(client_secret)

What I try to achieve:

  • iOS client sends a JWT token to the backend.
  • Backend (Java) calls https://appleid.apple.com/auth/token to verify the token.

what I have so far:

to make Apple verification call:

        restTemplate = new RestTemplate();

        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
        MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
        map.add("client_id", clientId); // app_id like com.app.id
        String token = generateJWT();   // generated jwt
        map.add("client_secret", token); 
        map.add("grant_type", "authorization_code");
        map.add("code", authorizationCode);  // JWT code we got from iOS
        HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers);

        final String appleAuthURL = "https://appleid.apple.com/auth/token";
        String response = restTemplate.postForObject(appleAuthURL, request, String.class);

token generation:

        final PrivateKey privateKey = getPrivateKey();
        final int expiration = 1000 * 60 * 5;

        String token = Jwts.builder()
                .setHeaderParam(JwsHeader.KEY_ID, keyId) // key id I got from Apple 
                .setIssuer(teamId)  
                .setAudience("https://appleid.apple.com")
                .setSubject(clientId) // app id com.app.id
                .setExpiration(new Date(System.currentTimeMillis() + expiration))
                .setIssuedAt(new Date(System.currentTimeMillis()))
                .signWith(SignatureAlgorithm.ES256, privateKey) // ECDSA using P-256 and SHA-256
                .compact();

        return token;

to get my private key from the file:

        final Reader pemReader = new StringReader(getKeyData());
        final PEMParser pemParser = new PEMParser(pemReader);
        final JcaPEMKeyConverter converter = new JcaPEMKeyConverter();
        final PrivateKeyInfo object = (PrivateKeyInfo) pemParser.readObject();
        final PrivateKey pKey = converter.getPrivateKey(object);

I confirmed my JWT has all required fields:

{
  "kid": "SAME KEY AS MY KEY ID",
  "alg": "ES256"
}

{
  "iss": "Blahblah",
  "aud": "https://appleid.apple.com",
  "sub": "com.app.id",
  "exp": 1578513833,
  "iat": 1578513533
}

解決方案

This line caught my attention:

map.add("code", authorizationCode);  // JWT code we got from iOS

The authorizationCode is not a jwt

JSON Web Tokens consist of 3 parts separated by dots

but the authorizationCode has 4 parts like this:

text1.text2.0.text3

You are probably using the identityToken from the iOS app instead of the authorizationCode

This is how you retrieve it:

let authorizationCode = String(data: appleIDCredential.authorizationCode!, encoding: .utf8)!
print("authorizationCode: (authorizationCode)")

Also good to have the following in mind for those who might come here after getting the same invalid_client error:

  1. kid is the id for the private key from developer.apple.com/account/resources/authkeys/list

  2. keyFile is the file holding the private key downloaded from developer.apple.com

  3. teamID can be found by logging in to developer.apple.com and clicking on account, the teamID can be seen in the upper right corner

  4. the value in aud should be https://appleid.apple.com

  5. app_id is the bundle identifier for the app

In case it might help, here is a working solution in python to create a client_secret:

# $ pip install pyjwt
import jwt
import time

kid = "myKeyId"  
keyFile = "/pathToFile/AuthKey.p8"
key = ""
with open(keyFile, 'r') as myFile:
    key = myFile.read()

print(key)

timeNow = int(round(time.time()))
time3Months = timeNow + 86400*90

claims = {
    'iss': teamID,
    'iat': timeNow,
    'exp': time3Months,
    'aud': 'https://appleid.apple.com',
    'sub': app_id,
}


secret = jwt.encode(claims, key, algorithm='ES256', headers={'kid': kid})
print("secret:")
print(secret)
client_secret = secret.decode("utf-8")
print(client_secret)

這篇關(guān)于invalid_client 用于使用蘋果登錄的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環(huán)繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動(dòng)生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數(shù)據(jù)庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對(duì)象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 91中文在线观看 | 免费黄色片视频 | 爱爱免费视频 | 国产日韩精品一区二区三区 | 精品视频在线播放 | 久久激情网 | 亚洲天堂成人在线视频 | 亚洲精品乱码久久久久久按摩观 | 久久99精品久久久久久国产越南 | 色综合激情 | 国产目拍亚洲精品99久久精品 | 伊人精品一区二区三区 | 日本一区二区三区四区 | 亚洲免费人成在线视频观看 | 午夜看片 | 日韩精品三区 | 国产精品视频一二三区 | 亚洲一区视频在线 | 91在线播 | 欧美一级淫片007 | 久久久久久久一区 | 中文字幕乱码一区二区三区 | 国产一区二区久久 | 日韩一区二区三区四区五区六区 | 福利视频一区 | 欧美日韩精品免费观看 | 亚洲国产精品一区 | 亚洲视频区 | 欧美精品在线免费观看 | 久久网亚洲 | 亚洲福利一区 | 一区天堂 | 国产高清在线精品一区二区三区 | 极品的亚洲 | 亚洲精品一区二区三区中文字幕 | 欧美日韩中文字幕 | 国产精品九九九 | 国产一二区在线 | 国产日韩欧美中文 | 欧美日韩亚洲一区二区 | 精品不卡 |