Swift和Firebase:检测已撤销的令牌

问题描述 投票:0回答:1

我想知道客户端(iOS)是如何通知撤销令牌的,因为Google在本指南中说:

如何检测(在客户端设备上)令牌被撤销并采取相应行动(重新验证或注销)?

响应客户端上的令牌撤销

如果通过Admin SDK撤销令牌,则会通知客户端撤销,并且用户需要重新进行身份验证或退出:

GOOGLE的例子:

function onIdTokenRevocation() {
  // For an email/password user. Prompt the user for the password again.
    let password = prompt('Please provide your password for reauthentication');
    let credential = firebase.auth.EmailAuthProvider.credential(
    firebase.auth().currentUser.email, password);
    firebase.auth().currentUser.reauthenticateWithCredential(credential)
    .then(result => {
      // User successfully reauthenticated. New ID tokens should be valid.
    })
    .catch(error => {
      // An error occurred.
    });
}
swift firebase firebase-authentication
1个回答
0
投票

当令牌失效时,所有iOS客户端用户API将在调用时抛出错误FIRAuthErrorCodeUserTokenExpired。您可以捕获它,然后重新验证用户。

如果将令牌发送到服务器,则可以按如下方式检测它:https://firebase.google.com/docs/auth/admin/manage-sessions#detect_id_token_revocation_in_the_sdk

您还可以设置自己的侦听器,以便在发生失效时立即检测失效。显示了使用实时数据库的示例:https://firebase.google.com/docs/auth/admin/manage-sessions#detect_id_token_revocation

© www.soinside.com 2019 - 2024. All rights reserved.