Search code examples
phpoauthgoogle-apifirebase-cloud-messaginggoogle-api-php-client

why does my oauth access token obtained using google api client contains plenty of '...'


I am using PHP to get oauth token for FCM however the access token returned contains a lot of '....'

$client= new \Google_Client();
    error_log(__DIR__);
    $client->setAuthConfig(__DIR__ . '/service-account-key.json');
    $client->addScope('https://www.googleapis.com/auth/firebase.messaging');
    $client->refreshTokenWithAssertion();
    $token = $client->getAccessToken();

    error_log(json_encode($token));
    return $token;

Result

The actual access token doesnt contain the asterisk(*), it used to be characters that i have replaced with asterisks to censor out the token.

{"access_token":"ya29.*.b*************r1FYWFz***CCg3v8VYHTlu*******************hiMIDhSX******6UfwvazfOcuV***********ewuo-c87WgM-ir
S5unipu0goCl3RtC_0g7hkjqNwQ2pcZjmJCZIr7JM5VwD4........................................................................................................................................................................................
......................................................................................................................................................................................................................................
......................................................................................................................................................................................................................................
....................................................................................................................................................","expires_in":3599,"token_type":"Bearer","created":1652776589}

Can someone please tell me why it is returning a bunch of '.'


Solution

  • Despite the access token being returned is filled periods(...), there is no issue using that access token to send a FCM notification. The issue that prevent me from sending a notification out is due to not following the correct payload format to send out the data.

    Ideal payload format

    $data = array(
                    "message" => array(
                        "token" => $user->device_token,
                        "notification" => array(
                            "title" => "New Task",
                            "body" => "Hi " . $user->name . ",\nYou have a new " . $ticket_description ." task to work on.",
                        ),
                        "data" => array(
                            "notification_id" => $notificationMessage->id,
                            "item_id" => $notificationMessage->item_id,
                            "ticket_classification" =>   $notificationMessage->classification,
                            "ticket_segment_type" => $notificationMessage->segment_type,
                            "routing_page"=>$notificationMessage->page_routing_classification,
                            "title" => $notificationMessage->title ,
                            "body" => $notificationMessage->body ,
                        ),
    
                        "android" => array(
                            "priority" => "high",
                            "notification" => array(
                                "sound" => 'default',
                                //So that noptification can be sent while the app is killed
                                "click_action" => "FCM_PLUGIN_ACTIVITY",
                            )
                        )
                    )
                );