diff --git a/CHANGELOG.md b/CHANGELOG.md index b9a9ccfe..7e7c8673 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## 30.1.0 + +* Added: optional `state` parameter on `createOAuth2Token`, returned unchanged on the success and failure URLs + ## 30.0.0 * Stable release of the dedicated database APIs: `mysql`, `postgresql`, `mongo`, `documentsDB`, and `vectorsDB` services, previously released as release candidates diff --git a/docs/account.md b/docs/account.md index f2850877..1cd83a06 100644 --- a/docs/account.md +++ b/docs/account.md @@ -639,6 +639,7 @@ A user is limited to 10 active sessions at a time by default. [Learn more about | success | string | URL to redirect back to your app after a successful login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. | | | failure | string | URL to redirect back to your app after a failed login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. | | | scopes | array | A list of custom OAuth2 scopes. Check each provider internal docs for a list of supported scopes. Maximum of 100 scopes are allowed, each 4096 characters long. | [] | +| state | string | An opaque value your app generates and keeps, for example in a cookie. It is returned unchanged as the `state` query parameter on the success and failure URLs, so your app can check that the sign-in it receives is one it started. Printable ASCII only (RFC 6749 Appendix A.5). Max length: 256 chars. | | ```http request diff --git a/docs/examples/account/create-o-auth-2-token.md b/docs/examples/account/create-o-auth-2-token.md index db4dc650..e0a51f76 100644 --- a/docs/examples/account/create-o-auth-2-token.md +++ b/docs/examples/account/create-o-auth-2-token.md @@ -16,6 +16,7 @@ $result = $account->createOAuth2Token( provider: OAuthProvider::AMAZON(), success: 'https://example.com', // optional failure: 'https://example.com', // optional - scopes: [] // optional + scopes: [], // optional + state: '' // optional ); ``` diff --git a/src/Appwrite/Client.php b/src/Appwrite/Client.php index 0335259a..18f5f9d8 100644 --- a/src/Appwrite/Client.php +++ b/src/Appwrite/Client.php @@ -43,11 +43,11 @@ class Client * */ protected array $headers = [ - 'user-agent' => 'AppwritePHPSDK/30.0.0 ()', + 'user-agent' => 'AppwritePHPSDK/30.1.0 ()', 'x-sdk-name' => 'PHP', 'x-sdk-platform' => 'server', 'x-sdk-language' => 'php', - 'x-sdk-version' => '30.0.0', + 'x-sdk-version' => '30.1.0', ]; /** diff --git a/src/Appwrite/Services/Account.php b/src/Appwrite/Services/Account.php index 631f0fb9..be2bd027 100644 --- a/src/Appwrite/Services/Account.php +++ b/src/Appwrite/Services/Account.php @@ -1630,7 +1630,7 @@ public function createMagicURLToken(string $userId, string $email, ?string $url * * @throws AppwriteException */ - public function createOAuth2Token(OAuthProvider $provider, ?string $success = null, ?string $failure = null, ?array $scopes = null): string + public function createOAuth2Token(OAuthProvider $provider, ?string $success = null, ?string $failure = null, ?array $scopes = null, ?string $state = null): string { $apiPath = str_replace( ['{provider}'], @@ -1653,6 +1653,10 @@ public function createOAuth2Token(OAuthProvider $provider, ?string $success = nu $apiParams['scopes'] = $scopes; } + if (!is_null($state)) { + $apiParams['state'] = $state; + } + $apiHeaders = []; $apiHeaders['X-Appwrite-Project'] = $this->client->getConfig('project'); $apiHeaders['accept'] = 'text/html';