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

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

https://console.cloud.google.com/https://console.cloud.google.com/配置一個project,得到clientID、clientSecret,填寫redirect_uri:

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

需要的參數(shù):

client_id

redirect_uri

response_type

scope

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

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

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

code 需要url decode!?。?/p>

response_type = token 可直接獲取access_token

3.請求access token

通過向Google發(fā)送post 請求,來獲得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

如果成功以后,我們會收到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來刷新access token

當access_token失效的時候,我們需要通過refresh_token來重新獲取。發(fā)送HTTP POST請求:

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ā)送請求的格式如下:

POST

請求成功之后,會多的JOSN格式的Response,如下:

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

因為服務器對refresh_token的請求有限制,如果過多的請求會導致請求失敗的情況。所以需要長期保存refresh_token,只要refresh_token沒有失效,就沒有必要多次請求。

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.搭建開發(fā)環(huán)境

客戶端ID:amzn1.xx

客戶端密鑰:xxxx

2.請求code

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

3.請求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.配置項

client_id: xx

client_secret: jwt token形式的

Team ID: xx

key ID: xx

P8 key 私鑰:xx

redirect_uri: xx

2.請求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": ""
}

用戶信息通過id_token解析得出

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

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

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

廣告

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

手機網(wǎng)站建設