signUpwithGoogle、Amazon、Apple-创新互联
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. 获取profilehttps://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.请求codehttps://www.amazon.com/ap/oa?client_id=***&scope=profile&response_type=code&state=email&redirect_uri=http://localhost:8080/
3.请求access_tokenPOST 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.刷新tokenPOST 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.获取profileGET https://api.amazon.com/user/profile?access_token=xxx
{
"user_id": "",
"name": "",
"email": ""
}
AppleApple 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.请求codehttps://appleid.apple.com/auth/authorize?response_mode=query&state=xx&response_type=code&client_id=xx&redirect_uri=xx
3.获取tokenPOST 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解析得出
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧
文章标题:signUpwithGoogle、Amazon、Apple-创新互联
文章地址:http://cdiso.cn/article/ihieo.html