最近在做海外市场的应用,接入Google登录认证。

  1. 客户端接入:get token(client): https://stackoverflow.com/questions/37107847/how-to-get-google-oauth-2-0-access-token-directly-using-curl-without-using-goo
  2. 服务端验证:verify token(server): https://stackoverflow.com/questions/359472/how-can-i-verify-a-google-authentication-api-access-token
1
2
3
4
5
6
7
8
9
# How to get Google OAuth 2.0 Access token directly using curl? (without using Google Libraries)
curl -d "client_id=MY_CLIENT_ID&\
  client_secret=MY_SECRET_KEY&\
  redirect_uri=http://localhost/etc&\
  grant_type=authorization_code&\
  code=CODE" https://oauth2.googleapis.com/token

# How can I verify a Google authentication API access token?
curl 'https://oauth2.googleapis.com/tokeninfo?id_token=XYZ123'

PS: Android 接入:https://firebase.google.com/docs/auth/android/manage-users?hl=zh-cn

返回字段含义:https://developers.google.com/identity/protocols/oauth2/openid-connect

PS:返回值中的sub是唯一的,长度最大可以达到255字符