From 183468ca148096807c3e7cf8d9ef371c9df4f3e7 Mon Sep 17 00:00:00 2001 From: David Schwertfeger Date: Tue, 27 Aug 2024 10:47:06 +0200 Subject: [PATCH] feat: Add Twitter/X auth --- .../server/src/auth/providers/config/twitter.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/waspc/data/Generator/templates/server/src/auth/providers/config/twitter.ts b/waspc/data/Generator/templates/server/src/auth/providers/config/twitter.ts index b0a6caa117..540ec16a33 100644 --- a/waspc/data/Generator/templates/server/src/auth/providers/config/twitter.ts +++ b/waspc/data/Generator/templates/server/src/auth/providers/config/twitter.ts @@ -37,13 +37,16 @@ const _waspConfig: ProviderConfig = { Authorization: `Bearer ${accessToken}`, }, }); - const providerProfile = (await response.json()) as { + + const jsonResponse = await response.json(); + + const providerProfile = jsonResponse.data as { id?: string; name?: string; username?: string; - profile_image_url?: string; }; + if (!providerProfile.id) { throw new Error("Invalid profile"); } @@ -53,10 +56,10 @@ const _waspConfig: ProviderConfig = { return createOAuthProviderRouter({ provider, - oAuthType: 'OAuth2', + oAuthType: 'OAuth2WithPKCE', userSignupFields: _waspUserSignupFields, - getAuthorizationUrl: ({ state }) => twitter.oAuthClient.createAuthorizationURL(state, config), - getProviderTokens: ({ code }) => twitter.oAuthClient.validateAuthorizationCode(code), + getAuthorizationUrl: ({ state, codeVerifier }) => twitter.oAuthClient.createAuthorizationURL(state, codeVerifier, config), + getProviderTokens: ({ code, codeVerifier }) => twitter.oAuthClient.validateAuthorizationCode(code, codeVerifier), getProviderInfo: ({ accessToken }) => getTwitterProfile(accessToken), }); },