안드로이드
구글플레이 유저 토큰 서버 인증
래머
2016. 10. 28. 14:02
원문 : https://developers.google.com/identity/sign-in/web/backend-auth
구글플레이 서비스 SDK를 통해서 클라이언트측에서 로그인하고 인증 정보를 서버로 넘겨서 서버측에서 클라이언트의 인증 정보를 검증하는 방법은 아래와 같다.
https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=XYZ123
위주소의 XYZ123부분에 클라이언트가 보내온 액세스 토큰을 넣고 Post또는 Get요청을 보내면 응답을 받을 수 있다.
HTTP 200응답이 수신될경우 JSON포맷의 결과 값을 받게 되고, 대략 아래와 같은 형태이다.
{ // These six fields are included in all Google ID Tokens. "iss": "https://accounts.google.com", "sub": "110169484474386276334", "azp": "1008719970978-hb24n2dstb40o45d4feuo2ukqmcc6381.apps.googleusercontent.com", "aud": "1008719970978-hb24n2dstb40o45d4feuo2ukqmcc6381.apps.googleusercontent.com", "iat": "1433978353", "exp": "1433981953", // These seven fields are only included when the user has granted the "profile" and // "email" OAuth scopes to the application. "email": "testuser@gmail.com", "email_verified": "true", "name" : "Test User", "picture": "https://lh4.googleusercontent.com/-kYgzyAWpZzJ/ABCDEFGHI/AAAJKLMNOP/tIXL9Ir44LE/s99-c/photo.jpg", "given_name": "Test", "family_name": "User", "locale": "en" }이중에서 aud값에 앱의 클라이언트 ID를 담고 있는데 일치 하는지 확인하고 일치한다면,
sub 항목을 유저의 ID로 사용하면된다. sub항목은 구글에서 개인을 식별할 수 있는 유니크 ID이다.