Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#5 Добавлен провайдер для отправки application/json запросов #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
4 changes: 3 additions & 1 deletion src/AmoCRM.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AmoCRM extends AbstractProvider
* @var array
*/
public $headers = [
'User-Agent' => 'amoCRM/oAuth Client 1.0',
'User-Agent' => 'amoCRM/oAuth Client 1.1',
];

/**
Expand All @@ -45,8 +45,10 @@ class AmoCRM extends AbstractProvider
*/
public function __construct($options = [], $collaborators = [])
{
$collaborators['optionProvider'] = new PostAuthOptionProvider();
parent::__construct($options, $collaborators);


if (isset($options['baseDomain'])) {
$this->baseDomain = $options['baseDomain'];
}
Expand Down
26 changes: 26 additions & 0 deletions src/PostAuthOptionProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace AmoCRM\OAuth2\Client\Provider;

use League\OAuth2\Client\OptionProvider\OptionProviderInterface;
use League\OAuth2\Client\Provider\AbstractProvider;
use League\OAuth2\Client\Tool\QueryBuilderTrait;

class PostAuthOptionProvider implements OptionProviderInterface
{
use QueryBuilderTrait;

/**
* @inheritdoc
*/
public function getAccessTokenOptions($method, array $params)
{
$options = ['headers' => ['Content-Type' => 'application/json']];

if ($method === AbstractProvider::METHOD_POST) {
$options['body'] = json_encode($params, JSON_UNESCAPED_SLASHES);
}

return $options;
}
}