Giter Site home page Giter Site logo

firebase_admin's People

Contributors

rbellens avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

firebase_admin's Issues

Sending reset/verify mails

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?

Invalid argument(s): The given string does not have the correct begin marker expected in a PEM file

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)

Firebase Custom Tokens generated by this are invalid

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');

State validation fails when getting access token

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!

Service Account not working

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.

Export UserRecord

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.

Outdated implementation of http

> 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

ServiceAccountMockCredential contains bad formatted access token

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.

No access to ServiceAccountCredential class

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.

Calling `listUsers` throws "Cannot be converted to a deep immutable object: Instance of 'GoogleCloudIdentitytoolkitV1ProviderUserInfo’"

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>

_AuthTokenProvider.onTokenChanged' ('Stream<String?> Function()') isn't a valid override of 'AuthTokenProvider.onTokenChanged

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
}]

Update http package dependency

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

FirebaseAdmin fails to verify Id Token when checkRevoked is set as true.

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.

Both Iterable and Map spread elements encountered in ambiguous literal

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);

OpenIdException(invalid_grant): Invalid JWT Signature in 0.1.3

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.

  1. Synced my time in my Windows 10 system.
  2. Reconfirmed that the service key exists on the console and iam as well.
  3. I have tried both the ways using service json file and credential methods on the example page.

Does not work with App Check enabled

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.

Can't use ServiceAccountCredential

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)

Unsupported operation: Unsupported platform: android

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

Still can not access 'service-account.json' file

I have tried two approaches.

  1. Credentials.applicationDefault() --> returns null;
  2. Credential credentials =
    FirebaseAdmin.instance.certFromPath("service-account.json"); --> throws FileNotFoundException

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?

any plans to make this work on the web?

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).

Supporting Flutter 2

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.

Unsupported operation: Unsupported platform: android

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?

Is this still maintained?

@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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.