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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Unity3D是一款流行的跨平台游戏开发引擎,支持多种移动平台和操作系统。最近,苹果推出了“Sign in with Apple”功能,该功能允许用户使用其Apple ID来登录第三方应用程序。 要在Unity3D中接入“Sign in with Apple”功能,需要遵循以下步骤: 1. 首先,确保你的Unity3D版本是最新的,以便能够支持最新的API和功能。 2. 在苹果开发者平台上创建一个新的App ID,并将其与你的Unity3D项目关联。确保在App ID设置中启用“Sign in with Apple”功能。 3. 在Unity3D中,编写代码以实现与苹果登录服务通信的逻辑。你需要使用Unity内置的网络API,通过发送HTTP请求和接收回复来实现与苹果服务器的通信。 4. 在Unity3D项目中创建一个用户界面,允许用户点击“Sign in with Apple”按钮。当用户点击这个按钮时,你的代码将向苹果服务器发送请求,获取用户的验证凭证。 5. 将从苹果服务器接收到的验证凭证与你的后端服务器通信。你的后端服务器需要验证这个凭证的有效性,并通过向苹果服务器发送请求获得用户的基本信息。 6. 在Unity3D中使用这些用户信息,例如显示用户的用户名、头像等。 需要注意的是,为了保护用户的隐私,苹果有一些要求和限制,开发人员需要遵守这些规定,例如要求提供“其他登录选项”以及对于用户与苹果登录服务的数据处理等。 总结:要在Unity3D中接入“Sign in with Apple”功能,你需要使用最新版本的Unity3D、遵循苹果开发者平台的规定、实现与苹果服务器的通信逻辑、创建用户界面、验证凭证、获取用户信息,并遵守苹果的隐私规定。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值