Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Studio: Update "Create a free account" link to redirect to magic signup flow #123

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/components/content-tab-snapshots.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { __, sprintf } from '@wordpress/i18n';
import { Icon, check, external } from '@wordpress/icons';
import { useI18n } from '@wordpress/react-i18n';
import { PropsWithChildren, useEffect } from 'react';
import { CLIENT_ID, PROTOCOL_PREFIX, WP_AUTHORIZE_ENDPOINT, SCOPES } from '../constants';
import { useArchiveSite } from '../hooks/use-archive-site';
import { useAuth } from '../hooks/use-auth';
import { useDeleteSnapshot } from '../hooks/use-delete-snapshot';
Expand Down Expand Up @@ -336,7 +337,12 @@ function NoAuth( { selectedSite }: React.ComponentProps< typeof EmptyGeneric > )
if ( isOffline ) {
return;
}
getIpcApi().openURL( 'https://wordpress.com/start/account/user-social' );
const baseURL = 'https://wordpress.com/log-in/link';
const authURL = encodeURIComponent(
`${ WP_AUTHORIZE_ENDPOINT }?response_type=token&client_id=${ CLIENT_ID }&redirect_uri=${ PROTOCOL_PREFIX }%3A%2F%2Fauth&scope=${ SCOPES }&from-calypso=1`
);
const finalURL = `${ baseURL }?redirect_to=${ authURL }&client_id=${ CLIENT_ID }`;
getIpcApi().openURL( finalURL );
} }
/>
),
Expand Down
5 changes: 5 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ export const AUTO_UPDATE_INTERVAL_MS = 60 * 60 * 1000;
export const WINDOWS_TITLEBAR_HEIGHT = 32;
export const STUDIO_DOCS_URL = `https://developer.wordpress.com/docs/developer-tools/studio/`;
export const WPCOM_PROFILE_URL = `https://wordpress.com/me`;
// OAuth constants
export const CLIENT_ID = '95109';
export const PROTOCOL_PREFIX = 'wpcom-local-dev';
export const WP_AUTHORIZE_ENDPOINT = 'https://public-api.wordpress.com/oauth2/authorize';
export const SCOPES = 'global';
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import path from 'path';
import * as Sentry from '@sentry/electron/main';
import { __, defaultI18n } from '@wordpress/i18n';
import packageJson from '../package.json';
import { PROTOCOL_PREFIX } from './constants';
import * as ipcHandlers from './ipc-handlers';
import { bumpAggregatedUniqueStat } from './lib/bump-stats';
import { getLocaleData, getSupportedLocale } from './lib/locale';
import { PROTOCOL_PREFIX, handleAuthCallback, setUpAuthCallbackHandler } from './lib/oauth';
import { handleAuthCallback, setUpAuthCallbackHandler } from './lib/oauth';
import { setupLogging } from './logging';
import { createMainWindow, withMainWindow } from './main-window';
import {
Expand Down
8 changes: 1 addition & 7 deletions src/lib/oauth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ipcMain, shell } from 'electron';
import * as Sentry from '@sentry/electron/main';
import wpcom from 'wpcom';
import { PROTOCOL_PREFIX, WP_AUTHORIZE_ENDPOINT, CLIENT_ID, SCOPES } from '../constants';
import { withMainWindow } from '../main-window';
import { loadUserData, saveUserData } from '../storage/user-data';

Expand All @@ -11,14 +12,7 @@ export interface StoredToken {
email?: string;
displayName?: string;
}

export const PROTOCOL_PREFIX = 'wpcom-local-dev';

const WP_AUTHORIZE_ENDPOINT = 'https://public-api.wordpress.com/oauth2/authorize';
const CLIENT_ID = '95109';
const REDIRECT_URI = `${ PROTOCOL_PREFIX }://auth`;

const SCOPES = 'global';
const TOKEN_KEY = 'authToken';

async function getToken(): Promise< StoredToken | null > {
Expand Down
Loading