Set expiration time for the access token(COMPOSER PHP)

Hi I want to set expiration time for the access token and I know that that it can be set in api section. I have created a custom api and when i pass the audience field in my regular webapp along with client ID and clent secret its throwing an error "Validation of “audience” was unsuccessful in C:\webpages\phptest\vendor\auth0\auth0-php\src\Exception\ConfigurationException.php:266 "
$auth0 = new \Auth0\SDK\Auth0([
‘domain’ => ‘oceanwise.eu.auth0.com’,
‘clientId’ =>‘qxxxxxxxxxxxx’,
‘clientSecret’ => ‘xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx’,
‘cookieSecret’ =>‘dxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxc7bd2’,
‘redirectUri’ =>‘http://localhost/phptest/login.php’,
‘audience’=>‘https://sdfhv/api
]);

if ($auth0->getExchangeParameters()) {
// If they’re present, we should perform the code exchange.
$auth0->exchange();
}
$session = $auth0->getCredentials();

please can anyone help me in connecting the api with my ragular webapplication

Hi @bhavith.chandra, you need to configure audience as an array rather than a string, as it accepts multiple potential identifiers for verification.

use Auth0\SDK\Auth0;
use Auth0\SDK\Configuration\SdkConfiguration;

$configuration = new SdkConfiguration(
  domain: '...',
  clientId: '...',
  clientSecret: '...',
  cookieSecret: '...',
  redirectUri: '...',
  audience': ['https://sdfhv/api'],
);

$auth0 = new Auth0($configuration);

I recommend configuring with the SdkConfiguration class, as it provides helpful type hinting that your IDE can surface for you for things like this.

For reference, here’s the constructor definition for that class, which lists all the available options and their types: auth0-PHP/SdkConfiguration.php at main · auth0/auth0-PHP · GitHub

1 Like