Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sumocoders/teamleader-oauth2
PHP Teamleader oauth2 package to connect with Teamleader API (https://developer.teamleader.eu/)
https://github.com/sumocoders/teamleader-oauth2
oauth2 teamleader
Last synced: about 1 month ago
JSON representation
PHP Teamleader oauth2 package to connect with Teamleader API (https://developer.teamleader.eu/)
- Host: GitHub
- URL: https://github.com/sumocoders/teamleader-oauth2
- Owner: sumocoders
- License: bsd-2-clause
- Created: 2022-11-16T11:33:57.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-03T10:12:28.000Z (8 months ago)
- Last Synced: 2024-11-14T19:14:29.975Z (about 2 months ago)
- Topics: oauth2, teamleader
- Language: PHP
- Homepage:
- Size: 27.3 KB
- Stars: 3
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Teamleader oauth2
## Installation
`composer require sumocoders/teamleader-oauth2`
## Setup
This package uses PSR-17 and PSR-18. You can use any implementation you want.
For saving the access we provide a TokenStorageInterface, where you'll need to implement storing and fetching of the tokens:
```php
interface TokenStorageInterface
{
public function getTokenType(): string;
public function getAccessToken(): ?string;
public function getRefreshToken(): ?string;
public function isExpired(): bool;
public function storeTokens(array $tokens): void;
}
```Look at the [default token storage class](https://github.com/sumocoders/teamleader-oauth2/blob/main/src/Storage/FilesystemTokenStorage.php) how you can make your own implementation.
The Teamleader class will need a clientId and clientSecret. Which you'll need to obtain at the [Teamleader marketplace](https://marketplace.teamleader.eu/).
## Usage
To obtain an access token you'll need to call:
```php
$teamleader->acquireAccessToken($redirectUrl, $code);
```Where `$redirectUrl` is the url you want Teamleader to come back to after Oauth2 authentication and `$code` is for the return when Teamleader comes back to your site and validate the authentication.
After that you can use the Teamleader class to make calls to the Teamleader API. When the access token is expired the Teamleader class will automatically refresh the token.
## Getting data
```php
$teamleader->get('users.me');
$teamleader->get('departments.list');
$teamleader->get('companies.list');
```## Posting data
```php
$teamleader->post(
'contacts.add',
[
'first_name' => 'John',
'last_name' => 'Doe',
]
);
$teamleader->post(
'contacts.update',
[
'id' => 'xxx',
'first_name' => 'John',
'last_name' => 'Doe',
'emails' => [
['type' => 'primary', 'email' => '[email protected]'],
],
]
)
```