Skip to content

Commit ddf9d08

Browse files
committed
feat: add withProvider to register oauth clients
1 parent e8b1a38 commit ddf9d08

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

src/Auth.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,29 @@ public function withGoogle(
172172
$options['redirectUri'] = _env('APP_URL') . '/auth/google/callback';
173173
}
174174

175-
$this->oauthClients[$clientName] = new \League\OAuth2\Client\Provider\Google(array_merge([
175+
$this->withProvider($clientName, new \League\OAuth2\Client\Provider\Google(array_merge([
176176
'clientId' => $clientId,
177177
'clientSecret' => $clientSecret,
178178
'redirectUri' => $options['redirectUri'],
179-
], $options));
179+
], $options)));
180180

181181
return $this;
182182
}
183183

184+
/**
185+
* Register a generic OAuth client
186+
* ---
187+
* Register a generic OAuth client to use with Leaf Auth, should be a league/oauth2-client compatible client.
188+
* @param string $clientName The name of the client to register
189+
* @param \League\OAuth2\Client\Provider\AbstractProvider $client An instance of a league/oauth2-client compatible client
190+
* @return static
191+
*/
192+
public function withProvider(string $clientName, $client)
193+
{
194+
$this->oauthClients[$clientName] = $client;
195+
return $this;
196+
}
197+
184198
/**
185199
* Return an oauth client
186200
* @param string $clientName The name of the client to return

0 commit comments

Comments
 (0)