Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
"intercom"
],
"require": {
"php": "^5.6|^7.0",
"league/oauth2-client": "~2.3"
"php": "^8.0",
"league/oauth2-client": "^2.6"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"mockery/mockery": "~0.9",
"squizlabs/php_codesniffer": "~2.0"
"phpunit/phpunit": "^9.5",
"mockery/mockery": "^1.5",
"squizlabs/php_codesniffer": "^3.6"
},
"autoload": {
"psr-4": {
Expand Down
23 changes: 12 additions & 11 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
Expand All @@ -8,19 +9,19 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">./</directory>
</include>
<exclude>
<directory suffix=".php">./vendor</directory>
<directory suffix=".php">./tests</directory>
</exclude>
</coverage>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./</directory>
<exclude>
<directory suffix=".php">./vendor</directory>
<directory suffix=".php">./tests</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
41 changes: 24 additions & 17 deletions src/Provider/Intercom.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,37 @@

namespace Intercom\OAuth2\Client\Provider;

use JetBrains\PhpStorm\ArrayShape;
use League\OAuth2\Client\Provider\AbstractProvider;
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
use League\OAuth2\Client\Provider\ResourceOwnerInterface;
use League\OAuth2\Client\Token\AccessToken;
use Psr\Http\Message\ResponseInterface;

class Intercom extends AbstractProvider
{

/**
* @var boolean By default Intercom strategy rejects users with unverified email addresses.
* @var boolean By default, Intercom strategy rejects users with unverified email addresses.
*/
protected $verifyEmail = true;
protected bool $verifyEmail = true;

/**
* Get authorization url to begin OAuth flow
*
* @return string
*/
public function getBaseAuthorizationUrl()
public function getBaseAuthorizationUrl(): string
{
return 'https://app.intercom.com/oauth';
}

/**
* Get access token url to retrieve token
*
* @param array $params
* @return string
*/
public function getBaseAccessTokenUrl(array $params)
public function getBaseAccessTokenUrl(array $params): string
{
return 'https://api.intercom.io/auth/eagle/token';
}
Expand All @@ -42,7 +44,7 @@ public function getBaseAccessTokenUrl(array $params)
*
* @return string
*/
public function getResourceOwnerDetailsUrl(AccessToken $token)
public function getResourceOwnerDetailsUrl(AccessToken $token): string
{
return 'https://api.intercom.io/me';
}
Expand All @@ -55,18 +57,19 @@ public function getResourceOwnerDetailsUrl(AccessToken $token)
*
* @return array
*/
protected function getDefaultScopes()
protected function getDefaultScopes(): array
{
return [];
}

/**
* Check a provider response for errors.
* @throws IdentityProviderException
*/
protected function checkResponse(ResponseInterface $response, $data)
protected function checkResponse(ResponseInterface $response, $data): void
{
$statusCode = $response->getStatusCode();
if (empty($data['errors']) && $statusCode == 200) {
if (empty($data['errors']) && $statusCode === 200) {
return;
}

Expand All @@ -84,7 +87,8 @@ protected function checkResponse(ResponseInterface $response, $data)
*
* @return array
*/
protected function getDefaultHeaders()
#[ArrayShape(['Accept' => "string", 'User-Agent' => "string"])]
protected function getDefaultHeaders(): array
{
return [ 'Accept' => 'application/json', 'User-Agent' => 'league/oauth2-intercom/2.0.0' ];
}
Expand All @@ -104,10 +108,11 @@ protected function getAuthorizationHeaders($token = null)
/**
* Requests resource owner details.
*
* @param AccessToken $token
* @param AccessToken $token
* @return mixed
* @throws IdentityProviderException
*/
protected function fetchResourceOwnerDetails(AccessToken $token)
protected function fetchResourceOwnerDetails(AccessToken $token): mixed
{
$url = $this->getResourceOwnerDetailsUrl($token);

Expand All @@ -119,14 +124,16 @@ protected function fetchResourceOwnerDetails(AccessToken $token)
/**
* Generate a user object from a successful user details request.
*
* @param object $response
* @param array $response
* @param AccessToken $token
* @return League\OAuth2\Client\Provider\ResourceOwnerInterface
* @return IntercomResourceOwner|ResourceOwnerInterface
*/
protected function createResourceOwner(array $response, AccessToken $token)
{
protected function createResourceOwner(
array $response,
AccessToken $token
): IntercomResourceOwner|ResourceOwnerInterface {
$validatedResponse = $response;
if ($this->verifyEmail == true && $response['email_verified'] != true) {
if ($this->verifyEmail && !$response['email_verified']) {
$validatedResponse = [];
}
return new IntercomResourceOwner($validatedResponse);
Expand Down
Loading