Skip to content

Commit 8f55b3c

Browse files
committed
s/twitter.com/x.com/g
1 parent b4248dc commit 8f55b3c

File tree

6 files changed

+36
-26
lines changed

6 files changed

+36
-26
lines changed

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Remix Auth Twitter ![example branch parameter](https://github.com/na2hiro/remix-auth-twitter/actions/workflows/main.yml/badge.svg?branch=main)
22

3-
Remix Auth plugin for Twitter [OAuth 2.0](https://developer.twitter.com/en/docs/authentication/oauth-2-0/user-access-token) and [1.0a](https://developer.twitter.com/en/docs/authentication/oauth-1-0a/obtaining-user-access-tokens).
3+
Remix Auth plugin for Twitter [OAuth 2.0](https://developer.x.com/en/docs/authentication/oauth-2-0/user-access-token) and [1.0a](https://developer.x.com/en/docs/authentication/oauth-1-0a/obtaining-user-access-tokens).
44

55
## Supported runtimes
66

@@ -9,9 +9,9 @@ Remix Auth plugin for Twitter [OAuth 2.0](https://developer.twitter.com/en/docs/
99
| Node.js ||
1010
| Cloudflare ||
1111

12-
## Demo
12+
## Example
1313

14-
Try out ~~[live demo](https://remix-auth-twitter-example.na2hiro.workers.dev/)~~ Currently it doesn't work due to updates on Twitter APIs. You could try cloning the [source code](https://github.com/na2hiro/remix-auth-twitter-example)
14+
See [example repo](https://github.com/na2hiro/remix-auth-twitter-example)
1515

1616
## Installation
1717

@@ -20,11 +20,21 @@ Install `remix-auth-twitter` npm module along with `remix-auth`:
2020
```shell
2121
npm install remix-auth-twitter remix-auth
2222
```
23+
24+
### Compatibility
25+
26+
| remix-auth-twitter | remix-auth | other notes |
27+
|--------------------|------------|-----------------------|
28+
| @2 | @3 | Points to twitter.com |
29+
| @3 | @3 | Points to x.com |
30+
| @4 (coming soon) | @4 | Points to x.com |
31+
32+
2333
## How to use
2434

2535
### Prerequisites
2636

27-
* Your app is registered to Twitter and you have client ID and secret (OAuth 2.0) or [consumer key and secret (OAuth 1.0a)](https://developer.twitter.com/en/docs/authentication/oauth-1-0a/api-key-and-secret)
37+
* Your app is registered to Twitter and you have client ID and secret (OAuth 2.0) or [consumer key and secret (OAuth 1.0a)](https://developer.x.com/en/docs/authentication/oauth-1-0a/api-key-and-secret)
2838
* Your app has [remix-auth](https://github.com/sergiodxa/remix-auth) set up and `authenticator` is provided:
2939
```typescript
3040
// app/services/auth.server.ts
@@ -33,7 +43,7 @@ npm install remix-auth-twitter remix-auth
3343

3444
### Tell the Authenticator to use the Twitter strategy (OAuth 2.0)
3545

36-
Note that profile is not passed to the verify function as it was done for 1.0a. You need to manually hit [/2/users/me](https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users-me) for example in order to retrieve user's id, screen name, etc. The example uses [`twitter-api-v2`](https://github.com/PLhery/node-twitter-api-v2) to do so.
46+
Note that profile is not passed to the verify function as it was done for 1.0a. You need to manually hit [/2/users/me](https://developer.x.com/en/docs/twitter-api/users/lookup/api-reference/get-users-me) for example in order to retrieve user's id, screen name, etc. The example uses [`twitter-api-v2`](https://github.com/PLhery/node-twitter-api-v2) to do so.
3747

3848
```typescript jsx
3949
// app/services/auth.server.ts

src/Twitter1Strategy.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ import { fixedEncodeURIComponent } from "./utils";
1717

1818
let debug = createDebug("TwitterStrategy");
1919

20-
const requestTokenURL = "https://api.twitter.com/oauth/request_token";
21-
const authorizationURL = "https://api.twitter.com/oauth/authorize";
22-
const authenticationURL = "https://api.twitter.com/oauth/authenticate";
23-
const tokenURL = "https://api.twitter.com/oauth/access_token";
20+
const requestTokenURL = "https://api.x.com/oauth/request_token";
21+
const authorizationURL = "https://api.x.com/oauth/authorize";
22+
const authenticationURL = "https://api.x.com/oauth/authenticate";
23+
const tokenURL = "https://api.x.com/oauth/access_token";
2424

2525
export interface Twitter1StrategyOptions {
2626
consumerKey: string;
@@ -44,7 +44,7 @@ export interface Twitter1StrategyVerifyParams {
4444
export const Twitter1StrategyDefaultName = "twitter1";
4545

4646
/**
47-
* Twitter's OAuth 1.0a login (https://developer.twitter.com/en/docs/authentication/oauth-1-0a/obtaining-user-access-tokens)
47+
* Twitter's OAuth 1.0a login (https://developer.x.com/en/docs/authentication/oauth-1-0a/obtaining-user-access-tokens)
4848
*
4949
* Applications must supply a `verify` callback, for which the function signature is:
5050
*

src/Twitter2Strategy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export interface Twitter2StrategyVerifyParams {
3232
export const Twitter2StrategyDefaultName = "twitter2";
3333

3434
/**
35-
* Twitter's OAuth 2.0 login (https://developer.twitter.com/en/docs/authentication/oauth-2-0/user-access-token)
35+
* Twitter's OAuth 2.0 login (https://developer.x.com/en/docs/authentication/oauth-2-0/user-access-token)
3636
*
3737
* Applications must supply a `verify` callback, for which the function signature is:
3838
*

src/oauth2Api.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { generateRandomString } from "./utils";
22

3-
// https://developer.twitter.com/en/docs/authentication/oauth-2-0/authorization-code
3+
// https://developer.x.com/en/docs/authentication/oauth-2-0/authorization-code
44
export type Scope =
55
| "tweet.read"
66
| "tweet.write"
@@ -38,7 +38,7 @@ export function buildAuthorizeUrl(
3838
code_challenge_method: "plain",
3939
});
4040

41-
let url = new URL("https://twitter.com/i/oauth2/authorize");
41+
let url = new URL("https://x.com/i/oauth2/authorize");
4242
url.search = params.toString();
4343

4444
return { url, state, challenge };
@@ -62,7 +62,7 @@ export async function requestToken(
6262
code_verifier: challenge,
6363
});
6464

65-
const url = new URL("https://api.twitter.com/2/oauth2/token");
65+
const url = new URL("https://api.x.com/2/oauth2/token");
6666
url.search = params.toString();
6767

6868
return await fetch(url.toString(), {

test/Twitter1Strategy.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ describe(Twitter1Strategy, () => {
101101
assertResponse(error);
102102

103103
expect(fetchMock.mock.calls[0][0]).toMatchInlineSnapshot(
104-
`"https://api.twitter.com/oauth/request_token?oauth_callback=https%3A%2F%2Fexample.com%2Fcallback&oauth_consumer_key=MY_CLIENT_ID&oauth_nonce=abcdefg&oauth_timestamp=NaN&oauth_version=1.0&oauth_signature_method=HMAC-SHA1&oauth_signature=1X41i0CFd3rGyZCbyb%2BH5WPMbts%3D"`
104+
`"https://api.x.com/oauth/request_token?oauth_callback=https%3A%2F%2Fexample.com%2Fcallback&oauth_consumer_key=MY_CLIENT_ID&oauth_nonce=abcdefg&oauth_timestamp=NaN&oauth_version=1.0&oauth_signature_method=HMAC-SHA1&oauth_signature=fbuRy0FPvsrz4o%2Bzpbw%2F%2Bq8VmCw%3D"`
105105
);
106106

107107
expect(error.status).toBe(401);
@@ -118,7 +118,7 @@ describe(Twitter1Strategy, () => {
118118
const url = new URL(req.url);
119119
url.search = "";
120120
switch (url.toString()) {
121-
case "https://api.twitter.com/oauth/request_token":
121+
case "https://api.x.com/oauth/request_token":
122122
return {
123123
body: "oauth_token=REQUEST_TOKEN&oauth_token_secret=REQUEST_TOKEN_SECRET&oauth_callback_confirmed=true",
124124
init: {
@@ -136,12 +136,12 @@ describe(Twitter1Strategy, () => {
136136
assertResponse(error);
137137

138138
expect(fetchMock.mock.calls[0][0]).toMatchInlineSnapshot(
139-
`"https://api.twitter.com/oauth/request_token?oauth_callback=https%3A%2F%2Fexample.com%2Fcallback&oauth_consumer_key=MY_CLIENT_ID&oauth_nonce=abcdefg&oauth_timestamp=NaN&oauth_version=1.0&oauth_signature_method=HMAC-SHA1&oauth_signature=1X41i0CFd3rGyZCbyb%2BH5WPMbts%3D"`
139+
`"https://api.x.com/oauth/request_token?oauth_callback=https%3A%2F%2Fexample.com%2Fcallback&oauth_consumer_key=MY_CLIENT_ID&oauth_nonce=abcdefg&oauth_timestamp=NaN&oauth_version=1.0&oauth_signature_method=HMAC-SHA1&oauth_signature=fbuRy0FPvsrz4o%2Bzpbw%2F%2Bq8VmCw%3D"`
140140
);
141141

142142
let redirect = error.headers.get("Location");
143143
expect(redirect).toMatchInlineSnapshot(
144-
`"https://api.twitter.com/oauth/authenticate?oauth_token=REQUEST_TOKEN"`
144+
`"https://api.x.com/oauth/authenticate?oauth_token=REQUEST_TOKEN"`
145145
);
146146
}
147147
});
@@ -200,7 +200,7 @@ describe(Twitter1Strategy, () => {
200200
const url = new URL(req.url);
201201
url.search = "";
202202
switch (url.toString()) {
203-
case "https://api.twitter.com/oauth/access_token":
203+
case "https://api.x.com/oauth/access_token":
204204
return {
205205
body: "oauth_token=ACCESS_TOKEN&oauth_token_secret=ACCESS_TOKEN_SECRET&screen_name=na2hiro&user_id=123",
206206
init: {
@@ -233,7 +233,7 @@ describe(Twitter1Strategy, () => {
233233
});
234234

235235
expect(fetchMock.mock.calls[0][0]).toMatchInlineSnapshot(
236-
`"https://api.twitter.com/oauth/access_token"`
236+
`"https://api.x.com/oauth/access_token"`
237237
);
238238
expect(fetchMock.mock.calls[0][1]!.body!.toString()).toMatchInlineSnapshot(
239239
`"oauth_token=TOKEN&oauth_verifier=VERIFIER&oauth_consumer_key=MY_CLIENT_ID"`
@@ -254,7 +254,7 @@ describe(Twitter1Strategy, () => {
254254
const url = new URL(req.url);
255255
url.search = "";
256256
switch (url.toString()) {
257-
case "https://api.twitter.com/oauth/access_token":
257+
case "https://api.x.com/oauth/access_token":
258258
return {
259259
body: "oauth_token=ACCESS_TOKEN&oauth_token_secret=ACCESS_TOKEN_SECRET",
260260
init: {

test/Twitter2Strategy.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ describe(Twitter2Strategy, () => {
9898

9999
let redirect = error.headers.get("Location");
100100
expect(redirect).toMatchInlineSnapshot(
101-
`"https://twitter.com/i/oauth2/authorize?response_type=code&client_id=MY_CLIENT_ID&redirect_uri=https%3A%2F%2Fexample.com%2Fcallback&scope=tweet.write+tweet.read+users.read&state=MOCKED_RANDOM_CHARS_16&code_challenge=MOCKED_RANDOM_CHARS_43&code_challenge_method=plain"`
101+
`"https://x.com/i/oauth2/authorize?response_type=code&client_id=MY_CLIENT_ID&redirect_uri=https%3A%2F%2Fexample.com%2Fcallback&scope=tweet.write+tweet.read+users.read&state=MOCKED_RANDOM_CHARS_16&code_challenge=MOCKED_RANDOM_CHARS_43&code_challenge_method=plain"`
102102
);
103103
}
104104
});
@@ -159,7 +159,7 @@ describe(Twitter2Strategy, () => {
159159
const url = new URL(req.url);
160160
url.search = "";
161161
switch (url.toString()) {
162-
case "https://api.twitter.com/2/oauth2/token":
162+
case "https://api.x.com/2/oauth2/token":
163163
return {
164164
body: JSON.stringify({
165165
token_type: "bearer",
@@ -207,7 +207,7 @@ describe(Twitter2Strategy, () => {
207207
const url = new URL(req.url);
208208
url.search = "";
209209
switch (url.toString()) {
210-
case "https://api.twitter.com/2/oauth2/token":
210+
case "https://api.x.com/2/oauth2/token":
211211
return {
212212
body: JSON.stringify({
213213
token_type: "bearer",
@@ -247,7 +247,7 @@ describe(Twitter2Strategy, () => {
247247
});
248248

249249
expect(fetchMock.mock.calls[0][0]).toMatchInlineSnapshot(
250-
`"https://api.twitter.com/2/oauth2/token?code=TOKEN&grant_type=authorization_code&client_id=MY_CLIENT_ID&redirect_uri=https%3A%2F%2Fexample.com%2Fcallback&code_verifier=undefined"`
250+
`"https://api.x.com/2/oauth2/token?code=TOKEN&grant_type=authorization_code&client_id=MY_CLIENT_ID&redirect_uri=https%3A%2F%2Fexample.com%2Fcallback&code_verifier=undefined"`
251251
);
252252

253253
expect(verify).toHaveBeenLastCalledWith({
@@ -264,7 +264,7 @@ describe(Twitter2Strategy, () => {
264264
const url = new URL(req.url);
265265
url.search = "";
266266
switch (url.toString()) {
267-
case "https://api.twitter.com/2/oauth2/token":
267+
case "https://api.x.com/2/oauth2/token":
268268
return {
269269
body: JSON.stringify({
270270
access_token: "TOKEN",

0 commit comments

Comments
 (0)