Fix #82 Adjust the FlexisipPusherConnector to fit with the recent changes

This commit is contained in:
Timothée Jaussoin 2023-03-21 15:46:02 +00:00
parent bf5a33918f
commit c5deca93a6
8 changed files with 326 additions and 340 deletions

View file

@ -106,7 +106,7 @@ We advise you to copy the `style.css` file and rename it to make your custom CSS
#### Flexisip Push notifications pusher
The API endpoint `POST /account_creation_tokens/send-by-push` uses the `flexisip_pusher` binary delivered by the [Flexisip](https://gitlab.linphone.org/BC/public/flexisip) project (and related package). You must configure the `APP_FLEXISIP_PUSHER_PATH` environement variable to point to the correct binary.
The API endpoint `POST /account_creation_tokens/send-by-push` uses the `flexisip_pusher` binary delivered by the [Flexisip](https://gitlab.linphone.org/BC/public/flexisip) project (and related package). You must configure the `APP_FLEXISIP_PUSHER_PATH` and `APP_FLEXISIP_PUSHER_FIREBASE_KEY` environnement variables to point to the correct binary.
APP_FLEXISIP_PUSHER_PATH=/opt/belledonne-communications/bin/flexisip_pusher

View file

@ -7,6 +7,7 @@ APP_SIP_DOMAIN=sip.example.com
APP_LINPHONE_DAEMON_UNIX_PATH=
APP_FLEXISIP_PUSHER_PATH=
APP_FLEXISIP_PUSHER_FIREBASE_KEY=
APP_API_KEY_EXPIRATION_MINUTES=60 # Number of minutes the generated API Keys are valid

View file

@ -38,21 +38,6 @@ class AccountCreationTokenController extends Controller
'pn_prid' => 'required',
]);
if (AccountCreationToken::where('pn_provider', $request->get('pn_provider'))
->where('pn_param', $request->get('pn_param'))
->where('pn_prid', $request->get('pn_prid'))
->where('used', false)
->count() > 0) {
abort(403, 'A similar token was already used');
}
if (AccountCreationToken::where('pn_provider', $request->get('pn_provider'))
->where('pn_param', $request->get('pn_param'))
->where('pn_prid', $request->get('pn_prid'))
->count() > 3) {
abort(403, 'The limit of tokens generated for this device has been reached');
}
$token = new AccountCreationToken;
$token->token = Str::random(WebAuthenticateController::$emailCodeSize);
$token->pn_provider = $request->get('pn_provider');

View file

@ -34,6 +34,10 @@ class FlexisipPusherConnector
$this->pnProvider = $pnProvider;
$this->pnParam = $pnParam;
$this->pnPrid = $pnPrid;
if ($this->pnProvider == 'fcm' && config('app.flexisip_pusher_firebase_key') == null) {
Log::error('Firebase pusher key not configured');
}
}
public function sendToken(string $token)
@ -42,11 +46,14 @@ class FlexisipPusherConnector
if (!empty($this->pusherPath)) {
$command = $this->pusherPath
. " --pn-provider '" . $this->pnProvider . "'"
. " --pn-param '" . $this->pnParam . "'"
. " --pn-prid " . $this->pnPrid
. " --apple-push-type Background"
. " --customPayload '" . $payload . "'";
. " --pn-provider '" . $this->pnProvider . "'"
. " --pn-param '" . $this->pnParam . "'"
. " --pn-prid " . $this->pnPrid
. " --customPayload '" . $payload . "'";
$command .= in_array($this->pnProvider, ['apns', 'apns.dev'])
? " --apple-push-type Background"
: " --key " . config('app.flexisip_pusher_firebase_key');
$output = null;
$retval = null;

View file

@ -76,4 +76,4 @@
"@php artisan key:generate --ansi"
]
}
}
}

614
flexiapi/composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -41,6 +41,7 @@ return [
* External interfaces
*/
'flexisip_pusher_path' => env('APP_FLEXISIP_PUSHER_PATH', null),
'flexisip_pusher_firebase_key' => env('APP_FLEXISIP_PUSHER_FIREBASE_KEY', null),
'linphone_daemon_unix_pipe' => env('APP_LINPHONE_DAEMON_UNIX_PATH', null),
/**

View file

@ -52,18 +52,6 @@ class ApiAccountCreationTokenTest extends TestCase
$response->assertStatus(503);
}
public function testLimit()
{
$token = AccountCreationToken::factory()->create();
$response = $this->json($this->method, $this->tokenRoute, [
'pn_provider' => $token->pn_provider,
'pn_param' => $token->pn_param,
'pn_prid' => $token->pn_prid,
]);
$response->assertStatus(403);
}
/**
* For retro-compatibility only
*/
@ -76,7 +64,7 @@ class ApiAccountCreationTokenTest extends TestCase
'pn_param' => $token->pn_param,
'pn_prid' => $token->pn_prid
]);
$response->assertStatus(403);
$response->assertStatus(503);
}
public function testInvalidToken()