invertase / dart_firebase_admin Goto Github PK
View Code? Open in Web Editor NEW๐ฅ A Firebase Admin SDK for Dart.
License: Apache License 2.0
๐ฅ A Firebase Admin SDK for Dart.
License: Apache License 2.0
When running dart lib/main.dart
, the process never stops.
Hello,
I was trying to implement dart firebase admin library to my dart:frog project. It is successfully initializing but when I try to do anything related firestore I get
Failed host lookup: 'metadata.google.internal'
I dont have any logic I am just calling on main.
Future<FirebaseAdminApp> init(InternetAddress ip, int port) async {
final admin = FirebaseAdminApp.initializeApp(
'gizemlikutucom',
// This will obtain authentication informations from the environment
Credential.fromApplicationDefaultCredentials(),
);
return admin;
}
Future<HttpServer> run(Handler handler, InternetAddress ip, int port) async {
FirebaseAdminApp admin = await init(ip, port);
try {
final firestore = Firestore(admin);
DocumentSnapshot a = await firestore.collection("a").doc("b").get();
print(a.data());
} catch (e) {
print(e);
}
return serve(handler, ip, port);
}
here the versions
environment:
sdk: ">=3.0.0 <4.0.0"
dependencies:
dart_firebase_admin: ^0.0.2
dart_frog: ^1.0.0
shelf_cors_headers: ^0.1.5
When i send the token back to the client and trie the LoginWithToken method I get:
error: [firebase_auth/invalid-custom-token] The custom token format is incorrect. Please check the documentation.
If i paste the token into jwt.io i get the following warning (although I can see the correct payload of the token.
Warning: Looks like your JWT signature is not encoded correctly using base64url (https://tools.ietf.org/html/rfc4648#section-5). Note that padding ("=") must be omitted as per https://tools.ietf.org/html/rfc7515#section-2
I did double check that the projects match and got it to work with the python admin sdk.
Any Ideas?
Thanks Mark
I tried this lib for a couple of collections which all worked fine.
On a given collection however I get this error:
ERROR - 2024-03-30 15:11:12.058685
POST /apps/execute_automation
Error thrown by handler.
type 'String' is not a subtype of type 'num' in type cast
package:firebaseapis/firestore/v1.dart 5451:39 new Value.fromJson
package:firebaseapis/firestore/v1.dart 4604:27 new MapValue.fromJson.
dart:collection MapBase.map
package:firebaseapis/firestore/v1.dart 4601:74 new MapValue.fromJson
package:firebaseapis/firestore/v1.dart 5461:26 new Value.fromJson
package:firebaseapis/firestore/v1.dart 2449:41 new ArrayValue.fromJson.
dart:_internal ListIterable.toList
package:firebaseapis/firestore/v1.dart 2451:20 new ArrayValue.fromJson
package:firebaseapis/firestore/v1.dart 5441:28 new Value.fromJson
package:firebaseapis/firestore/v1.dart 2958:27 new Document.fromJson.
dart:collection MapBase.map
package:firebaseapis/firestore/v1.dart 2955:74 new Document.fromJson
package:firebaseapis/firestore/v1.dart 5057:26 new RunQueryResponseElement.fromJson
package:firebaseapis/firestore/v1.dart 1888:49 ProjectsDatabasesDocumentsResource.runQuery.
dart:_internal ListIterable.toList
package:firebaseapis/firestore/v1.dart 1890:10 ProjectsDatabasesDocumentsResource.runQuery
I could not pinpoint the exact document that got it to fail but this is the general data structure:
This is what I am doing
final admin = FirebaseAdminApp.initializeApp(
'pharaoh-example',
Credential.fromServiceAccount(File("$publicDir/serviceAccountKey.json")),
);
final auth = Auth(admin);
But I get an error whenever I run the file
../../../../../../../.pub-cache/hosted/pub.dev/dart_firebase_admin-0.1.0/lib/src/auth/token_generator.dart:95:51: Error: The argument type 'List<int>' can't be assigned to the parameter type 'Uint8List'.
- 'List' is from 'dart:core'.
- 'Uint8List' is from 'dart:typed_data'.
final signPromise = await _signer.sign(utf8.encode(token));
^
../../../../../../../.pub-cache/hosted/pub.dev/dart_firebase_admin-0.1.0/lib/src/auth/token_generator.dart:137:58: Error: A value of type 'List<int>' can't be returned from an async function with return type 'Future<Uint8List>'.
- 'List' is from 'dart:core'.
- 'Future' is from 'dart:async'.
- 'Uint8List' is from 'dart:typed_data'.
Future<Uint8List> sign(Uint8List buffer) async => utf8.encode('');
I'm getting this error when using Messaging.send
. I believe I've narrowed it down to that this is happening when attempting to send a message to a stale FCM token. 'active' tokens do not throw the exception.
I'm migrating some things from JS to Dart. I see you have some TS files committed as well. Could this potentially be related to detect-invalid-token-responses-from-the-fcm-backend?
I have issue updating the user data based on user's bid. First, I retrieve the user's data by email, and I get what I expect. Then, I used the uid from the response for updating the user's data, but I keep getting the following error:
E/flutter (13587): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: FirebaseAuthAdminException: auth/missinguid: A uid identifier is required for the current operation.
E/flutter (13587): #0 validateResponse (package:_discoveryapis_commons/src/api_requester.dart:306:9)
E/flutter (13587): <asynchronous suspension>
E/flutter (13587): #1 ApiRequester.request (package:_discoveryapis_commons/src/api_requester.dart:72:16)
E/flutter (13587): <asynchronous suspension>
E/flutter (13587): #2 AccountsResource.update (package:firebaseapis/identitytoolkit/v1.dart:714:23)
E/flutter (13587): <asynchronous suspension>
E/flutter (13587): #3 _AuthHttpClient.setAccountInfo.<anonymous closure> (package:dart_firebase_admin/src/auth/auth_api_request.dart:966:24)
E/flutter (13587): <asynchronous suspension>
E/flutter (13587): #4 _AbstractAuthRequestHandler.updateExistingAccount (package:dart_firebase_admin/src/auth/auth_api_request.dart:733:22)
E/flutter (13587): <asynchronous suspension>
E/flutter (13587): #5 _BaseAuth.updateUser (package:dart_firebase_admin/src/auth/base_auth.dart:772:9)
E/flutter (13587): <asynchronous suspension>
E/flutter (13587): #6 LoginController.login.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:stock_log/app/modules/login/controllers/login_controller.dart:162:23)
E/flutter (13587): <asynchronous suspension>
E/flutter (13587): #7 LoginController.login.<anonymous closure>.<anonymous closure> (package:stock_log/app/modules/login/controllers/login_controller.dart:149:13)
E/flutter (13587): <asynchronous suspension>
E/flutter (13587): #8 LoginController.login.<anonymous closure> (package:stock_log/app/modules/login/controllers/login_controller.dart:144:11)
E/flutter (13587): <asynchronous suspension>
E/flutter (13587): #9 LoginController.login (package:stock_log/app/modules/login/controllers/login_controller.dart:87:28)
E/flutter (13587): <asynchronous suspension>
E/flutter (13587):
Here is my code:
await auth.getUserByEmail(email.value).then((user) async {
String uid = user.uid;
await auth
.updateUser(uid, ath.UpdateRequest(password: code.toString()))
.then((value) async {
print('USER UPDATED');
print(value.toJson());
});
});
Version 0.3.0
I know it's an early build, so just drawing attention to a blocking feature for wider adoption. We use verifyIdToken
to verify requests from clients before performing requests using admin functionality or firestore.
Unfortunately, I don't have enough familiarity with the jwt spec and library design to understand what the jwtKey
and other missing params are at src/utils/jwt.dart:100
.
Issue:
Auth#verifyIdToken always throws unimplemented error.
Reproduce:
final FirebaseAdminApp admin = await FirebaseAdminInitialization(container).initialize();
final auth = Auth(admin);
final idToken = await auth.verifyIdToken(jwt);
await admin.close();
StackTrace:
#0 PublicKeySignatureVerifier.verify (package:dart_firebase_admin/src/utils/jwt.dart:100)
#1 FirebaseTokenVerifier._verifySignature (package:dart_firebase_admin/src/auth/token_verifier.dart:119)
#2 FirebaseTokenVerifier._decodeAndVerify (package:dart_firebase_admin/src/auth/token_verifier.dart:101)
<asynchronous suspension>
#3 FirebaseTokenVerifier.verifyJWT (package:dart_firebase_admin/src/auth/token_verifier.dart:76)
<asynchronous suspension>
#4 _BaseAuth.verifyIdToken (package:dart_firebase_admin/src/auth/base_auth.dart:360)
I wonder if it will be implemented in this package
I downloaded the service-account.json
file and put it into my root folder of my dart_frog project.
I use a custom main.dart
file. For now I put the initialization into the run function to test my setup.
Future<HttpServer> run(Handler handler, InternetAddress ip, int port) async {
final credentials =
Credential.fromServiceAccount(File('service-account.json'));
final admin = FirebaseAdminApp.initializeApp(
'projectName',
credentials,
);
final firestore = Firestore(admin);
await firestore
.doc('{collection}/{id}')
.get();
return serve(handler, ip, port);
}
I get the following error on Data Fetching
FirebaseFirestoreAdminException: firestore/unknown: No error details. HTTP status was: 404. null
Am I missing something?
Encountering a FormatException
error when using the firebaseAuth.getUserByEmail
method. The error message is "Invalid radix-10 number".
Just call the firebaseAuth.getUserByEmail
method with an email of an existing user.
I want to do the below operation and since my res.status(201).json(object)
tries to encode the object
before sending to the frontend, it fails and gives me the error of Converting object to an encodable object failed: Instance of 'DateTime'
which is from here --> lib/src/auth/user/UserMetadata/toJson
(location of the datetime)
return res.status(201).json({
"success": true,
"user": savedUser.toJson(),
"token": jwtToken,
});
firestore.collection('yourCollection').doc('yourDoc')
.update({'a.' : 'b'});
ArgumentError (Invalid argument (path): must not start or end with "." ...
If we try to do it in the console it allows us to do that, so I guess it is not the correct behavior for a map field
Path: dart_firebase_admin-0.0.2/lib/src/google_cloud_firestore/path.dart
Hi,
If possible, please upgrade the http package to the latest.
Thank you.
Any examples please.
Has anyone already used the createUser
function?
I always get a FirebaseAuthAdminException
with the code auth/internalerror
and the message An internal error has occurred.
final createRequest = CreateRequest(
email: email,
displayName: '$firstName $lastName',
password: randomPassword,
);
try {
user = await auth.createUser(createRequest);
} on FirebaseAuthAdminException catch (e) {
print('');
print('FirebaseAuthAdminException');
print('code: ${e.code}');
print('message: ${e.message}');
} catch (e) {
print('catched: $e);
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.