Fonctionnement plugin ghlocal

Slt all,

Je voulais savoir si vous arriviez à faire fonctionner le plugin Google Devices …ou des évolutions côté GH ont été apportées rendant ce plugin non utilisable ?
Je suis bloqué à la première étape à savoir récupérer les tokens GH …dans la documentation il est précisé que le plugin est capable de récupérer les tokens mais il y a aussi une notion de récupération des tokens manuellement …

Sur la récupération auto j’ai cette erreur :

Extract sudo /root/go/bin/grpcurl -H 'authorization: Bearer [!] Could not get master token.' -import-path /var/www/html/plugins/ghlocal/core/class/../../data -proto /var/www/html/plugins/ghlocal/core/class/../../data/google/internal/home/foyer/v1.proto googlehomefoyer-pa.googleapis.com:443 google.internal.home.foyer.v1.StructuresService/GetHomeGraph | jq '.home.devices[] | {deviceName, localAuthToken}'
[2021-12-07 10:31:05][DEBUG] : Result
[2021-12-07 10:31:05][DEBUG] : Result Array (     [0] =>  )

A quoi correspond les autres champs (adresse google assistant relay) du formulaire de configuration du plugin ?

Je précise que je suis en double authent côté google et que le mdp a été testé et est opérationnel.

Je n’ai pas testé la récupération manuelle du token … mais dans le cas ou je le récupère ou dois-je le(s) renseigner ?

Par avance merci pour vos retour.
Cordialement
@chris94440

PS : jeedom déployé sur un buster 10

En complément j’ai controlé que le mdp de l’app google était ok … et il l’est … :slight_smile:
J’ai trouvé un projet php pour récupérer ce token … lorsque je l’exécute j’ai l’erreur : Error=BadAuthentication …qui voudrait dire que mes crédentials ne sont pas bons…mais je les ais testés … :thinking:

Quelqu’un pour qui ce la fonctionne pourrait il tester le scenario ci-dessous pour voir si il est opérationnel ou pas … :pray:

juste remplacez vos identifiants / mdp gmail
et copier le fichier joint en modifiant l’extension par pem dans /var/www/html/gpsoauth/
pubkey.txt (207,4 Ko)

//source https://github.com/endrsmar/gpsoauthphp/blob/master/src/GPSOAuthHelper.php

$_URL = 'https://android.clients.google.com/auth';
$_AGENT = 'mgr.go/0.0.1';
$_KEY = 'AAAAgMom/1a/v0lblO2Ubrt60J2gcuXSljGFQXgcyZWveWLEwo6prwgi3iJIZdodyhKZQrNWp5nKJ3srRXcUW+F1BD3baEVGcmEgqaLZUNBjm057pKRI16kB0YppeGx5qIQ5QjKzsR8ETQbKLNWgRY0QRNVz34kMJR3P/LgHax/6rmf5AAAAAwEAAQ==';

$email='************';
$password='*****************';

masterLogin('ac2dm','us','us','en',21,$email,$password,$_URL,$_KEY,$scenario);

function masterLogin($service = 'ac2dm', $deviceCountry = 'us', $operatorCountry = 'us', $lang = 'en', $sdkVersion = 21,$email,$password,$_URL,$_KEY,$scenario){
  $signature = CreateSignature($email, $password, GetPEMKey(), GetRSAKey($_KEY,$scenario),$scenario);
  //$scenario->setLog('signature : ' . $signature);
  //$scenario->setLog('Pem key : ' . GetPEMKey());
  //$scenario->setLog('RSA key : ' . json_encode(GetRSAKey($_KEY,$scenario)));
  $data = [
    'accountType' => 'HOSTED_OR_GOOGLE',
    'Email' => $email,
    'has_permission' => '1',
    'add_account' => '1',
    'EncryptedPasswd' => $signature,
    'service' => $service,
    'source' => 'android',
    'device_country' => $deviceCountry,
    'operatorCountry' => $operatorCountry,
    'lang' => $lang,
    'sdk_version' => ''.$sdkVersion
  ];
  return authRequest($data,$_URL,$scenario);
}

 function GetPEMKey(){
  return file_get_contents('/var/www/html/gpsoauth/pubkey.pem');
}

function GetRSAKey($_KEY,$scenario){
  return Base64ToRSAKey($_KEY,$scenario);
}

function authRequest(array $data,$_URL,$scenario){
  $curlHandle = curl_init();
  curl_setopt($curlHandle, CURLOPT_URL,$_URL);
  curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($curlHandle, CURLOPT_FOLLOWLOCATION, true);
  curl_setopt($curlHandle, CURLOPT_POST, 1);
  curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $data);
  curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt($curlHandle, CURLOPT_HTTPHEADER, [
    'User-Agent: mgrgo/0.0.1'
  ]);
  $result = curl_exec($curlHandle);
  $scenario->setLog('Resul : ' . json_encode($result));
  return ParseAuthResponse($result);
}

function ByteStringToInt32($source, $offset = 0){
  return (ord($source[$offset])<<24) + (ord($source[$offset+1])<<16) + (ord($source[$offset+2])<<8) + ord($source[$offset+3]);
}
		
function Base64ToRSAKey($key,$scenario){
  //$scenario->setLog('$key : ' . $key);
  $decoded = base64_decode($key);
  //$scenario->setLog('decode $key : ' . $decoded);
  $modLenght = ByteStringToInt32($decoded);
  $expLenght = ByteStringToInt32($decoded, 4 + $modLenght);
  //$scenario->setLog('$modLenght : ' . $modLenght);
  //$scenario->setLog('$expLenght : ' . $expLenght);
  $mod = substr($decoded, 4, $modLenght);
  $exp = substr($decoded, 8 + $modLenght, $expLenght);
  //$scenario->setLog('$mod : ' . $mod);
  //$scenario->setLog('$exp : ' . $exp);
  return ['modulus' => $mod, 'exponent' => $exp];
}
		
function ParseAuthResponse($response){
  $result = [];
  foreach (explode("\n", $response) as $line){
    if (!strlen($line)) continue;
    $kvp = explode('=', $line);
    $result[$kvp[0]] = $kvp[1];
  }
  return $result;
}
		
function KeyToStruct(array $key,$scenario){
  //$scenario->setLog('Modulus : ' . $key['modulus']);
  //$scenario->setLog('exponent : ' . $key['exponent']);
  return hex2bin('00000080'.bin2hex($key['modulus']).'00000003'.bin2hex($key['exponent']));
}
		
function CreateSignature($email, $password, $pemKey, $rsaKey,$scenario){
  $encrypted = '';
  openssl_public_encrypt($email.chr(0).$password, $encrypted, $pemKey, OPENSSL_PKCS1_OAEP_PADDING);
  $hash = substr(sha1(KeyToStruct($rsaKey,$scenario), true), 0, 4);
  return URLSafeBase64(chr(0).$hash.$encrypted);
}
		
function URLSafeBase64($input){
  return strtr(base64_encode($input), ['+' => '-', '/' => '_']);
}

second complément … :slight_smile:
La lib gpsoauth est installée sous python2.7 et python 3 … peut etre une cause non ?

Hi Folks,

I am working on same issue and fixed the recuperation of the Token using gpsoaut in version 0.4.1

Now I am stuck on the second part on grpcurl

Hi @Igor
Good new … i will try this version as soon as possible thx