Skip to content

Commit

Permalink
Start adding upwork
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed Dec 27, 2023
1 parent 633132a commit 0587c67
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 1 deletion.
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -31,6 +31,7 @@
"symfony/http-client": "^6.2",
"symfony/postmark-mailer": "^6.2",
"tightenco/ziggy": "^1.0",
"upwork/php-upwork-oauth2": "^2.4",
"voku/stop-words": "^2.0",
"wamania/php-stemmer": "^3.0",
"webklex/laravel-imap": "^5.3"
Expand Down
133 changes: 132 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions routes/api.php
Expand Up @@ -22,3 +22,17 @@
Route::post(
'/signed', [SignedUrlAuth::class, 'create']
)->name('signed_url.create');


Route::get('/upwork/callback', function (Request $request) {
$authorizationCode = $request->get('code');

logger("Code coming in " . $authorizationCode);
// With this authorization code, you can now request an access token
// by sending a POST request to the authorization server with your clientId, clientSecret
// grantType('authorization_code'), redirectUri, and authorizationCode you just received

// Make sure to handle errors appropriately and securely store access tokens.

return "OK";
});
41 changes: 41 additions & 0 deletions tests/Feature/UpworkTest.php
@@ -0,0 +1,41 @@
<?php

namespace Tests\Feature;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;

class UpworkTest extends TestCase
{
/**
* A basic feature test example.
*/
public function test_connects(): void
{
$config = new \Upwork\API\Config(
array(
'clientId' => env("UPWORK_KEY"), // SETUP YOUR CONSUMER KEY
'clientSecret' => env("UPWORK_SECRET"), // SETUP KEY SECRET
//'grantType' => 'client_credentials', // used in Client Credentials Grant
'redirectUri' => 'https://e538b8057c8e.ngrok.app/api/upwork/callback', // used in Code Authorization Grant
//'accessToken' => null, // WARNING: keep this up-to-date!
//'refreshToken' => null, // WARNING: keep this up-to-date! // NOT needed for Client Credentials Grant
//'expiresIn' => null, // WARNING: keep this up-to-date!
//'debug' => true, // enables debug mode
//'authType' => 'MyOAuthPHPLib' // your own authentication type, see AuthTypes directory
)
);

$client = new \Upwork\API\Client($config);
//$client::setOrgUidHeader('1234567890'); // Organization UID (optional)

// $accessTokenInfo has the following structure
// array('access_token' => ..., 'refresh_token' => ..., 'expires_in' => ...);
// keeps the access token in a secure place
// gets info of authenticated user
$accessTokenInfo = $client->auth();

dd($accessTokenInfo);
}
}

0 comments on commit 0587c67

Please sign in to comment.