Skip to content

Commit 607e785

Browse files
committed
Add X OAuth announcement blog
1 parent d37c438 commit 607e785

4 files changed

Lines changed: 158 additions & 2 deletions

File tree

.optimize-cache.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,7 @@
11191119
"images\\blog\\why-you-need-to-try-the-new-bun-runtime\\bun-buildtime.png": "69b92a76d4e7935d666da1b010e6606a8b73c009de23e00a891c551fb1d042dd",
11201120
"images\\blog\\why-you-need-to-try-the-new-bun-runtime\\cover.png": "96d6da52011044ed190620d57510a98964bec3f3339712960acead8f2208529a",
11211121
"images\\blog\\why-you-need-to-try-the-new-bun-runtime\\ts-buildtime.png": "f1e53206a80937c86b33f615ba6936a8c10266dc01ba221da4a7c2735e806ae9",
1122+
"images\\blog\\x-oauth2-appwrite\\cover.png": "1e6bfcc38f758e57a684a3b092bd8500e45353e7dc164af20753882ecbf8373e",
11221123
"images\\brand\\new-brand-grid-desktop.png": "3469b9692f5f8be1a635974c14a3e55c0f311559e499ffe83a145234db93da90",
11231124
"images\\brand\\new-brand-grid-mobile.png": "129543e6f56036bbfd3f0e8e12534b179b3202885f687ab71429f7b6c7e95fd2",
11241125
"images\\brand\\t-shirts.png": "ae53c30bc47e43ac23ffdcd54a90e5bdf7170e04eeb2e7c3f758e771dfd29e1e",
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
---
2+
layout: post
3+
title: Announcing X OAuth support in Appwrite Auth
4+
description: Appwrite now supports X (formerly Twitter) OAuth2 login. Learn how to add it to your app in minutes.
5+
date: 2026-04-09
6+
cover: /images/blog/x-oauth2-appwrite/cover.png
7+
timeToRead: 5
8+
author: aditya-oberai
9+
category: announcement, tutorial
10+
featured: false
11+
---
12+
13+
We're excited to announce that Appwrite Auth now includes an X OAuth adapter. You can now let users sign in with their X account using Appwrite's built-in OAuth2 support, with no custom backend code required.
14+
15+
X is one of the most widely used social platforms, with hundreds of millions of active users. Adding "Sign in with X" gives your users a fast, familiar way to get started without creating a new account, and gives you a verified identity to work with from day one.
16+
17+
In this guide, we'll walk through what this means for your app, why it matters, and how to set it up.
18+
19+
# Why X OAuth is useful for developers and users
20+
21+
For users, social login removes the friction of registration. There's no new password to create or forget, no verification email to wait for. They click one button, approve access, and they're in.
22+
23+
For developers, social login with Appwrite means you don't have to implement or maintain any OAuth infrastructure yourself. Appwrite handles the redirect, the token exchange, the session creation, and the refresh flow. You call one SDK method. The rest happens server-side.
24+
25+
X in particular is valuable for apps that are social or content-focused. If your users are already on X, letting them authenticate with it creates a natural connection between their X identity and your product. You can also use the access token Appwrite stores to call the X API on their behalf, enabling things like reading their profile, fetching their posts, or building X-connected features.
26+
27+
Appwrite's X adapter also implements **OAuth 2.0 with PKCE** (Proof Key for Code Exchange), which is required by X's API v2 and protects against authorization code interception attacks. This is handled automatically with no extra configuration needed on your end.
28+
29+
# How OAuth2 works in Appwrite
30+
31+
When a user signs in with X, Appwrite manages the entire OAuth2 flow on your behalf:
32+
33+
1. Your app calls an Appwrite SDK method, which returns an authorization URL.
34+
2. The user is redirected to X's consent screen.
35+
3. After granting access, X redirects back to Appwrite with an authorization code.
36+
4. Appwrite exchanges the code for an access token and refresh token with X.
37+
5. Appwrite redirects the user to your success URL with a `userId` and `secret`.
38+
6. Your app uses these to create an Appwrite session.
39+
40+
Appwrite's X adapter uses **OAuth 2.0 with PKCE** (Proof Key for Code Exchange), which is required by X's API v2 and adds an extra layer of security by preventing authorization code interception attacks.
41+
42+
# Creating an X Developer app
43+
44+
To connect Appwrite to X, you first need to register an app on the [X Developer Portal](https://console.x.com).
45+
46+
Log in and create a new project, then create a new app inside that project (or use an existing one). Give your app a name that reflects what you're building.
47+
48+
![X Developer Portal - New App](/images/integrations/oauth-x/new-app.png)
49+
50+
Once the app is created, open the app's **Settings** and scroll down to **User authentication settings**. Click **Set up** and configure the following:
51+
52+
- **App permissions**: Select **Read** at a minimum. If your app needs to post or access direct messages, select the appropriate permissions.
53+
- **Type of App**: Select **Web App, Automated App or Bot**.
54+
- **Callback URI / Redirect URL**: Temporarily add `https://temporary-endpoint.com/`. You'll replace this with the real URI from Appwrite in the next step.
55+
56+
![X OAuth2 user authentication settings](/images/integrations/oauth-x/oauth2.png)
57+
58+
After saving, X will display a **Client ID** and **Client Secret**. Save both. The Client Secret is only shown once, so copy it somewhere safe before closing the page.
59+
60+
# Enabling X as a provider in Appwrite
61+
62+
Head to your [Appwrite Console](https://cloud.appwrite.io/) and open your project. Navigate to **Auth** > **Settings**, scroll to **OAuth2 Providers**, and click on **X**.
63+
64+
![X OAuth2 provider in Appwrite](/images/integrations/oauth-x/provider.png)
65+
66+
Enable the provider and paste in your **Client ID** and **Client Secret**. Appwrite will display a **Redirect URI**. Copy it and go back to your X app's **User authentication settings** to replace the temporary callback URL with this value.
67+
68+
Save the changes in both the X Developer Portal and Appwrite.
69+
70+
# Logging in from your frontend
71+
72+
With the provider configured, you can trigger X login using the Appwrite SDK. Here's an example using the JavaScript SDK:
73+
74+
```js
75+
import { Client, Account, OAuthProvider } from 'appwrite';
76+
77+
const client = new Client()
78+
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1')
79+
.setProject('<PROJECT_ID>');
80+
81+
const account = new Account(client);
82+
83+
const authUrl = await account.createOAuth2Token({
84+
provider: OAuthProvider.X,
85+
success: 'https://your-app.com/auth/callback',
86+
failure: 'https://your-app.com/auth/login?error=oauth'
87+
});
88+
89+
window.location.href = authUrl;
90+
```
91+
92+
Then on your callback page, read the `userId` and `secret` from the query string and create the session manually:
93+
94+
```js
95+
const params = new URLSearchParams(window.location.search);
96+
const userId = params.get('userId');
97+
const secret = params.get('secret');
98+
99+
if (userId && secret) {
100+
await account.createSession({ userId, secret });
101+
window.location.href = '/dashboard';
102+
}
103+
```
104+
105+
# Accessing user data
106+
107+
After login, you can fetch the authenticated user's profile from Appwrite:
108+
109+
```js
110+
const user = await account.get();
111+
112+
console.log(user.name); // display name from X
113+
console.log(user.email); // email from X (if granted)
114+
```
115+
116+
If you need the X access token to call the X API directly, retrieve it from the user's identities:
117+
118+
```js
119+
const { identities } = await account.listIdentities();
120+
const xIdentity = identities.find(i => i.provider === 'x');
121+
122+
console.log(xIdentity.providerAccessToken); // X OAuth2 access token
123+
```
124+
125+
You can use this access token to make requests to the [X API v2](https://docs.x.com) on behalf of the user.
126+
127+
# Refreshing the access token
128+
129+
X access tokens expire. When you need a fresh token, call `updateSession` to silently renew it using the stored refresh token:
130+
131+
```js
132+
await account.updateSession({ sessionId: 'current' });
133+
134+
const { identities } = await account.listIdentities();
135+
const xIdentity = identities.find(i => i.provider === 'x');
136+
137+
console.log(xIdentity.providerAccessToken); // fresh token
138+
```
139+
140+
This renews the X access token without interrupting the user's Appwrite session.
141+
142+
# Final thoughts
143+
144+
Adding X login to your app with Appwrite comes down to three things: registering an app on the X Developer Portal, configuring the provider in the Appwrite Console, and calling one SDK method. Appwrite handles the PKCE flow, token exchange, and session management for you.
145+
146+
If you have questions or run into issues, the [Appwrite Discord server](https://appwrite.io/discord) is the best place to get help.
147+
148+
# Further reading
149+
150+
- [X OAuth integration guide](/integrations/oauth-x)
151+
- [Appwrite Auth OAuth2 docs](/docs/products/auth/oauth2)
152+
- [X Developer Portal](https://console.x.com)
153+
- [X API OAuth2 documentation](https://docs.x.com/fundamentals/authentication/oauth-2-0/overview)
154+
- [Understanding OAuth and OpenID Connect](/blog/post/oauth-openid)
155+
- [Appwrite Auth API reference](/docs/references/cloud/client-web/account)

src/routes/integrations/oauth-x/+page.markdoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ category: auth
1111
product:
1212
avatar: '/images/integrations/avatars/x.png'
1313
vendor: X
14-
description: 'X (formerly Twitter) is a social media platform where users can post short messages, follow others, and engage in real-time conversations on topics ranging from news and politics to entertainment and technology.'
14+
description: 'X is a social media platform where users can post short messages, follow others, and engage in real-time conversations on topics ranging from news and politics to entertainment and technology.'
1515
platform:
1616
- 'Cloud'
1717
images:
@@ -63,7 +63,7 @@ Follow the [OAuth 2 login](/docs/products/auth/oauth2#init) flow to test your pr
6363

6464
If you would like to learn more about X and Appwrite Auth, we have some resources that you should visit:
6565

66-
- [X Developer Portal](https://developer.twitter.com/en/portal/dashboard)
66+
- [X Developer Portal](https://console.x.com)
6767
- [Implement OAuth login in your apps using Appwrite Auth](/docs/products/auth/oauth2)
6868
- [Understanding OAuth and OpenID Connect](/blog/post/oauth-openid)
6969
- [Appwrite Auth API reference](/docs/references/cloud/client-web/account)
128 KB
Loading

0 commit comments

Comments
 (0)