clientId = $clientId; $this->clientSecret = $clientSecret; $this->version = $version; $this->authEndpoint = $authEndpoint; } /** * Gets the OAuth2 client ID * * @return string OAuth2 client ID */ public function getClientId() { return $this->clientId; } /** * Gets the OAuth2 client secret * * @return string OAuth2 client secret */ public function getClientSecret() { return $this->clientSecret; } /** * Gets the credential version * * @return string credential version */ public function getVersion() { return $this->version; } /** * Gets the OAuth2 grant type * * @return string Grant type */ public function getGrantType() { return $this->grantType; } /** * Gets the OAuth2 scope * * @return string OAuth2 scope */ public function getScope() { return $this->isLwa() ? self::LWA_SCOPE : self::COGNITO_SCOPE; } /** * Checks if this is an LWA (v3.x) configuration * * @return bool True if using LWA authentication */ public function isLwa() { return strncmp($this->version, '3.', 2) === 0; } /** * Gets the appropriate OAuth2 token endpoint based on the credential version * * @return string Token endpoint URL * @throws \InvalidArgumentException If the version is not supported */ public function getTokenEndpoint() { // Custom authEndpoint used for testing if ($this->authEndpoint !== null && trim($this->authEndpoint) !== '') { return $this->authEndpoint; } switch ($this->version) { // Cognito endpoints (v2.x) case "2.1": return "https://creatorsapi.auth.us-east-1.amazoncognito.com/oauth2/token"; case "2.2": return "https://creatorsapi.auth.eu-south-2.amazoncognito.com/oauth2/token"; case "2.3": return "https://creatorsapi.auth.us-west-2.amazoncognito.com/oauth2/token"; // LWA endpoints (v3.x) case "3.1": return "https://api.amazon.com/auth/o2/token"; case "3.2": return "https://api.amazon.co.uk/auth/o2/token"; case "3.3": return "https://api.amazon.co.jp/auth/o2/token"; default: throw new \InvalidArgumentException("Unsupported version: {$this->version}. Supported versions are: 2.1, 2.2, 2.3, 3.1, 3.2, 3.3"); } } /** * Sets the grant type * * @param string $grantType Grant type * @return $this */ public function setGrantType($grantType) { $this->grantType = $grantType; return $this; } }