Auth tokens

This commit is contained in:
David Bomba 2022-07-28 16:29:42 +10:00
parent d98fd30add
commit b44e1a02ca
4 changed files with 83 additions and 11 deletions

View File

@ -22,7 +22,7 @@ class Yodlee
private string $test_api_endpoint = 'https://sandbox.api.yodlee.com/ysl'; private string $test_api_endpoint = 'https://sandbox.api.yodlee.com/ysl';
protected string $fast_track_url = 'https://fl4.sandbox.yodlee.com/authenticate/restserver/fastlink'; public string $fast_track_url = 'https://fl4.sandbox.yodlee.com/authenticate/restserver/fastlink';
protected string $client_id; protected string $client_id;
@ -47,16 +47,68 @@ class Yodlee
public function getAccessToken() public function getAccessToken()
{ {
return $this->bankRequest('/auth/token', 'post'); $response = $this->bankFormRequest('/auth/token', 'post');
return $response->token->accessToken;
}
public function createUser()
{
// {
// "user": {
// "preferences": {
// "dateFormat": "string",
// "timeZone": "string",
// "currency": "USD",
// "locale": "en_US"
// },
// "address": {
// "zip": "string",
// "country": "string",
// "address3": "string",
// "address2": "string",
// "city": "string",
// "address1": "string",
// "state": "string"
// },
// "loginName": "string",
// "name": {
// "middle": "string",
// "last": "string",
// "fullName": "string",
// "first": "string"
// },
// "email": "string",
// "segmentName": "string"
// }
// }
$user['user'] = [
'loginName' => 'test123',
];
return $this->bankRequest('/user/register', 'post', $user);
} }
private function bankRequest(string $uri, string $verb, array $data = []) private function bankRequest(string $uri, string $verb, array $data = [])
{ {
nlog($this->getHeaders());
nlog($this->buildBody());
nlog($this->api_endpoint . $uri);
$response = Http::withHeaders($this->getHeaders())->asForm()->{$verb}($this->api_endpoint . $uri, $this->buildBody()); $response = Http::withHeaders($this->getHeaders(['loginName' => $this->admin_name]))->{$verb}($this->api_endpoint . $uri, $this->buildBody());
if($response->successful())
return $response->object();
if($response->failed())
return $response->body();
}
private function bankFormRequest(string $uri, string $verb, array $data = [])
{
$response = Http::withHeaders($this->getFormHeaders(['loginName' => $this->admin_name]))->asForm()->{$verb}($this->api_endpoint . $uri, $this->buildBody());
if($response->successful()) if($response->successful())
return $response->object(); return $response->object();
@ -70,7 +122,15 @@ class Yodlee
{ {
return array_merge($data, [ return array_merge($data, [
'Api-Version' => '1.1', 'Api-Version' => '1.1',
'loginName' => $this->admin_name 'ContentType' => 'application/json'
]);
}
private function getFormHeaders($data = [])
{
return array_merge($data, [
'Api-Version' => '1.1',
]); ]);
} }

View File

@ -11,6 +11,7 @@
namespace App\Http\Controllers\Bank; namespace App\Http\Controllers\Bank;
use App\Helpers\Bank\Yodlee\Yodlee;
use App\Http\Controllers\BaseController; use App\Http\Controllers\BaseController;
use Illuminate\Http\Request; use Illuminate\Http\Request;
@ -20,10 +21,11 @@ class YodleeController extends BaseController
public function auth(Request $request) public function auth(Request $request)
{ {
$yodlee = new Yodlee(); $yodlee = new Yodlee(true);
$data = [ $data = [
'access_token' => $yodlee->getAccessToken() 'access_token' => $yodlee->getAccessToken(),
'fasttrack_url' => $yodlee->fast_track_url
]; ];
return view('bank.yodlee.auth', $data); return view('bank.yodlee.auth', $data);

View File

@ -27,10 +27,10 @@
'click', 'click',
function() { function() {
window.fastlink.open({ window.fastlink.open({
fastLinkURL: 'https://fl4.sandbox.yodlee.com/authenticate/restserver/fastlink', fastLinkURL: '{{ $fasttrack_url }}',
accessToken: 'Bearer {{ $access_token }}', accessToken: 'Bearer {{ $access_token }}',
params: { params: {
configName : '<config-name-from-config-tool>' configName : 'Example2'
}, },
onSuccess: function (data) { onSuccess: function (data) {
// will be called on success. For list of possible message, refer to onSuccess(data) Method. // will be called on success. For list of possible message, refer to onSuccess(data) Method.

View File

@ -37,4 +37,14 @@ class YodleeApiTest extends TestCase
$this->assertNotNull($access_token); $this->assertNotNull($access_token);
} }
public function testCreateUser()
{
$yodlee = new Yodlee(true);
$create_user = $yodlee->createUser();
nlog($create_user);
}
} }