You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
932 B
42 lines
932 B
<?php
|
|
|
|
namespace authkit2\Oidc\Flows;
|
|
use authkit2\Oidc\Client;
|
|
use authkit2\Oidc\Authentication\ClientAuthentication;
|
|
use authkit2\Oidc\Token;
|
|
|
|
/**
|
|
* OpenId client_credentials grant flow
|
|
*/
|
|
class ServiceAccountFlow
|
|
{
|
|
/**
|
|
* oidc client for making requests authenticated with our id/secret
|
|
* @var Client
|
|
*/
|
|
protected $client;
|
|
|
|
/**
|
|
* Initialize a new service account flow
|
|
*
|
|
* @param string $client_id oauth client id
|
|
* @param string $client_secret oauth client secret
|
|
*/
|
|
public function __construct(string $client_id, string $client_secret)
|
|
{
|
|
$this->client = new Client(new ClientAuthentication($client_id, $client_secret));
|
|
}
|
|
|
|
/**
|
|
* Fetch a service account token for the initialized credentials
|
|
*
|
|
* @return Token
|
|
*/
|
|
public function getServiceAccountToken(): Token
|
|
{
|
|
$response = $this->client->post('token', ['grant_type'=>'client_credentials']);
|
|
return Token::fromResponse($response);
|
|
}
|
|
}
|
|
|
|
|
|
|