php-jwt icon indicating copy to clipboard operation
php-jwt copied to clipboard

Missing/Invalid claim "kid" in auth header

Open jigarius opened this issue 10 years ago • 9 comments

Getting error "Missing claim "kid" in auth header". When I add the key ID to get rid of this error, I get "Invalid claim 'kid' in auth header." - I request you to please let me know if you know something about this. Development has stopped for 2 days because of this issue. Thanks a tonne.

// Prepare payload options
$payload = array_merge(array (
    'iss' => $service_email,
    'sub' => $service_email,
    'aud' => 'https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit',
    'iat' => $now,
    'exp' => $now + ($ttl * 60),
    'claims' => array (),
), $options);

// Prepare payload claims
$payload['uid'] = firebase_uid2fbid($uid, TRUE);
$payload['claims'] = array(
    'provider' => 'drupal',
);

// Generate token
\Firebase\JWT\JWT::$leeway = 60;
$token = \Firebase\JWT\JWT::encode($payload, $service_key, 'RS256', $service_kid);

Here, the $server_kid = config.private_key_id and $server_email = config.client_email. If this is not an issue, please tell me what is it I am doing wrong.

jigarius avatar Jun 03 '16 02:06 jigarius

Cross posted here (please respect the community's time and indicate when you do this) and answered in part here, and here.

The second link includes the required attributes for the new auth SDK: image

katowulf avatar Jun 14 '16 18:06 katowulf

Same problem here, and I fail to see how the Stack Overflow posts address this issue?

Tom32i avatar Jun 28 '16 09:06 Tom32i

Looks like there is just some confusion with the custom authentication implementation between the old and the new Firebase SDKs. It seems that you're trying to send the custom tokens directly to the database, which is an old Firebase SDK implementation. In the new Firebase SDK, however, this is not supported, due to a change in the security model.

Depending on what you want to do, you may want to take one of the two approaches when you're working with the new version:

  1. Client to server: Create a custom token following the documentation https://firebase.google.com/docs/auth/server#use_a_jwt_library (without adding an extra kid field), send it to your client apps, and call signInWithCustomToken(customToken) in the client application. Now that application can make authenticated calls to the database.

  2. Server to server: If you want to do everything from your server, what you need to do is authenticate the database connections with a service account. This is explained here: http://stackoverflow.com/questions/37426093/using-custom-tokens-to-make-rest-requests-to-fb-db-as-an-admin http://www.google.com/url?q=http%3A%2F%2Fstackoverflow.com%2Fquestions%2F37426093%2Fusing-custom-tokens-to-make-rest-requests-to-fb-db-as-an-admin&sa=D&sntz=1&usg=AFQjCNEFpSgLGDXERK_gr6GQpaIkBpFr_A

Same problem here, and I fail to see how the Stack Overflow posts address this issue?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/firebase/php-jwt/issues/95#issuecomment-228992572, or mute the thread https://github.com/notifications/unsubscribe/AEFmUQ40u0AnjGDbmWWOJFjrkJ-xywQxks5qQOLTgaJpZM4ItJRi .

jigarius avatar Jun 28 '16 11:06 jigarius

Thanks for your answer.

Do you know if it is possible at all to call a Firebase database from a PHP server with Auth enabled?

Tom32i avatar Jun 28 '16 12:06 Tom32i

@Tom32i I am using this project for calling Firebase database from PHP. https://github.com/kreait/firebase-php In the new firebase web console click the gear icon -> Permissions -> Service Accounts. Create new one for your server, they give a .json file with the key for the service account, put this in safe place on php server and load it in the config of this project, (they have good documentation.) http://firebase-php.readthedocs.io/en/latest/

timtimmytime avatar Jul 23 '16 15:07 timtimmytime

@jrm1987

This is explained here:

that link contains only this text, related to server-to-server:

Also, making the request to the firebase REST API is still an exercise for the reader.

e-oz avatar Jul 23 '16 16:07 e-oz

Actually, I copied and pasted the exact answer which Google sent me.

El 23 jul. 2016 11:46 a. m., "Evgeniy OZ" [email protected] escribió:

@jrm1987 https://github.com/jrm1987

This is explained here:

that link contains only this text, related to server-to-server:

Also, making the request to the firebase REST API is still an exercise for the reader.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/firebase/php-jwt/issues/95#issuecomment-234727963, or mute the thread https://github.com/notifications/unsubscribe-auth/AEFmUc8DCsUtadUCrijs4ZXyY0NPDtkaks5qYkVNgaJpZM4ItJRi .

jigarius avatar Jul 23 '16 18:07 jigarius

Shouldnt this be closed? Im using the "kid" in the current version (5) and it is working as expected.

cottton avatar Jul 27 '18 16:07 cottton

There are 3 token type. But firebase only verify token from client app. https://github.com/kreait/firebase-php/issues/169#issuecomment-366950404

khuongphp avatar Apr 26 '20 11:04 khuongphp