Skip to content

Firebase Custom Tokens generated by this are invalid #19

@jpeiffer

Description

@jpeiffer

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions