作为Unity和C#的新手,我在我的项目中使用Firebase电子邮件认证。2我想使用响应的JWT令牌。3下面是我的相关代码:
private IEnumerator Login(string _email, string _password)
{
//Call the Firebase auth signin function passing the email and password
var LoginTask = auth.SignInWithEmailAndPasswordAsync(_email, _password);
//Wait until the task completes
yield return new WaitUntil(predicate: () => LoginTask.IsCompleted);
.
.
.
else
{
//User is now logged in
//Now get the result
User = LoginTask.Result;
Debug.LogFormat("User signed in successfully: {0} ({1})", User.DisplayName, User.Email);
warningLoginText.text = "";
confirmLoginText.text = "Logged In";
}
}
I think I need to access it from LoginTask. However, I don't know how to get JWT. I will use it API request operations. Thank you for your help.
1条答案
按热度按时间i7uq4tfw1#
我也经历过类似的事情,希望这能有所帮助:
要从Unity中的Firebase身份验证响应获取JWT令牌,您可以使用SignInWithEmailAndPasswordAsync()方法返回的User对象并访问User.Token属性。
JWT标记:
值得注意的是,令牌的生存期为1小时,超过此期限后您必须刷新它。