appsup-dart / firebase_admin Goto Github PK
View Code? Open in Web Editor NEWA pure Dart implementation of the Firebase admin sdk
License: Other
A pure Dart implementation of the Firebase admin sdk
License: Other
I am not sure if I am lost with this. I am trying to carry verification process into my own backend. I can not send nor verify mails through this package. Am I missing something? I need to get oobCode via query and update matching user with that code only. Can I achieve this with this package?
No documentation available how to use in flutter mobile app. But when I tried to use it gives error
Unhandled Exception: Unsupported operation: Unsupported platform: android
When I try to run the example from the source code, whenever it reaches the very first line in the main class:
var credential = Credentials.applicationDefault();
it triggers the Unhandled exception shown below.
I'm using the "service-account.json" file approach.
Could you please guide me on what to look for on this issue?
Thanks
Invalid argument(s): The given string does not have the correct begin marker expected in a PEM file.
#0 parsePem (package:x509/src/x509_base.dart:257:7)
#1 _SyncIterator.moveNext (dart:core-patch/core_patch.dart:183:26)
#2 Iterable.first (dart:core/iterable.dart:489:13)
#3 new Certificate.fromJson (package:firebase_admin/src/auth/credential.dart:42:34)
#4 new ServiceAccountCredential.fromJson (package:firebase_admin/src/auth/credential.dart:82:35)
#5 new ServiceAccountCredential (package:firebase_admin/src/auth/credential.dart:88:41)
#6 Credentials._credentialFromFile (package:firebase_admin/src/credential.dart:190:14)
#7 Credentials._getApplicationDefault (package:firebase_admin/src/credential.dart:138:14)
#8 Credentials.applicationDefault (package:firebase_admin/src/credential.dart:77:33)
#9 main (file:///D:/OneDrive%20-%20Softtek/AppDev/firebase_admin/example/main.dart:11:32)
#10 _delayEntrypointInvocation. (dart:isolate-patch/isolate_patch.dart:283:19)
#11 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
Version: firebase_admin: ^0.2.0-dev.1
The Firebase custom tokens generated by this library result in an auth error from the Firebase servers:
The custom token format is incorrect. Please check the documentation.
It appears this library is putting in extra attributes that are not put in via the Java SDK. Specifically, this puts in a kid
and a typ
attribute in the header that the Java SDK doesn't.
I tried generating a token manually without those attributes and it was accepted by Firebase. Through some more experimentation, it's the typ
attribute that's causing Firebase to reject the token as invalid as it accepts it still with the kid
in place.
It looks like all that needs to change is to remove the typ
header. The fix would be to change: lib/src/auth/token_tenerator.dart
Around lines 68-70... from:
var builder = JsonWebSignatureBuilder()
..jsonContent = claims
..setProtectedHeader('typ', 'JWT')
..addRecipient(certificate.privateKey, algorithm: 'RS256');
... to ...
var builder = JsonWebSignatureBuilder()
..jsonContent = claims
..addRecipient(certificate.privateKey, algorithm: 'RS256');
ServiceAccountCredential('service-account.json')
UNDEFIEND serviceaccountCredential
Inside Credentials class there are hardcoded informations inside login method.
I don`t know if its an error or it was supposed to be there.
Hi!
I am facing the issue with app authentication using the following code:
final credential = FirebaseAdmin.instance.certFromPath('path/to/private/key');
final token = await credential.getAccessToken();
The output is:
FirebaseAppError(app/invalid-credential): Credential implementation provided to initializeApp() via the "credential" property failed to fetch a valid Google OAuth2 access token with the following error: "Invalid argument(s): State does not match."
I tried to find what's wrong and found that when creating the credential, the Flow.callback is called without state key in the response map. In case of jwtBearer flow the Flow.state is randomly generated and it is compared to response.state in Flow.callback.
As the response.state is empty, state validation fails with the output described above.
I am not a guru of all this authentication stuff and not sure if removing state validation is a good solution here, but it fixes this issue.
I Is there a known workaround for this issue?
Thanks!
always trow to page google login with error Missing required parameter: client_id
I can't get a service account to work with this library. Is there some secret for doing so that needs to be documented?
I'm saving a service-account.json and using Credentials.applicationDefault()
, but it does not work. It does work when I remove that (it finds credentials in the .config/configstore/firebase-tools.json
). I've tried generating a key for both the firebase-admin service account, and for a custom service account with firebase-admin privileges, but neither approach works.
Currently UserRecord is not being exported by firebase_admin.dart, which I believe is important for working with the data being returned by firebase_admin auth apis.
My workaround right now is to import the file directly, but importing an implementation file (which it is, until it's exported) is bad practice.
> Task :app:compileFlutterBuildProdDebug
../../../.pub-cache/hosted/pub.dartlang.org/firebase_admin-0.1.4/lib/src/auth/auth_api_request.dart:37:61: Error: The argument type 'String' can't be assigned to the parameter type 'Uri'.
- 'Uri' is from 'dart:core'.
var response = await httpClient.post('$baseUrl$endpoint',
PR will follow
The ServiceAccountMockCredential class contains an access token mock-access-token
(line 38 in test.dart)
However access tokens should be in the JSON webtoken ( RFC 7519) standard format. mock-access-token does not following this formatting standard, hence it's being rejected when trying to use the ServiceAccountMockCredentials in a unit test.
I'm not sure whether the sample is outdated, but the first example on pub.dev doesn't seem to work. Even though I imported credentials.dart, even though I can see the ServiceAccountCredential class in the implementation file. I get undefined class whenever I try to use ServiceAccountCredential.
I followed install and import as per pub.dev.
Also Flutter (or at least VSCode) doesn't seem to like the credentials.dart import.
Running under Windows.
The class definition for GoogleCloudIdentitytoolkitV1ProviderUserInfo
cannot be found in firebase_admin. Instead it can be found in a dependency: https://github.com/invertase/dart_firebase_apis/blob/541a555ac378f7fadfdd404f5de04e6898da9523/generated/firebaseapis/lib/identitytoolkit/v1.dart#L3996
Seems like firebase_admin is unexpectedly getting this class rather than raw json data for deserialization.
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Invalid argument (value): Cannot be converted to a deep immutable object: Instance of 'GoogleCloudIdentitytoolkitV1ProviderUserInfo'
#0 toDeepImmutable
deep_immutable.dart:90
#1 new _DeepImmutableList.<anonymous closure>
deep_immutable.dart:123
#2 MappedListIterable.elementAt (dart:_internal/iterable.dart:415:31)
#3 ListIterator.moveNext (dart:_internal/iterable.dart:344:26)
#4 new _List._ofEfficientLengthIterable (dart:core-patch/array.dart:162:27)
#5 new _List.of (dart:core-patch/array.dart:127:20)
#6 new List.of (dart:core-patch/array_patch.dart:49:20)
#7 new List.from (dart:core-patch/array_patch.dart:33:19)
#8 new List.unmodifiable (dart:core-patch/array_patch.dart:67:24)
#9 new _DeepImmutableList
deep_immutable.dart:122
#10 toDeepImmutable
deep_immutable.dart:84
#11 new _DeepImmutableMap.<anonymous closure>
deep_immutable.dart:115
#12 MapBase.map (dart:collection/maps.dart:82:28)
#13 new _DeepImmutableMap
deep_immutable.dart:114
#14 toDeepImmutable
deep_immutable.dart:88
#15 new _SnapshotImpl
snapshot.dart:254
#16 _SnapshotImpl.set
snapshot.dart:362
#17 new UnmodifiableSnapshotView.fromJson
snapshot_view.dart:77
#18 new UserRecord.fromJson
user_record.dart:136
#19 AuthRequestHandler.downloadAccount.<anonymous closure>
auth_api_request.dart:93
#20 MappedListIterable.elementAt (dart:_internal/iterable.dart:415:31)
#21 ListIterator.moveNext (dart:_internal/iterable.dart:344:26)
#22 new _GrowableList._ofEfficientLengthIterable (dart:core-patch/growable_array.dart:189:27)
#23 new _GrowableList.of (dart:core-patch/growable_array.dart:150:28)
#24 new List.of (dart:core-patch/array_patch.dart:47:28)
#25 ListIterable.toList (dart:_internal/iterable.dart:214:7)
#26 AuthRequestHandler.downloadAccount
auth_api_request.dart:94
<asynchronous suspension>
#27 Auth.listUsers
auth.dart:56
<asynchronous suspension>
('invalid_grant: Invalid grant: account not found', '{"error":"invalid_grant","error_description":"Invalid grant: account not found"}')
Code has errors
[{
"resource": "/home/steve/Documents/GitHub/forks/firebase_admin/lib/src/database.dart",
"owner": "generated_diagnostic_collection_name#0",
"code": {
"value": "invalid_override",
"target": {
"$mid": 1,
"external": "https://dart.dev/diagnostics/invalid_override",
"path": "/diagnostics/invalid_override",
"scheme": "https",
"authority": "dart.dev"
}
},
"severity": 8,
"message": "'_AuthTokenProvider.onTokenChanged' ('Stream<String?> Function()') isn't a valid override of 'AuthTokenProvider.onTokenChanged' ('Stream<Future?> Function()').",
"source": "dart",
"startLineNumber": 25,
"startColumn": 23,
"endLineNumber": 25,
"endColumn": 37
}]
The http
update to 1.0.0 is breaking dependencies all over the place, including firebase_admin
:
Because no versions of firebase_admin match >0.2.0 <0.3.0 and firebase_admin 0.2.0 depends on http ^0.13.0, firebase_admin ^0.2.0 requires http ^0.13.0.
So, because firedart depends on both http ^1.0.0 and firebase_admin ^0.2.0, version solving failed.
grpc-dart
solved the problem by specifying a version window: http: '>=0.13.0 <2.0.0'
https://github.com/grpc/grpc-dart/pull/629/files
I am using FirebaseAdmin to verify the token using the following code
final authToken = request.raw.headers["token"][0];
await FirebaseAdmin.instance.app().auth().verifyIdToken(authToken);
When I set
await FirebaseAdmin.instance.app().auth().verifyIdToken(authToken,true);
It returns the following error
FirebaseAppError(app/invalid-credential): Credential implementation provided to initializeApp() via the "credential" property failed to fetch a valid Google OAuth2 access token with the following error: "Invalid argument(s): State does not match".
Please check this error and let me know if I am making any mistakes.
https://firebase.google.com/docs/database/admin/start#authenticate-with-limited-privileges mentions a good way of authorizing an admin for the realtime database is to provide some specialized uid which is passed in while initializing the firebase app (via a fxn called AuthVariableOverride
).
Is there a way to do this in this package?
Dart: 1.13.4
package version: firebase_admin: ^0.2.0-dev.0
Including the repo gives this error:
.../.pub-cache/hosted/pub.dartlang.org/firebase_dart-1.0.0-dev.41/lib/src/database/impl/treestructureddata/treestructureddata.dart:59:14: Error: Both Iterable and Map spread elements encountered in ambiguous literal.
json = {...json.asMap()}..removeWhere((k, v) => v == null);
It looks like it can be fixed by giving the offending line a cast to explicitly tell the compiler the result is a Map and not a Set as follows:
json = <dynamic, dynamic>{...json.asMap()}
..removeWhere((k, v) => v == null);
Hi
Thank you for fixing state validation error.
Unfortunately, there is a new error coming from the new version 0.1.3 and error is given below.
Credential implementation provided to initializeApp() via the "credential" property failed to fetch a valid Google OAuth2 access token with the following error: "OpenIdException(invalid_grant): Invalid JWT Signature.". There are two likely causes: (1) your server time is not properly synced or (2) your certificate key file has been revoked. To solve (1), re-sync the time on your server. To solve (2), make sure the key ID for your key file is still present at https://console.firebase.google.com/iam-admin/serviceaccounts/project. If not, generate a key file at https://console.firebase.google.com/project/_/settings/serviceaccounts/adminsdk.
I have done the following.
I'm not sure what needs done to fix this, but with App Check enabled database actions silently fail. Also having an easier way to tell when database actions fail would be nice. I tried debugging them but came up empty handed.
Hi, I'm trying to use this to verify a JWT token sent from my UI (which uses Firebase Auth) to my custom backend server and I can't seem to use ServiceAccountCredential as shown in the front example (doesn't seem available in namespace).
I thought I could maybe instead use Credentials.cert('path/to/my/private/key.json') but that seems unimplemented.
What would be the best approach here? (I'm trying to follow these instructions: https://firebase.google.com/docs/auth/admin/verify-id-tokens#nodejs)
I tried this package in my project but still, it return this response:
Unsupported operation: Unsupported platform: android
I tried the same implementation but nothing worked.
by the way, what's this? where do we need to store the service-account.json file?
// * a configuration file, specific for this library, stored in the user's home directory
I have tried two approaches.
Here is an absolute path of my file: E:\Flutter_projects\Personal\authorization\service-account.json (root of the project)
In case it tries to look into android app I also put this file here and here:
E:\Flutter_projects\Personal\authorization\android\app\service-account.json
E:\Flutter_projects\Personal\authorization\android\service-account.json
But it did not help :( What am I doing wrong?
It is pure Dart, so hopefully it's doable? You won't be able to save credentials to the disk or look for credentials on disk, but you could use HTML local storage for such things (or just use shared_settings and it'll work automatically).
Any chance you guys upgrade this package. Thank you!
Because firebase_admin 0.1.4 depends on http ^0.12.0 and no versions of firebase_admin match >0.1.4 <0.2.0, firebase_admin ^0.1.4 requires http ^0.12.0.
So, because your app depends on both http ^0.13.0 and firebase_admin ^0.1.4, version solving failed.
Please upgrade - this plugin is stopping me from upgrading my app to newer versions of firebase and everything else due to dependancies.
I'm using the following dependencies in pubspec.yamp
firebase_admin: ^0.1.2
I have also created the environment variable in Win10
GOOGLE_APPLICATION_CREDENTIALS=C:\Users\Faisel\Downloads\service-account.json
Added the following in build.gradle
classpath 'com.google.firebase:firebase-admin:5.3.1'
I'm using the following code and I'm getting Unsupported operation: Unsupported platform: android
var credential = Credentials.applicationDefault();
credential ??= await Credentials.login();
var projectId = 'mtm-res-123456';
// create an app
var app = FirebaseAdmin.instance.initializeApp(AppOptions(
credential: credential ?? Credentials.applicationDefault(),
projectId: projectId,
storageBucket: '$projectId.appspot.com'));
If I remove the line, credential ??= await Credentials.login(); I'm getting the following error message.
I/flutter (14814): Credential implementation provided to initializeApp() via the "credential" property failed to fetch a valid Google OAuth2 access token with the following error: "NoSuchMethodError: The method 'getAccessToken' was called on null.
I have also tried this code,
var app = FirebaseAdmin.instance.initializeApp(AppOptions(
credential: FirebaseAdmin.instance.certFromPath('/project/app/service-account.json'),
));
In this case, I get the following error message
I/flutter (14814): FirebaseAppError(app/invalid-credential): Failed to parse certificate key file: FileSystemException: Cannot open file, path = '/project/app/service-account.json' (OS Error: No such file or directory, errno = 2)
service-account.json is located in same folder as google-services.json.
I'm trying with my emulator.
Please help me. What am I doing wrong?
@rbellens It seems like this package is not really maintained anymore. Are there any plans on continuing with this package in the near future?
I can also offer my help if the problem is missing time. Please let me know how I can contribute.
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.