Skip to content

Commit

Permalink
fix: twitter update and version update
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed Sep 26, 2023
1 parent 5a1f593 commit f820516
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 22 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html)

## [unreleased]
## [16.0.1] - 2023-09-26

- Added `twitter` as a built-in thirdparty provider

## [16.0.0] - 2023-08-XX

Expand Down Expand Up @@ -180,7 +182,6 @@ Because of account linking we've introduced a new Primary user concept (see abov
- Added `getUser`, `listUsersByAccountInfo`, `convertToRecipeUserId` to the main exports
- Updated compilation target of typescript to ES2017 to make debugging easier.
- Added account-linking recipe
- Added `twitter` as a built-in thirdparty provider

### Migration guide

Expand Down
2 changes: 2 additions & 0 deletions lib/build/recipe/thirdparty/providers/custom.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// @ts-nocheck
import { TypeProvider, ProviderInput } from "../types";
export declare const DEV_OAUTH_REDIRECT_URL = "https://supertokens.io/dev/oauth/redirect-to-app";
export declare function isUsingDevelopmentClientId(client_id: string): boolean;
export declare function getActualClientIdFromDevelopmentClientId(client_id: string): string;
export default function NewProvider(input: ProviderInput): TypeProvider;
7 changes: 4 additions & 3 deletions lib/build/recipe/thirdparty/providers/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ var __importDefault =
return mod && mod.__esModule ? mod : { default: mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getActualClientIdFromDevelopmentClientId = void 0;
exports.getActualClientIdFromDevelopmentClientId = exports.isUsingDevelopmentClientId = exports.DEV_OAUTH_REDIRECT_URL = void 0;
const utils_1 = require("./utils");
const pkce_challenge_1 = __importDefault(require("pkce-challenge"));
const configUtils_1 = require("./configUtils");
const jose_1 = require("jose");
const DEV_OAUTH_AUTHORIZATION_URL = "https://supertokens.io/dev/oauth/redirect-to-provider";
const DEV_OAUTH_REDIRECT_URL = "https://supertokens.io/dev/oauth/redirect-to-app";
exports.DEV_OAUTH_REDIRECT_URL = "https://supertokens.io/dev/oauth/redirect-to-app";
// If Third Party login is used with one of the following development keys, then the dev authorization url and the redirect url will be used.
const DEV_OAUTH_CLIENT_IDS = [
"1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com",
Expand All @@ -21,6 +21,7 @@ const DEV_KEY_IDENTIFIER = "4398792-";
function isUsingDevelopmentClientId(client_id) {
return client_id.startsWith(DEV_KEY_IDENTIFIER) || DEV_OAUTH_CLIENT_IDS.includes(client_id);
}
exports.isUsingDevelopmentClientId = isUsingDevelopmentClientId;
function getActualClientIdFromDevelopmentClientId(client_id) {
if (client_id.startsWith(DEV_KEY_IDENTIFIER)) {
return client_id.split(DEV_KEY_IDENTIFIER)[1];
Expand Down Expand Up @@ -246,7 +247,7 @@ function NewProvider(input) {
/* Transformation needed for dev keys BEGIN */
if (isUsingDevelopmentClientId(impl.config.clientId)) {
accessTokenAPIParams["client_id"] = getActualClientIdFromDevelopmentClientId(impl.config.clientId);
accessTokenAPIParams["redirect_uri"] = DEV_OAUTH_REDIRECT_URL;
accessTokenAPIParams["redirect_uri"] = exports.DEV_OAUTH_REDIRECT_URL;
}
/* Transformation needed for dev keys END */
return await utils_1.doPostRequest(tokenAPIURL, accessTokenAPIParams);
Expand Down
54 changes: 47 additions & 7 deletions lib/build/recipe/thirdparty/providers/twitter.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,42 @@
"use strict";
var __importDefault =
(this && this.__importDefault) ||
var __createBinding =
(this && this.__createBinding) ||
(Object.create
? function (o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, {
enumerable: true,
get: function () {
return m[k];
},
});
}
: function (o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
});
var __setModuleDefault =
(this && this.__setModuleDefault) ||
(Object.create
? function (o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}
: function (o, v) {
o["default"] = v;
});
var __importStar =
(this && this.__importStar) ||
function (mod) {
return mod && mod.__esModule ? mod : { default: mod };
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null)
for (var k in mod)
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const custom_1 = __importDefault(require("./custom"));
const custom_1 = __importStar(require("./custom"));
const utils_1 = require("./utils");
function Twitter(input) {
var _a;
Expand Down Expand Up @@ -47,16 +78,25 @@ function Twitter(input) {
return config;
};
originalImplementation.exchangeAuthCodeForOAuthTokens = async function (input) {
let clientId = originalImplementation.config.clientId;
let redirectUri = input.redirectURIInfo.redirectURIOnProviderDashboard;
// We need to do this because we don't call the original implementation
/* Transformation needed for dev keys BEGIN */
if (custom_1.isUsingDevelopmentClientId(originalImplementation.config.clientId)) {
clientId = custom_1.getActualClientIdFromDevelopmentClientId(originalImplementation.config.clientId);
redirectUri = custom_1.DEV_OAUTH_REDIRECT_URL;
}
/* Transformation needed for dev keys END */
const basicAuthToken = Buffer.from(
`${originalImplementation.config.clientId}:${originalImplementation.config.clientSecret}`,
`${clientId}:${originalImplementation.config.clientSecret}`,
"utf8"
).toString("base64");
const twitterOauthTokenParams = Object.assign(
{
grant_type: "authorization_code",
client_id: originalImplementation.config.clientId,
client_id: clientId,
code_verifier: input.redirectURIInfo.pkceCodeVerifier,
redirect_uri: input.redirectURIInfo.redirectURIOnProviderDashboard,
redirect_uri: redirectUri,
code: input.redirectURIInfo.redirectURIQueryParams.code,
},
originalImplementation.config.tokenEndpointBodyParams
Expand Down
2 changes: 1 addition & 1 deletion lib/build/version.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/build/version.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/ts/recipe/thirdparty/providers/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getProviderConfigForClient } from "./configUtils";
import { JWTVerifyGetKey, createRemoteJWKSet } from "jose";

const DEV_OAUTH_AUTHORIZATION_URL = "https://supertokens.io/dev/oauth/redirect-to-provider";
const DEV_OAUTH_REDIRECT_URL = "https://supertokens.io/dev/oauth/redirect-to-app";
export const DEV_OAUTH_REDIRECT_URL = "https://supertokens.io/dev/oauth/redirect-to-app";

// If Third Party login is used with one of the following development keys, then the dev authorization url and the redirect url will be used.
const DEV_OAUTH_CLIENT_IDS = [
Expand All @@ -14,7 +14,7 @@ const DEV_OAUTH_CLIENT_IDS = [
];
const DEV_KEY_IDENTIFIER = "4398792-";

function isUsingDevelopmentClientId(client_id: string): boolean {
export function isUsingDevelopmentClientId(client_id: string): boolean {
return client_id.startsWith(DEV_KEY_IDENTIFIER) || DEV_OAUTH_CLIENT_IDS.includes(client_id);
}

Expand Down
23 changes: 19 additions & 4 deletions lib/ts/recipe/thirdparty/providers/twitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
* under the License.
*/
import { ProviderInput, TypeProvider } from "../types";
import NewProvider from "./custom";
import NewProvider, {
DEV_OAUTH_REDIRECT_URL,
getActualClientIdFromDevelopmentClientId,
isUsingDevelopmentClientId,
} from "./custom";
import { doPostRequest } from "./utils";

export default function Twitter(input: ProviderInput): TypeProvider {
Expand Down Expand Up @@ -64,15 +68,26 @@ export default function Twitter(input: ProviderInput): TypeProvider {
};

originalImplementation.exchangeAuthCodeForOAuthTokens = async function (input) {
let clientId = originalImplementation.config.clientId;
let redirectUri = input.redirectURIInfo.redirectURIOnProviderDashboard;

// We need to do this because we don't call the original implementation
/* Transformation needed for dev keys BEGIN */
if (isUsingDevelopmentClientId(originalImplementation.config.clientId)) {
clientId = getActualClientIdFromDevelopmentClientId(originalImplementation.config.clientId);
redirectUri = DEV_OAUTH_REDIRECT_URL;
}
/* Transformation needed for dev keys END */

const basicAuthToken = Buffer.from(
`${originalImplementation.config.clientId}:${originalImplementation.config.clientSecret}`,
`${clientId}:${originalImplementation.config.clientSecret}`,
"utf8"
).toString("base64");
const twitterOauthTokenParams = {
grant_type: "authorization_code",
client_id: originalImplementation.config.clientId,
client_id: clientId,
code_verifier: input.redirectURIInfo.pkceCodeVerifier,
redirect_uri: input.redirectURIInfo.redirectURIOnProviderDashboard,
redirect_uri: redirectUri,
code: input.redirectURIInfo.redirectURIQueryParams.code,
...originalImplementation.config.tokenEndpointBodyParams,
};
Expand Down
2 changes: 1 addition & 1 deletion lib/ts/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
export const version = "16.0.0";
export const version = "16.0.1";

export const cdiSupported = ["4.0"];

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "supertokens-node",
"version": "16.0.0",
"version": "16.0.1",
"description": "NodeJS driver for SuperTokens core",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit f820516

Please sign in to comment.