signUpwithGoogle、Amazon、Apple-創(chuàng)新互聯(lián)

?Google 1.搭建開(kāi)發(fā)環(huán)境

https://console.cloud.google.com/https://console.cloud.google.com/配置一個(gè)project,得到clientID、clientSecret,填寫(xiě)redirect_uri:

創(chuàng)新互聯(lián)"三網(wǎng)合一"的企業(yè)建站思路。企業(yè)可建設(shè)擁有電腦版、微信版、手機(jī)版的企業(yè)網(wǎng)站。實(shí)現(xiàn)跨屏營(yíng)銷(xiāo),產(chǎn)品發(fā)布一步更新,電腦網(wǎng)絡(luò)+移動(dòng)網(wǎng)絡(luò)一網(wǎng)打盡,滿(mǎn)足企業(yè)的營(yíng)銷(xiāo)需求!創(chuàng)新互聯(lián)具備承接各種類(lèi)型的網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站項(xiàng)目的能力。經(jīng)過(guò)十多年的努力的開(kāi)拓,為不同行業(yè)的企事業(yè)單位提供了優(yōu)質(zhì)的服務(wù),并獲得了客戶(hù)的一致好評(píng)。2.請(qǐng)求 code

需要的參數(shù):

client_id

redirect_uri

response_type

scope

其中,client_id是在第一步中創(chuàng)建憑據(jù)的時(shí)候得到的,向Google 授權(quán)服務(wù)器發(fā)送如下信息則可以獲取到code

https://accounts.google.com/o/oauth2/auth?client_id=XXX&redirect_uri=XXX&scope=email&response_type=code

使用瀏覽器訪(fǎng)問(wèn)到上面的網(wǎng)址,點(diǎn)擊確認(rèn)授權(quán)以后,則可以獲取一段

code 需要url decode?。?!

response_type = token 可直接獲取access_token

3.請(qǐng)求access token

通過(guò)向Google發(fā)送post 請(qǐng)求,來(lái)獲得access token

https://accounts.google.com/o/oauth2/tokenhttps://accounts.google.com/o/oauth2/token

需要的參數(shù):POST

code = XXX

client_id = XXX

cilent_secret = XXX

redirect_uri = XXX

grant_type = authorization_code

如果成功以后,我們會(huì)收到JSON格式的Response:

{
    "access_token": "xxx",
    "expires_in": 3600,
    "scope": "openid https://www.googleapis.com/auth/userinfo.email",
    "token_type": "Bearer",
    "id_token": "xxx"
}
4.使用refresh token來(lái)刷新access token

當(dāng)access_token失效的時(shí)候,我們需要通過(guò)refresh_token來(lái)重新獲取。發(fā)送HTTP POST請(qǐng)求:

https://www.googleapis.com/oauth2/tokenhttps://www.googleapis.com/oauth2/v4/token

需要的參數(shù):

refresh_token = XX

client_id = XX

client_secret = XX

grant_type = XX

發(fā)送請(qǐng)求的格式如下:

POST

請(qǐng)求成功之后,會(huì)多的JOSN格式的Response,如下:

{ 
"access_token": "xxx", 
"token_type": "Bearer", 
"expires_in": 3600 
}

因?yàn)榉?wù)器對(duì)refresh_token的請(qǐng)求有限制,如果過(guò)多的請(qǐng)求會(huì)導(dǎo)致請(qǐng)求失敗的情況。所以需要長(zhǎng)期保存refresh_token,只要refresh_token沒(méi)有失效,就沒(méi)有必要多次請(qǐng)求。

5. 獲取profile

https://openidconnect.googleapis.com/v1/userinfohttps://openidconnect.googleapis.com/v1/userinfo

Header :

Authorization = Bearer ya29.****

{ "sub": "****", 
"picture": "https://lh3.googleusercontent.com/****", 
"email": "****", 
"email_verified": true 
}
Amazon

官方獲取code 文檔地址:

https://developer.amazon.com/zh/docs/login-with-amazon/authorization-code-grant.htmlhttps://developer.amazon.com/zh/docs/login-with-amazon/authorization-code-grant.html

1.搭建開(kāi)發(fā)環(huán)境

客戶(hù)端ID:amzn1.xx

客戶(hù)端密鑰:xxxx

2.請(qǐng)求code

https://www.amazon.com/ap/oa?client_id=***&scope=profile&response_type=code&state=email&redirect_uri=http://localhost:8080/

3.請(qǐng)求access_token

POST https://api.amazon.com/auth/o2/token

參數(shù) x-www-form-urlencoded

grant_type:?authorization_code

code: xxx

client_id: xxx

client_secret: xxx

redirect_uri: localhost:8080

返回:

{
    "access_token": "",
    "refresh_token": "",
    "token_type": "bearer",
    "expires_in": 3600
}
4.刷新token

POST https://api.amazon.com/auth/o2/token

參數(shù) x-www-form-urlencoded

grant_type:?refresh_token

client_id: xxx

client_secret: xxx

refresh_token: xxx

5.獲取profile

GET https://api.amazon.com/user/profile?access_token=xxx

{
    "user_id": "",
    "name": "",
    "email": ""
}
Apple

Apple Developer Documentationhttps://developer.apple.com/documentation/sign_in_with_apple/sign_in_with_apple_rest_api/authenticating_users_with_sign_in_with_apple

1.配置項(xiàng)

client_id: xx

client_secret: jwt token形式的

Team ID: xx

key ID: xx

P8 key 私鑰:xx

redirect_uri: xx

2.請(qǐng)求code?

https://appleid.apple.com/auth/authorize?response_mode=query&state=xx&response_type=code&client_id=xx&redirect_uri=xx

3.獲取token

POST https://appleid.apple.com/auth/token

參數(shù) x-www-form-urlencoded

grant_type:?authorization_code

code: xxx

client_id: xxx

client_secret: xxx

redirect_uri: localhost:8080

client_secret 就是自己用腳本生成的jwt token 可參考Apple Developer Documentation

{
    "access_token": "",
    "token_type": "Bearer",
    "expires_in": 3600,
    "refresh_token": "",
    "id_token": ""
}

用戶(hù)信息通過(guò)id_token解析得出

你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級(jí)服務(wù)器適合批量采購(gòu),新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧

網(wǎng)站題目:signUpwithGoogle、Amazon、Apple-創(chuàng)新互聯(lián)
標(biāo)題鏈接:http://www.bm7419.com/article40/ihieo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊(cè)、標(biāo)簽優(yōu)化品牌網(wǎng)站建設(shè)、品牌網(wǎng)站設(shè)計(jì)響應(yīng)式網(wǎng)站、App開(kāi)發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)