Skip to content

Commit

Permalink
create Token traits
Browse files Browse the repository at this point in the history
  • Loading branch information
hbhossein committed Oct 2, 2023
1 parent 5242adc commit b811d6b
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/Traits/HasToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Jooyeshgar\Moadian\Traits;

use Jooyeshgar\Moadian\Facades\Moadian;
use Jooyeshgar\Moadian\Services\SignatureService;

trait HasToken
{
/**
* Create authorization token
*
* @param SignatureService $signer
*
*/
public function addToken(SignatureService $signer)
{
$payload = [
'nonce' => Moadian::getNonce(),
'clientId' => config('moadian.username')
];

$token = $signer->sign($payload);

$auth = 'Bearer ' . $token;
$this->headers['authorization'] = $auth;
}
}

0 comments on commit b811d6b

Please sign in to comment.