signUp with Google、Amazon、Apple

 Google

1.搭建开发环境

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

2.请求 code

需要的参数:

client_id

redirect_uri

response_type

scope

其中,client_id是在第一步中创建凭据的时候得到的,向Google 授权服务器发送如下信息则可以获取到code

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

使用浏览器访问到上面的网址,点击确认授权以后,则可以获取一段

code 需要url decode!!!

response_type = token 可直接获取access_token

 3.请求access token

通过向Google发送post 请求,来获得access token

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

需要的参数: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来重新获取。发送HTTP POST请求:

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

需要的参数:

refresh_token = XX

client_id = XX

client_secret = XX

grant_type = XX

发送请求的格式如下:

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.搭建开发环境

客户端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

参数 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

 参数 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

 参数 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解析得出

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值