Skip to content

Commit 0ce57bd

Browse files
committed
Add missing git-auth-helpers
1 parent d058f66 commit 0ce57bd

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { oAuthState } from './state';
2+
3+
const KNOWN_CORS_PROXY_URLS = [
4+
'https://playground.wordpress.net/cors-proxy.php?',
5+
'https://wordpress-playground-cors-proxy.net/?',
6+
'http://127.0.0.1:5263/cors-proxy.php?',
7+
];
8+
9+
export function isGitHubUrl(url: string): boolean {
10+
if (url.includes('github.com')) {
11+
return true;
12+
}
13+
for (const corsProxyUrl of KNOWN_CORS_PROXY_URLS) {
14+
if (
15+
url.startsWith(corsProxyUrl) &&
16+
url.substring(corsProxyUrl.length).includes('github.com')
17+
) {
18+
return true;
19+
}
20+
}
21+
return false;
22+
}
23+
24+
export function createGitHubAuthHeaders(): Record<string, string> {
25+
const token = oAuthState.value.token;
26+
if (!token) {
27+
return {};
28+
}
29+
30+
return {
31+
Authorization: `Basic ${btoa(`${token}:`)}`,
32+
// Tell the CORS proxy to forward the Authorization header
33+
'X-Cors-Proxy-Allowed-Request-Headers': 'Authorization',
34+
};
35+
}

packages/playground/website/src/lib/state/redux/boot-site-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { selectSiteBySlug } from './slice-sites';
2727
// @ts-ignore
2828
import { corsProxyUrl } from 'virtual:cors-proxy-url';
2929
import { modalSlugs } from '../../../components/layout';
30-
import { createGitHubAuthHeaders } from '../../github/git-auth-helpers';
30+
import { createGitHubAuthHeaders } from '../../../github/git-auth-helpers';
3131

3232
export function bootSiteClient(
3333
siteSlug: string,

0 commit comments

Comments
 (0)