斯威夫特& Firebase:检测已吊销的令牌 [英] Swift & Firebase: Detect revoked token

查看:58
本文介绍了斯威夫特& Firebase:检测已吊销的令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道Google如何按照本指南中的说明向客户端(iOS)通知已撤销的令牌:

I wonder how the client (iOS) is informed on the revoked token as it is said in this guide by Google:

我如何才能(在客户端设备上)检测到令牌已被吊销并采取相应的措施(重新认证或注销)?

How can I detect (on the client device) that the token was revoked and act accordingly (either re-authenticate or sign out)?

在客户端上响应令牌吊销

如果通过Admin SDK吊销了令牌,则会将撤销通知通知客户端,并要求用户重新认证或注销:

If the token is revoked via the Admin SDK, the client is informed of the revocation and the user is expected to reauthenticate or is signed out:

以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.
    });
}

推荐答案

当令牌失效时,所有iOS客户端用户API调用时都会抛出错误FIRAuthErrorCodeUserTokenExpired.您可以捕获该错误,然后重新验证用户身份.

When a token is invalidated, all iOS client side user APIs will throw an error FIRAuthErrorCodeUserTokenExpired when called. You can catch that and then reauthenticate the user.

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

If you sending the token to your server, you can detect it as follows: 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

You can also setup your own listener to detect invalidation as soon as it happens. An example using real time database is shown: https://firebase.google.com/docs/auth/admin/manage-sessions#detect_id_token_revocation

这篇关于斯威夫特& Firebase:检测已吊销的令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆