使用Firebase简单登录时如何访问/验证Firebase身份验证对象的内容? [英] How to access/verify the contents of the firebase auth object when using firebase simple login?

查看:112
本文介绍了使用Firebase简单登录时如何访问/验证Firebase身份验证对象的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Firebase简单登录时是否可以访问/验证firebase auth对象的内容?这对于调试/配置安全规则很有用.

Is it possible to access/verify the contents of the firebase auth object when using firebase simple login? It would be useful for debugging / configuring security rules.

推荐答案

用于auth的其他调试.使用Firebase简单登录时的令牌和安全规则,您可以使用两个出色的工具:

For additional debugging of the auth. token and security rules when using Firebase Simple Login, you have two great tools at your disposal:

  1. 启用debug模式,方法是在生成自定义Firebase令牌时传递可选的debug: true标志.由于安全限制,在使用委派身份验证服务时,您无法自动执行此操作,但是您可以通过自定义登录.

  1. Enable debug mode, by passing the optional debug: true flag when generating a custom Firebase token. You cannot do this automatically when using the delegated authentication service due to security constraints, but you may generate tokens yourself via Custom Login.

此外,尝试使用以下命令在客户端库上启用调试模式,这将产生其他信息,例如正在读取或写入的路径以及通过网络传输的数据:

Also, try enabling debug-mode on the client library with the following command, which will yield additional information such as the paths being read from or written to, and the data going over the wire:

Firebase.enableLogging(true, true);

authClient.login('twitter', { debug: true });

如您所建议,请看一下身份验证令牌的内容.有几种方法可以做到这一点.最简单的方法是将其手动传递给firebaseRef.auth(),然后检查在回调中返回的响应有效载荷,该回调包含auth的内容.令牌.或者,因为所有Firebase均经过身份验证.令牌遵循开放的 JSON Web令牌(JWT)标准,您可以解析身份验证的内容.通过Base64解码令牌,并用句点(.)分隔每个令牌序列.

As you suggest, take a peek at the contents of the authentication token. There are a few ways to do this. The easiest is to manually pass it to firebaseRef.auth(), and examine the response payload that is returned in the callback, which contains the contents of the auth. token. Alternatively, since all Firebase auth. tokens follow the open JSON Web Token (JWT) standard, you can parse the contents of the auth. token by Base64-decoding each of the token sequences, separated by a period (.).

通常,Firebase简单登录会自动为您处理此步骤,但是您可以手动调用ref.auth(<token>, function(authData) { ... });,在通过简单登录进行身份验证后,令牌可以通过user.firebaseAuthToken来使用.

Normally, Firebase Simple Login automatically handles this step for you, but you can manually call ref.auth(<token>, function(authData) { ... });, where the token is available via user.firebaseAuthToken after authenticating with Simple Login.

这篇关于使用Firebase简单登录时如何访问/验证Firebase身份验证对象的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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