Skip to content

Commit

Permalink
Support Callable Component Config
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Mar 3, 2021
1 parent d742495 commit 201b084
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Providers/WeChat.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class WeChat extends Base
public function __construct(array $config)
{
parent::__construct($config);
$this->prepareForComponent();
}

/**
Expand Down Expand Up @@ -58,6 +57,23 @@ public function tokenFromCode(string $code): array
return $this->normalizeAccessTokenResponse($response->getBody()->getContents());
}

/**
* @param array $componentConfig ['id' => xxx, 'token' => xxx]
*
* @return \Overtrue\Socialite\Providers\WeChat
*/
public function withComponent(array $componentConfig)
{
$this->component = $componentConfig;

return $this;
}

public function getComponent()
{
return $this->component;
}

protected function getAuthUrl(): string
{
$path = 'oauth2/authorize';
Expand All @@ -84,6 +100,7 @@ protected function buildAuthUrlFromBase(string $url): string
protected function getCodeFields(): array
{
if (!empty($this->component)) {
$this->prepareForComponent();
$this->with(array_merge($this->parameters, ['component_appid' => $this->component['id']]));
}

Expand Down

0 comments on commit 201b084

Please sign in to comment.