mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 00:27:24 +00:00
Swap out corsproxy.io for our custom proxy
This commit is contained in:
6 files changed
+35
-25
No files matched your search
@@ -61,7 +61,7 @@ describe('useGitHubOAuth PKCE', () => {
|
||||
wrapper: TestApp,
|
||||
});
|
||||
|
||||
// Mock fetch for token exchange and user info (using corsproxy.io URLs)
|
||||
// Mock fetch for token exchange and user info (using proxy URLs)
|
||||
const mockFetch = vi.fn()
|
||||
.mockResolvedValueOnce({
|
||||
ok: true,
|
||||
@@ -147,7 +147,7 @@ describe('useGitHubOAuth PKCE', () => {
|
||||
|
||||
// Check that the token request includes the code verifier
|
||||
expect(mockFetch).toHaveBeenCalledWith(
|
||||
expect.stringContaining('corsproxy.io/?url=https://github.com/login/oauth/access_token'),
|
||||
'https://proxy.shakespeare.diy/?url=https%3A%2F%2Fgithub.com%2Flogin%2Foauth%2Faccess_token',
|
||||
expect.objectContaining({
|
||||
method: 'POST',
|
||||
body: expect.stringContaining('"code_verifier":"test-verifier"'),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useState, useCallback } from 'react';
|
||||
import { useGitSettings } from './useGitSettings';
|
||||
import { proxyUrl } from '@/lib/proxyUrl';
|
||||
|
||||
interface GitHubOAuthState {
|
||||
isLoading: boolean;
|
||||
@@ -17,7 +18,8 @@ export function useGitHubOAuth() {
|
||||
isLoading: false,
|
||||
error: null,
|
||||
});
|
||||
const { addCredential } = useGitSettings();
|
||||
const { settings, addCredential } = useGitSettings();
|
||||
const { corsProxy } = settings;
|
||||
|
||||
// Check if OAuth is configured
|
||||
const isOAuthConfigured = !!(
|
||||
@@ -122,7 +124,8 @@ export function useGitHubOAuth() {
|
||||
code_verifier: codeVerifier,
|
||||
};
|
||||
|
||||
const tokenResponse = await fetch('https://corsproxy.io/?url=https://github.com/login/oauth/access_token', {
|
||||
const tokenUrl = proxyUrl(corsProxy, 'https://github.com/login/oauth/access_token');
|
||||
const tokenResponse = await fetch(tokenUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
@@ -142,7 +145,8 @@ export function useGitHubOAuth() {
|
||||
}
|
||||
|
||||
// Get user info to verify the token works
|
||||
const userResponse = await fetch('https://corsproxy.io/?url=https://api.github.com/user', {
|
||||
const userUrl = proxyUrl(corsProxy, 'https://api.github.com/user');
|
||||
const userResponse = await fetch(userUrl, {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${tokenData.access_token}`,
|
||||
'Accept': 'application/vnd.github.v3+json',
|
||||
@@ -177,7 +181,7 @@ export function useGitHubOAuth() {
|
||||
}));
|
||||
return false;
|
||||
}
|
||||
}, [addCredential]);
|
||||
}, [addCredential, corsProxy]);
|
||||
|
||||
return {
|
||||
...state,
|
||||
|
||||
Reference in new issue
Block a user