googleapis / googleapis/google-cloud-php

Credentials for Static Access Token

Open
#9,678 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
1.2k
Forks
463
Avg merge
2d 1h
Merged PRs (30d)
145

Description

I am creating this to see if it would be useful for anyone, as I have run into an instance where it would be nice (for testing). We have removed the `accessToken` option from our client libraries, so if you have a static access token, there's no way for you to easily provide it in order to authenticate. This may be by design, as it's better to set up appropriate credentials flows instead. However, we could add a Credential class like this for dev/testing:

```php
use Google\Auth\FetchAuthTokenInterface;

class StaticTokenCredentials implements FetchAuthTokenInterface
{
private string $accessToken;

public function __construct(string $accessToken)
{
$this->accessToken = $accessToken;
}

/**
* Return the supplied access token.
*/
public function fetchAuthToken(callable $httpHandler = null): array
{
return [
'access_token' => $this->accessToken,
'expires_in' => 3600, // Customize if you know the exact TTL
];
}

public function getCacheKey(): ?string
{
// Unique key to prevent collision if tokens change
return 'static_token_' . md5($this->accessToken);
}

public function getLastReceivedToken(): ?array
{
return [
'access_token' => $this->accessToken,
];
}
}
```

Contributor guide

Open the contributing guide

Research direction

The issue names FetchAuthTokenInterface and proposes StaticTokenCredentials, but gives no repository file or test entry point. Start by locating existing FetchAuthTokenInterface implementations and credential tests, then compare how token expiry and cache keys are handled. Done should establish whether static-token credentials are supported and, if so, cover the proposed authentication behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
authentication
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.