액세스 토큰 취소 및 앱 연결 해제

Google로 로그인한 사용자에게 앱에서 Google 계정을 연결 해제할 수 있는 기능을 제공하는 것이 좋습니다. 사용자가 계정을 삭제하면 앱이 Google API에서 가져온 정보를 삭제해야 합니다.

다음 코드 예에서는 앱이 사용자를 대신하여 부여받은 액세스 토큰을 프로그래매틱 방식으로 취소하고 사용자의 계정을 앱에서 연결 해제하는 방법을 보여줍니다.

Swift

GIDSignIn.sharedInstance.disconnect { error in
    guard error == nil else { return }

    // Google Account disconnected from your app.
    // Perform clean-up actions, such as deleting data associated with the
    //   disconnected account.
}

Objective-C

[GIDSignIn.sharedInstance disconnectWithCompletion:^(NSError * _Nullable error) {
    if (error) { return; }

    // Google Account disconnected from your app.
    // Perform clean-up actions, such as deleting data associated with the
    //   disconnected account.
}];

disconnectWithCompletion: 메서드는 계정을 연결 해제하고 토큰을 취소하는 것 외에도 사용자를 로그아웃시킵니다. disconnectWithCompletion:을 호출하기 전에 사용자를 로그아웃시켜서는 안 됩니다.

그런 다음 콜백 블록 내에서 연결 해제 성공에 응답하고 앱 또는 백엔드 코드에서 적절한 로직을 트리거할 수 있습니다.