mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-16 19:33:11 +02:00
Cache fix issues V2 (#5237)
# Description of Changes <!-- Please provide a summary of the changes, including: - What was changed - Why the change was made - Any challenges encountered Closes #(issue_number) --> --- ## Checklist ### General - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md) (if applicable) - [ ] I have performed a self-review of my own code - [ ] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing) for more details.
This commit is contained in:
@@ -343,7 +343,7 @@ describe('SpringAuthClient', () => {
|
||||
});
|
||||
|
||||
const result = await springAuth.signInWithOAuth({
|
||||
provider: 'github',
|
||||
provider: '/oauth2/authorization/github',
|
||||
options: { redirectTo: '/auth/callback' },
|
||||
});
|
||||
|
||||
|
||||
@@ -250,11 +250,11 @@ class SpringAuthClient {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sign in with OAuth provider (GitHub, Google, Authentik, etc.)
|
||||
* This redirects to the Spring OAuth2 authorization endpoint
|
||||
* Sign in with OAuth/SAML provider (GitHub, Google, Authentik, etc.)
|
||||
* This redirects to the Spring OAuth2/SAML2 authorization endpoint
|
||||
*
|
||||
* @param params.provider - OAuth provider ID (e.g., 'github', 'google', 'authentik', 'mycompany')
|
||||
* Can be any known provider or custom string - the backend determines available providers
|
||||
* @param params.provider - Full auth path from backend (e.g., '/oauth2/authorization/google', '/saml2/authenticate/stirling')
|
||||
* The backend provides the complete path including the auth type and provider ID
|
||||
*/
|
||||
async signInWithOAuth(params: {
|
||||
provider: OAuthProvider;
|
||||
@@ -264,15 +264,16 @@ class SpringAuthClient {
|
||||
const redirectPath = normalizeRedirectPath(params.options?.redirectTo);
|
||||
persistRedirectPath(redirectPath);
|
||||
|
||||
// Redirect to Spring OAuth2 endpoint (Vite will proxy to backend)
|
||||
const redirectUrl = `/oauth2/authorization/${params.provider}`;
|
||||
// console.log('[SpringAuth] Redirecting to OAuth:', redirectUrl);
|
||||
// Use the full path provided by the backend
|
||||
// This supports both OAuth2 (/oauth2/authorization/...) and SAML2 (/saml2/authenticate/...)
|
||||
const redirectUrl = params.provider;
|
||||
// console.log('[SpringAuth] Redirecting to SSO:', redirectUrl);
|
||||
// Use window.location.assign for full page navigation
|
||||
window.location.assign(redirectUrl);
|
||||
return { error: null };
|
||||
} catch (error) {
|
||||
return {
|
||||
error: { message: error instanceof Error ? error.message : 'OAuth redirect failed' },
|
||||
error: { message: error instanceof Error ? error.message : 'SSO redirect failed' },
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -295,9 +295,9 @@ describe('Login', () => {
|
||||
await user.click(oauthButton);
|
||||
|
||||
await waitFor(() => {
|
||||
// Should use 'authentik' directly, NOT map to 'oidc'
|
||||
// Should use full path directly, NOT map to 'oidc'
|
||||
expect(springAuth.signInWithOAuth).toHaveBeenCalledWith({
|
||||
provider: 'authentik',
|
||||
provider: '/oauth2/authorization/authentik',
|
||||
options: { redirectTo: '/auth/callback' }
|
||||
});
|
||||
});
|
||||
@@ -338,10 +338,10 @@ describe('Login', () => {
|
||||
await user.click(oauthButton);
|
||||
|
||||
await waitFor(() => {
|
||||
// Should use 'mycompany' directly - this is the critical fix
|
||||
// Should use full path directly - this is the critical fix
|
||||
// Previously it would map unknown providers to 'oidc'
|
||||
expect(springAuth.signInWithOAuth).toHaveBeenCalledWith({
|
||||
provider: 'mycompany',
|
||||
provider: '/oauth2/authorization/mycompany',
|
||||
options: { redirectTo: '/auth/callback' }
|
||||
});
|
||||
});
|
||||
@@ -382,9 +382,9 @@ describe('Login', () => {
|
||||
await user.click(oauthButton);
|
||||
|
||||
await waitFor(() => {
|
||||
// Should use 'oidc' when explicitly configured
|
||||
// Should use full path when explicitly configured
|
||||
expect(springAuth.signInWithOAuth).toHaveBeenCalledWith({
|
||||
provider: 'oidc',
|
||||
provider: '/oauth2/authorization/oidc',
|
||||
options: { redirectTo: '/auth/callback' }
|
||||
});
|
||||
});
|
||||
|
||||
@@ -109,13 +109,12 @@ export default function Login() {
|
||||
updateSupportedLanguages(data.languages, data.defaultLocale);
|
||||
}
|
||||
|
||||
// Extract provider IDs from the providerList map
|
||||
// The keys are like "/oauth2/authorization/google" - extract the last part
|
||||
const providerIds = Object.keys(data.providerList || {})
|
||||
.map(key => key.split('/').pop())
|
||||
.filter((id): id is string => id !== undefined);
|
||||
// Use the full paths from providerList as provider identifiers
|
||||
// The backend provides paths like "/oauth2/authorization/google" or "/saml2/authenticate/stirling"
|
||||
// We'll use these full paths so the auth client knows where to redirect
|
||||
const providerPaths = Object.keys(data.providerList || {});
|
||||
|
||||
setEnabledProviders(providerIds);
|
||||
setEnabledProviders(providerPaths);
|
||||
} catch (err) {
|
||||
console.error('[Login] Failed to fetch enabled providers:', err);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ interface OAuthButtonsProps {
|
||||
onProviderClick: (provider: OAuthProvider) => void
|
||||
isSubmitting: boolean
|
||||
layout?: 'vertical' | 'grid' | 'icons'
|
||||
enabledProviders?: OAuthProvider[] // List of enabled provider IDs from backend
|
||||
enabledProviders?: OAuthProvider[] // List of full auth paths from backend (e.g., '/oauth2/authorization/google', '/saml2/authenticate/stirling')
|
||||
}
|
||||
|
||||
export default function OAuthButtons({ onProviderClick, isSubmitting, layout = 'vertical', enabledProviders = [] }: OAuthButtonsProps) {
|
||||
@@ -37,19 +37,24 @@ export default function OAuthButtons({ onProviderClick, isSubmitting, layout = '
|
||||
? Object.keys(oauthProviderConfig)
|
||||
: enabledProviders;
|
||||
|
||||
// Build provider list - use provider ID to determine icon and label
|
||||
const providers = providersToShow.map(id => {
|
||||
if (id in oauthProviderConfig) {
|
||||
// Build provider list - extract provider ID from full path for display
|
||||
const providers = providersToShow.map(pathOrId => {
|
||||
// Extract provider ID from full path (e.g., '/saml2/authenticate/stirling' -> 'stirling')
|
||||
const providerId = pathOrId.split('/').pop() || pathOrId;
|
||||
|
||||
if (providerId in oauthProviderConfig) {
|
||||
// Known provider - use predefined icon and label
|
||||
return {
|
||||
id,
|
||||
...oauthProviderConfig[id]
|
||||
id: pathOrId, // Keep full path for redirect
|
||||
providerId, // Store extracted ID for display lookup
|
||||
...oauthProviderConfig[providerId]
|
||||
};
|
||||
}
|
||||
// Unknown provider - use generic icon and capitalize ID for label
|
||||
return {
|
||||
id,
|
||||
label: id.charAt(0).toUpperCase() + id.slice(1),
|
||||
id: pathOrId, // Keep full path for redirect
|
||||
providerId, // Store extracted ID for display lookup
|
||||
label: providerId.charAt(0).toUpperCase() + providerId.slice(1),
|
||||
file: GENERIC_PROVIDER_ICON
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user