我想向Firebase用户对象添加属性.该用户文档说我可以用火力地堡实时数据库只存储附加属性.
我不确定这在实践中如何发挥作用.
以下在实践中意味着什么?
您无法直接向Firebase用户对象添加其他属性; 相反,您可以将其他属性存储在Firebase实时数据库中.
我把它解释如下:
"你不能修改FIRUser对象的属性,但你可以将它与其他对象结合起来"
我发现了以这种方式插入的set函数文档:
var userRef = ref.child("users");
userRef.set({
newfield: "value"
});
Run Code Online (Sandbox Code Playgroud)
这是一种明智的做法吗?
database-design firebase firebase-authentication firebase-realtime-database
我已成功部署了https://firebase.google.com/docs/auth/android/facebook-login中的教程代码,以便将Firebase身份验证登录与Facebook集成.用户已在Firebase Auth控制台中成功创建.
但是,我注意到用户对象中的电子邮件字段为空( - ).奇怪的是,我使用获取的令牌使用GraphRequest直接从提供者结果对象中成功检索了电子邮件信息.
根据我阅读的文档(https://firebase.google.com/docs/reference/android/com/google/firebase/auth/FirebaseUser.html#getEmail()),应从登录提供商填充电子邮件字段.
一些额外的奇怪行为:
有什么我想念或做的我做错了吗?
这是我的代码:
public class LoginActivity extends AppCompatActivity {
private static final String TAG = "LOGIN_ACTIVITY";
private static final int RC_SIGN_IN = 777;
private EventBus eventBus;
private SweetAlertDialog pDialog;
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
private CallbackManager mCallbackManager;
private ImageView mPasswordVisibilityView;
private TextView txtPassword;
private boolean justEnteredAuthStateChanged = false;
private GoogleApiClient mGoogleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.login);
// Firebase
mAuth = FirebaseAuth.getInstance();
mAuthListener …Run Code Online (Sandbox Code Playgroud) android facebook-authentication firebase firebase-authentication
我希望通过NodeJS或Javascript API从Firebase获取Auth User(s)UID.我已附上截图,以便您知道我在寻找什么.

希望,你们帮我解决这个问题.
我正在尝试使用Firebase Auth为Angular 2路由构建AuthGuard.
这是AuthGuard服务:
import { Injectable } from '@angular/core';
import { CanActivate, Router,
ActivatedRouteSnapshot,
RouterStateSnapshot } from '@angular/router';
import { AuthService } from './auth.service';
@Injectable()
export class AuthGuard implements CanActivate {
constructor(private AuthService: AuthService,
private router: Router) {}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
if (this.AuthService.loggedIn) { return true; }
this.router.navigate(['login']);
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
这是AuthService,它检查用户是否登录并将结果绑定到其构造函数中的"loggedIn"属性.
import { Injectable } from '@angular/core';
import { AngularFire } from 'angularfire2';
import { Router } from '@angular/router';
@Injectable()
export class AuthService {
loggedIn: …Run Code Online (Sandbox Code Playgroud) firebase typescript firebase-authentication angularfire2 angular
我有一个调用addCheckin()方法的页面,它位于控制器内部.在控制器中,我试图创建一个如下引用:
var ref = firebase.database().ref("users/" + $scope.whichuser + "/meetings/" +$scope.whichmeeting + "/checkins");
Run Code Online (Sandbox Code Playgroud)
$scope.whichuser并且$scope.whichmeeting是$routeParams,我从其他途径传递.这是我的签到控制器 -
myApp.controller("CheckinsController",
['$scope','$rootScope','$firebaseArray','$routeParams','$firebaseObject',
function($scope,$rootScope,$firebaseArray,$routeParams,$firebaseObject){
$scope.whichuser = $routeParams.uid;
$scope.whichmeeting = $routeParams.mid;
var ref = firebase.database().ref("users/" + $scope.whichuser + "/meetings/" +$scope.whichmeeting + "/checkins");
$scope.addCheckin = function(){
var checkinInfo = $firebaseArray(ref);
var data={
firstname:$scope.firstname,
lastname:$scope.lastname,
email:$scope.email,
date:firebase.database.ServerValue.TIMESTAMP
}
checkinInfo.$add(data);
}
}]);/*controller*/
Run Code Online (Sandbox Code Playgroud)
我在这里遇到两个错误 -
错误1:
Error: permission_denied at /users/Vp2P1MqKm7ckXqV2Uy3OzTnn6bB3/meetings: Client doesn't have permission to access the desired data.
错误2:
Error: permission_denied at /users/Vp2P1MqKm7ckXqV2Uy3OzTnn6bB3/meetings/-KT5tqMYKXsFssmcRLm6/checkins: Client …
angularjs firebase angularfire firebase-authentication firebase-realtime-database
我正在使用Firebase身份验证在Android中创建一个简单的身份验证应用 直到现在我成功签署了用户,但问题是用户仍然登录,我找不到签署他的方法.
这是我的MainActivity.java代码
public class MainActivity extends AppCompatActivity {
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//tracking the sign in and singn out operations
mAuth = FirebaseAuth.getInstance();
mAuthListener = new FirebaseAuth.AuthStateListener(){
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user!=null){
System.out.println("User logged in");
}
else{
System.out.println("User not logged in");
}
}
};
}
public void onStart(){
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
}
public void onStop(){
super.onStop();
if (mAuthListener != null) {
mAuth.removeAuthStateListener(mAuthListener); …Run Code Online (Sandbox Code Playgroud) 我正在使用firebase phone auth在本机应用程序中使用此文档我在一些不同的设备上测试了它.有时电话验证工作,有时它会抛出此错误
firebase phone auth错误:令牌无效.在nativeToJSError
我是通过firebase的文档做的,并尝试了解这个错误.那是我的代码.
confirmPhone = async (phoneNumber) => {
const phoneWithAreaCode = phoneNumber.replace(/^0+/, '+972');
return new Promise((res, rej) => {
firebase.auth().verifyPhoneNumber(phoneWithAreaCode)
.on('state_changed', async (phoneAuthSnapshot) => {
switch (phoneAuthSnapshot.state) {
case firebase.auth.PhoneAuthState.AUTO_VERIFIED:
UserStore.setVerificationId(phoneAuthSnapshot.verificationId)
await this.confirmCode(phoneAuthSnapshot.verificationId, phoneAuthSnapshot.code, phoneAuthSnapshot)
res(phoneAuthSnapshot)
break
case firebase.auth.PhoneAuthState.CODE_SENT:
UserStore.setVerificationId(phoneAuthSnapshot.verificationId)
res(phoneAuthSnapshot)
break
case firebase.auth.PhoneAuthState.AUTO_VERIFY_TIMEOUT:
UserStore.setVerificationId(phoneAuthSnapshot.verificationId)
UserStore.setErrorCodeAuthentication('SMS code has expired')
res(phoneAuthSnapshot)
case firebase.auth.PhoneAuthState.ERROR:
console.log(phoneAuthSnapshot.error.code)
if (phoneAuthSnapshot.error) {
this.showMessageErrorByCode(phoneAuthSnapshot.error.code)
}
rej(phoneAuthSnapshot)
break
}
})
})
}
confirmCode = async (verificationId, code, phoneAuthSnapshot) => {
console.log(verificationId,code); …Run Code Online (Sandbox Code Playgroud) 我希望使用 createUserWithEmailAndPassword() 在 Firebase Auth 中创建一个用户帐户 - 无需登录用户。我希望用户首先验证电子邮件地址。直接登录用户会导致许多不需要的副作用。
/signup 页面有以下代码 - 我希望用户在注册后停留在 /signup 页面上,以便能够看到注册消息。
firebase.auth().createUserWithEmailAndPassword(data.email, data.password)
.then((user)=> {
//Send email verification link
user.sendEmailVerification()
//Show message - "Your account was created - please verify using link in email"
handleStatusMessage(AUTH_SUCCESS)
})
.catch((error)=>{...})
Run Code Online (Sandbox Code Playgroud)
app.js 具有以下登录和重定向处理程序
//handle login and redirect
firebase.auth().onAuthStateChanged((user) => {
if (user) {
if(!user.emailVerified){
//Exit if email is not verified
console.log('auth.js exit')
//Line 7
}
store.dispatch(setInitialStore()).then(() => {
renderApp()
//Brings user to start page
if (history.location.pathname === '/login') { …Run Code Online (Sandbox Code Playgroud) 当我为项目运行 bitbucket 管道时,我在颤动测试期间收到错误:
/root/.pub-cache/hosted/pub.dartlang.org/firebase_core-1.24.0/lib/src/firebase_app.dart:18:25: Error: Member not found: 'FirebaseAppPlatform.verifyExtends'.
FirebaseAppPlatform.verifyExtends(_delegate);
^^^^^^^^^^^^^
Run Code Online (Sandbox Code Playgroud)
当我在终端中运行颤振测试时,我没有遇到这些问题。
我的管道脚本是:
firebase firebase-authentication flutter flutter-test flutter-objectbox
我有一个只有PHP(没有Java,没有node.js)的共享主机方案.我需要从我的Android应用程序发送firebase ID令牌并通过PHP-JWT验证它.
我正在按照教程:验证Firebase ID令牌
它说:
"如果您的后端使用的语言没有官方的Firebase Admin SDK,您仍然可以验证ID令牌.首先,找到适合您语言的第三方JWT库.然后,验证标题,有效负载和签名ID令牌."
我找到了这个库:Firebase-PHP-JWT.在gitHub示例中; 我无法理解
$关键部分:
`$key = "example_key";`
Run Code Online (Sandbox Code Playgroud)
和
$ token部分:
`$token = array(
"iss" => "http://example.org",
"aud" => "http://example.com",
"iat" => 1356999524,
"nbf" => 1357000000
);`
Run Code Online (Sandbox Code Playgroud)
我的问题:
编辑:
哦,我明白了.GitHub示例演示了如何生成JWT代码(编码)以及如何解码它.在我的情况下,我只需要解码由firebase编码的jwt.所以,我只需要使用这个代码:
$decoded = JWT::decode($jwt, $key, array('HS256'));
Run Code Online (Sandbox Code Playgroud)
在此代码部分中,$ jwt是firebase ID令牌.对于$ key变量文档说:
最后,确保ID令牌由与令牌的孩子声明相对应的私钥签名.从https://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com获取公钥,并使用JWT库验证签名.使用来自该端点的响应的Cache-Control标头中的max-age值来了解何时刷新公钥.
我不明白如何将这个公钥传递给解码功能.键是这样的:
"----- BEGIN CERTIFICATE ----- \nMIIDHDCCAgSgAwIBAgIIZ36AHgMyvnQwDQYJKoZIhvcNAQEFBQAwMTEvMC0GA1UE \nAxMmc2VjdXJldG9rZW4uc3lzdGVtLmdzZXJ2aWNlYWNjb3VudC5jb20wHhcNMTcw \nMjA4MDA0NTI2WhcNMTcwMjExMDExNTI2WjAxMS8wLQYDVQQDEyZzZWN1cmV0b2tl \nbi5zeXN0ZW0uZ3NlcnZpY2VhY2NvdW50LmNvbTCCASIwDQYJKoZIhvcNAQEBBQAD \nggEPADCCAQoCggEBANBNTpiQplOYizNeLbs + r941T392wiuMWr1gSJEVykFyj7fe \nCCIhS/zrmG9jxVMK905KwceO/FNB4SK + l8GYLb559xZeJ6MFJ7QmRfL7Fjkq7GHS\N0/sOFpjX7vfKjxH5oT65Fb1 + …
firebase ×10
android ×3
javascript ×3
angular ×1
angularfire ×1
angularfire2 ×1
angularjs ×1
api ×1
flutter ×1
flutter-test ×1
jwt ×1
node.js ×1
php ×1
react-native ×1
typescript ×1