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

[11.15] Added functionality to handle access tokens #800

Open
wants to merge 16 commits into
base: 11.15
Choose a base branch
from
Open
Prev Previous commit
Next Next commit
Add rotation functionality for group access tokens
  • Loading branch information
Angutivik Casper Rúnur Tausen committed Mar 12, 2024
commit c44e0aa17002b36b35f7c44c60dc36cc7fe6bef9
18 changes: 18 additions & 0 deletions src/Api/Groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,24 @@ public function deleteGroupAccessToken(string|int $group_id, string|int $token_i
return $this->delete($this->getGroupPath($group_id, 'access_tokens/'.self::encodePath($token_id)));
}

/**
* @param string|int $group_id
* @param string|int $token_id
* @param string $expiry
*
* @return mixed
*/
public function rotateGroupAccessToken(string|int $group_id, string|int $token_id, string $expiry = ''): mixed
{
$regex = '/(?:19|20)\d{2}-(0[1-9]|1[0-2])-(0[1-9]|[1-2]\d|3[01])/';
if ($expiry !== '' && preg_match($regex, $expiry) !== false) {
$uri = 'access_tokens/'.self::encodePath($token_id).'/rotate?expires_at='.$expiry;
return $this->post($this->getGroupPath($group_id, $uri));
}

return $this->post($this->getGroupPath($group_id, 'access_tokens/'.self::encodePath($token_id).'/rotate'));
}

/**
* @param int|string $id
* @param array $parameters {
Expand Down