이전에 GoogleAuthUtil.getToken 또는 Plus.API를 사용하여 Google 로그인과 통합했다면 보안 강화와 사용자 환경을 향상하기 위해 최신 Sign-In API로 이전해야 합니다.
액세스 토큰 역패턴에서 마이그레이션
GoogleAuthUtil.getToken로 가져온 액세스 토큰을 백엔드 서버에 ID 어설션으로 전송해서는 안 됩니다. 토큰이 백엔드에 발급되었는지 쉽게 확인할 수 없으므로 공격자가 액세스 토큰을 삽입할 수 있기 때문입니다.
예를 들어 Android 코드가 아래 예와 같다면 앱을 최신 권장사항으로 이전해야 합니다.
이 예에서 액세스 토큰 요청은 oauth2:과 범위 문자열을 GoogleAuthUtil.getToken 호출(oauth2:https://www.googleapis.com/auth/plus.login)의 scope 매개변수로 사용합니다.
GoogleAuthUtil.getToken로 획득한 액세스 토큰으로 인증하는 대신 ID 토큰 흐름 또는 인증 코드 흐름을 사용하세요.
ID 토큰 흐름으로 이전
사용자 ID, 이메일 주소, 이름 또는 프로필 사진 URL만 필요하다면 ID 토큰 흐름을 따르세요.
ID 토큰 흐름으로 이전하려면 다음을 변경하세요.
Android 클라이언트 측
요청하는 경우 GET_ACCOUNTS (연락처) 권한 삭제
GoogleAuthUtil, Plus.API, AccountPicker.newChooseAccountIntent() 또는 AccountManager.newChooseAccountIntent()를 사용하는 코드를 GoogleSignInOptions.Builder.requestIdToken(...) 구성으로 Auth.GOOGLE_SIGN_IN_API로 전환합니다.
서버에서 Google Drive, YouTube, 연락처와 같은 다른 Google API에 액세스해야 하는 경우 서버 인증 코드 흐름을 사용하세요.
서버 인증 코드 흐름으로 이전하려면 다음과 같이 변경합니다.
Android 클라이언트 측
GET_ACCOUNTS (연락처) 권한 요청 시 삭제
GoogleAuthUtil, Plus.API, AccountPicker.newChooseAccountIntent() 또는 AccountManager.newChooseAccountIntent()를 사용하는 코드를 GoogleSignInOptions.Builder.requestServerAuthCode(...) 구성으로 Auth.GOOGLE_SIGN_IN_API로 전환합니다.
이전 엔드포인트와 새 엔드포인트 간에 API 액세스 로직을 계속 공유할 수 있습니다. 예를 들면 다음과 같습니다.
GoogleTokenResponsetokenResponse=newGoogleAuthorizationCodeTokenRequest(...);StringaccessToken=tokenResponse.getAccessToken();StringrefreshToken=tokenResponse.getRefreshToken();LongexpiresInSeconds=tokenResponse.getExpiresInSeconds();// Shared by your old and new implementation, old endpoint can pass null for refreshTokenprivatevoiddriveAccess(StringrefreshToken,StringaccessToken,LongexpiresInSeconds){GoogleCredentialcredential=newGoogleCredential.Builder().setTransPort(...)....build();credential.setAccessToken(accessToken);credential.setExpiresInSeconds(expiresInSeconds);credential.setRefreshToken(refreshToken);}
GoogleAuthUtil ID 토큰 흐름에서 이전
GoogleAuthUtil를 사용하여 ID 토큰을 가져오는 경우 새 Sign-In API ID 토큰 흐름으로 이전해야 합니다.
예를 들어 Android 코드가 다음 예시와 같다면 이전해야 합니다.
이 예시에서 ID 토큰 요청은 audience:server:client_id와 웹 서버의 클라이언트 ID를 GoogleAuthUtil.getToken 호출(audience:server:client_id:9414861317621.apps.googleusercontent.com)의 '범위' 매개변수로 사용합니다.
새로운 Sign-In API ID 토큰 흐름에는 다음과 같은 이점이 있습니다.
간소화된 원탭 로그인 환경
서버가 추가 네트워크 호출 없이 사용자 프로필 정보를 가져올 수 있습니다.
ID 토큰 흐름으로 이전하려면 다음과 같이 변경합니다.
Android 클라이언트 측
요청하는 경우 GET_ACCOUNTS (연락처) 권한 삭제
GoogleAuthUtil, Plus.API, AccountPicker.newChooseAccountIntent() 또는 AccountManager.newChooseAccountIntent()를 사용하는 코드를 GoogleSignInOptions.Builder.requestIdToken(...) 구성으로 Auth.GOOGLE_SIGN_IN_API로 전환합니다.
서버 측
새 Sign-In API는 지원 중단된 형식을 사용하는 GoogleAuthUtil.getToken와 달리 OpenID Connect 사양을 준수하는 ID 토큰을 발급합니다.
특히 발급자는 이제 https 스키마가 있는 https://accounts.google.com입니다.
이전 프로세스 중에 서버는 기존 Android 클라이언트와 새 Android 클라이언트 모두의 ID 토큰을 확인해야 합니다. 두 가지 형식의 토큰을 확인하려면 사용하는 클라이언트 라이브러리에 맞춰 변경합니다 (하나를 사용하는 경우).
Java (Google API 클라이언트 라이브러리): 1.21.0 이상으로 업그레이드
PHP (Google API 클라이언트 라이브러리): v1을 사용하는 경우 1.1.6 이상으로 업그레이드하고 v2를 사용하는 경우 2.0.0-RC1 이상으로 업그레이드합니다.
Node.js: 0.9.7 이상으로 업그레이드
Python 또는 자체 구현: https://accounts.google.com 및 accounts.google.com 발급자를 모두 허용합니다.
GoogleAuthUtil 서버 인증 코드 흐름에서 이전
GoogleAuthUtil를 사용하여 서버 인증 코드를 가져오는 경우 새로운 Sign-In API 인증 코드 흐름으로 이전해야 합니다.
예를 들어 Android 코드가 다음 예와 같다면 이전해야 합니다.
이 예에서 서버 인증 코드 요청은 oauth2:server:client_id + 웹 서버의 클라이언트 ID를 GoogleAuthUtil.getToken 호출 (oauth2:server:client_id:9414861317621.apps.googleusercontent.com)의 scope 매개변수로 사용합니다.
새로운 Sign-In API 인증 코드 흐름에는 다음과 같은 이점이 있습니다.
간편한 원탭 로그인 환경
아래의 이전 가이드를 따르면 인증 코드 교환을 수행할 때 서버에서 사용자의 프로필 정보가 포함된 ID 토큰을 가져올 수 있습니다.
새 인증 코드 흐름으로 이전하려면 다음을 변경하세요.
Android 클라이언트 측
GET_ACCOUNTS (연락처) 권한 요청 시 삭제
GoogleAuthUtil, Plus.API, AccountPicker.newChooseAccountIntent() 또는 AccountManager.newChooseAccountIntent()를 사용하는 코드를 GoogleSignInOptions.Builder.requestServerAuthCode(...) 구성으로 Auth.GOOGLE_SIGN_IN_API로 전환합니다.
서버 측
현재 코드를 유지하되 GoogleAuthorizationCodeTokenRequest 객체를 구성할 때 https://oauth2.googleapis.com/token를 토큰 서버 엔드포인트로 지정합니다. 그러면 다른 네트워크 호출 없이 사용자의 이메일, 사용자 ID, 프로필 정보가 포함된 ID 토큰을 가져올 수 있습니다. 이 엔드포인트는 완전히 하위 호환되며 아래 코드는 기존 Android 클라이언트 구현과 새 Android 클라이언트 구현에서 모두 가져온 서버 인증 코드에 사용할 수 있습니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2024-11-09(UTC)"],[[["\u003cp\u003eGoogle Sign-In for Android is outdated and developers should migrate to Credential Manager for enhanced security and user experience.\u003c/p\u003e\n"],["\u003cp\u003eAvoid sending access tokens directly to backend servers for authentication; instead, utilize the ID token or server auth code flow.\u003c/p\u003e\n"],["\u003cp\u003eMigrating to the ID token flow is recommended for retrieving basic user information like ID, email, and profile details.\u003c/p\u003e\n"],["\u003cp\u003eThe server auth code flow is suitable for accessing Google APIs beyond user profile data, such as Google Drive or YouTube.\u003c/p\u003e\n"],["\u003cp\u003eWhen migrating from GoogleAuthUtil, ensure your server can verify ID tokens from both old and new clients by updating client libraries or accepting both issuer formats.\u003c/p\u003e\n"]]],[],null,["# Migrate from GoogleAuthUtil and Plus.API\n\n| **Warning:** Google Sign-In for Android is outdated and no longer supported. To ensure the continued security and usability of your app, [migrate\n| to Credential Manager](https://developer.android.com/training/sign-in/credential-manager/) today. Credential Manager supports passkey, password, and federated identity authentication (such as Sign-in with Google), stronger security, and a more consistent user experience. For Wear developers: Credential Manager will be supported in Wear OS 5.1 and later on selected watches. Developers actively supporting Wear OS 3, 4 and 5.0 devices with Sign in with Google should continue using Google Sign-in for Android for your Wear applications. Sign in with Google support will be available on Credential Manager APIs for these versions of WearOS at a later date.\n\nIf you integrated with Google Sign-In in the past using\n`GoogleAuthUtil.getToken` or `Plus.API`, you should migrate to the newest\nSign-In API for greater security and a better user experience.\n\nMigrate from access token anti-pattern\n--------------------------------------\n\nYou should not send access tokens obtained with `GoogleAuthUtil.getToken` to\nyour backend server as an identity assertion, since you cannot easily verify\nthat the token was issued to your backend, leaving you vulnerable to insertion\nof an access token from an attacker.\n\nFor example, if your Android code looks like the example below, you should\nmigrate your app to the current best practices.\n\nIn the example, access token requests use `oauth2:` plus a scope string as the\n`scope` parameter for the `GoogleAuthUtil.getToken` call\n(`oauth2:https://www.googleapis.com/auth/plus.login`).\n\nInstead of authenticating with an access token acquired with\n`GoogleAuthUtil.getToken`, use either the ID token flow or the auth code flow.\n\n### Migrate to the ID token flow\n\nIf all you need is the user's ID, email address, name, or profile picture URL,\nuse the [ID token flow](/identity/sign-in/android/backend-auth).\n\nTo migrate to the ID token flow, make the following changes:\n\n#### Android client side\n\n- Remove the `GET_ACCOUNTS` (Contacts) permission if you request it\n- Switch any code using `GoogleAuthUtil`, `Plus.API`, `AccountPicker.newChooseAccountIntent()`, or `AccountManager.newChooseAccountIntent()` to `Auth.GOOGLE_SIGN_IN_API` with `GoogleSignInOptions.Builder.requestIdToken(...)` configuration.\n\n#### Server side\n\n- Create a new endpoint for [ID token auth](/identity/sign-in/android/backend-auth)\n- Turn off the old endpoint after your client apps are migrated\n\n### Migrate to the server auth code flow\n\nIf your server needs to access other Google APIs, such as Google Drive, Youtube,\nor Contacts, use the [server auth code flow](/identity/sign-in/android/offline-access).\n\nTo migrate to the server auth code flow, make the following changes:\n\n#### Android client side\n\n- Remove the `GET_ACCOUNTS` (Contacts) permission if you request it\n- Switch any code using `GoogleAuthUtil`, `Plus.API`, `AccountPicker.newChooseAccountIntent()`, or `AccountManager.newChooseAccountIntent()` to `Auth.GOOGLE_SIGN_IN_API` with `GoogleSignInOptions.Builder.requestServerAuthCode(...)` configuration.\n\n#### Server side\n\n- Create a new endpoint for the [server auth code flow](/identity/sign-in/android/offline-access)\n- Turn off the old endpoint after your client apps are migrated\n\nYou can still share API access logic between your old and new endpoints. For\nexample: \n\n```carbon\nGoogleTokenResponse tokenResponse = new GoogleAuthorizationCodeTokenRequest(...);\nString accessToken = tokenResponse.getAccessToken();\nString refreshToken = tokenResponse.getRefreshToken();\nLong expiresInSeconds = tokenResponse.getExpiresInSeconds();\n\n// Shared by your old and new implementation, old endpoint can pass null for refreshToken\nprivate void driveAccess(String refreshToken, String accessToken, Long expiresInSeconds) {\n GoogleCredential credential = new GoogleCredential.Builder()\n .setTransPort(...)\n ...\n .build();\n credential.setAccessToken(accessToken);\n credential.setExpiresInSeconds(expiresInSeconds);\n credential.setRefreshToken(refreshToken);\n}\n```\n\nMigrate from the GoogleAuthUtil ID token flow\n---------------------------------------------\n\nIf you use `GoogleAuthUtil` to get ID tokens, you should migrate to the new\nSign-In API [ID token flow](/identity/sign-in/android/backend-auth).\n\nFor example, if your Android code looks like the following example, you should\nmigrate:\n\nIn the example, ID token requests use `audience:server:client_id` plus the\nclient ID for your web server as the 'scope' parameter for the\n`GoogleAuthUtil.getToken` call\n(`audience:server:client_id:9414861317621.apps.googleusercontent.com`).\n\nThe new Sign-In API ID token flow has the following benefits:\n\n- Streamlined one-tap sign-in experience\n- Your server can get user profile information without an extra network call\n\nTo migrate to the ID token flow, make the following changes:\n\n#### Android client side\n\n- Remove the `GET_ACCOUNTS` (Contacts) permission if you request it\n- Switch any code using `GoogleAuthUtil`, `Plus.API`, `AccountPicker.newChooseAccountIntent()`, or `AccountManager.newChooseAccountIntent()` to `Auth.GOOGLE_SIGN_IN_API` with `GoogleSignInOptions.Builder.requestIdToken(...)` configuration.\n\n#### Server side\n\nThe new Sign-In API issues ID tokens that comply with the OpenID Connect\nspecification, unlike `GoogleAuthUtil.getToken`, which uses a deprecated format.\nIn particular, the issuer is now `https://accounts.google.com`, with a `https`\nschema.\n\nDuring your migration process, your server needs to verify ID token from both\nyour old and new Android clients. To verify both formats of the token, make the\nchange that corresponds to the client library you use (if you use one):\n\n- Java (Google APIs Client Libraries): upgrade to 1.21.0 or newer\n- PHP (Google APIs Client Libraries): if you use v1, upgrade to 1.1.6 or newer; if you use v2, upgrade to 2.0.0-RC1 or newer\n- Node.js: upgrade to 0.9.7 or newer\n- Python or your own implementations: accept both of these issuers: `https://accounts.google.com` and `accounts.google.com`\n\nMigrate from the GoogleAuthUtil server auth code flow\n-----------------------------------------------------\n\nIf you use `GoogleAuthUtil` to get a server auth code, you should migrate to the\nnew Sign-In API [auth code flow](/identity/sign-in/android/offline-access).\n\nFor example, if your Android code looks like the following example, you should\nmigrate:\n\nIn the example, server auth code requests use `oauth2:server:client_id` + the\nclient ID for your web server as the `scope` parameter for the\n`GoogleAuthUtil.getToken` call (`oauth2:server:client_id:9414861317621.apps.googleusercontent.com`).\n\nThe new Sign-In API auth code flow has the following benefits:\n\n- Streamlined one-tap sign-in experience\n- If you follow the migration guide below, your server can get an ID token containing the user's profile information when you do the auth code exchange\n\nTo migrate to the new auth code flow, make the following changes:\n\n#### Android client side\n\n- Remove the `GET_ACCOUNTS` (Contacts) permission if you request it\n- Switch any code using `GoogleAuthUtil`, `Plus.API`, `AccountPicker.newChooseAccountIntent()`, or `AccountManager.newChooseAccountIntent()` to `Auth.GOOGLE_SIGN_IN_API` with `GoogleSignInOptions.Builder.requestServerAuthCode(...)` configuration.\n\n#### Server side\n\nKeep your current code, but specify `https://oauth2.googleapis.com/token`\nas the token server endpoint when constructing the\n`GoogleAuthorizationCodeTokenRequest` object, so that you can get an ID token\nwith the user's email, user ID, and profile info without the need for another\nnetwork call. This endpoint is fully backward compatible, and the below code\nwill work for server auth codes retrieved from both your old and new Android\nclient implementations. \n\n```css+lasso\nGoogleTokenResponse tokenResponse = new GoogleAuthorizationCodeTokenRequest(\n transport,\n jsonFactory,\n // Use below for tokenServerEncodedUrl parameter\n \"https://oauth2.googleapis.com/token\",\n clientSecrets.getDetails().getClientId(),\n clientSecrets.getDetails().getClientSecret(),\n authCode,\n REDIRECT_URI)\n .execute();\n\n...\n\n// You can also get an ID token from auth code exchange.\nGoogleIdToken googleIdToken = tokenResponse.parseIdToken();\nGoogleIdTokenVerifier verifier = new GoogleIdTokenVerifier.Builder(transport, jsonFactory)\n .setAudience(Arrays.asList(SERVER_CLIENT_ID))\n .setIssuer(\"https://accounts.google.com\")\n .build();\n// Refer to ID token documentation to see how to get data from idToken object.\nGoogleIdToken idToken = verifier.verify(idTokenString);\n...\n```\n| **Note:** If you use the server auth code flow, but only need to access the user's profile information on your server, consider switching to the recommended [ID token flow](/identity/sign-in/android/backend-auth)."]]