@noatgnu/cupcake-core 1.3.14 → 1.3.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -165,7 +165,10 @@ const authInterceptor = (req, next) => {
165
165
  req.url.includes('/auth/token/') ||
166
166
  req.url.includes('/auth/orcid/') ||
167
167
  req.url.includes('/auth/register/') ||
168
- req.url.includes('/site-config/public/')) {
168
+ req.url.includes('/auth/exchange-code/') ||
169
+ req.url.includes('/site-config/public/') ||
170
+ req.url.includes('/users/auth_config/') ||
171
+ req.url.includes('/users/registration_status/')) {
169
172
  return next(req);
170
173
  }
171
174
  const token = localStorage.getItem('ccvAccessToken');
@@ -441,13 +444,19 @@ class AuthService {
441
444
  return null;
442
445
  }
443
446
  }
444
- initiateORCIDLogin() {
445
- return this.http.get(`${this.apiUrl}/auth/orcid/login/`)
447
+ initiateORCIDLogin(rememberMe = false) {
448
+ const params = rememberMe ? '?remember_me=true' : '';
449
+ return this.http.get(`${this.apiUrl}/auth/orcid/login/${params}`)
446
450
  .pipe(map(response => ({
447
451
  authorizationUrl: response.authorization_url,
448
452
  state: response.state
449
453
  })));
450
454
  }
455
+ exchangeAuthCode(authCode) {
456
+ return this.http.post(`${this.apiUrl}/auth/exchange-code/`, {
457
+ auth_code: authCode
458
+ }).pipe(tap$1(response => this.setAuthData(response)));
459
+ }
451
460
  handleORCIDCallback(code, state, rememberMe = false) {
452
461
  const params = new URLSearchParams({ code, state, remember_me: rememberMe.toString() });
453
462
  return this.http.get(`${this.apiUrl}/auth/orcid/callback/?${params}`)
@@ -504,6 +513,9 @@ class AuthService {
504
513
  getRefreshToken() {
505
514
  return localStorage.getItem('ccvRefreshToken');
506
515
  }
516
+ handleExternalLogin(response) {
517
+ this.setAuthData(response);
518
+ }
507
519
  setAuthData(response) {
508
520
  const accessToken = response.accessToken || response.access_token || response.access;
509
521
  const refreshToken = response.refreshToken || response.refresh_token || response.refresh;
@@ -863,10 +875,10 @@ class ApiService {
863
875
  }
864
876
  // Authentication configuration
865
877
  getAuthConfig() {
866
- return this.http.get(`${this.apiUrl}/users/auth_config/`);
878
+ return this.get(`${this.apiUrl}/users/auth_config/`);
867
879
  }
868
880
  getRegistrationStatus() {
869
- return this.http.get(`${this.apiUrl}/users/registration_status/`);
881
+ return this.get(`${this.apiUrl}/users/registration_status/`);
870
882
  }
871
883
  // ===================================================================
872
884
  // PASSWORD MANAGEMENT METHODS
@@ -2414,6 +2426,7 @@ class LoginComponent {
2414
2426
  returnUrl = '/';
2415
2427
  ngOnInit() {
2416
2428
  this.loadAuthConfig();
2429
+ this.handleHashParams();
2417
2430
  this.route.queryParams.subscribe(params => {
2418
2431
  this.returnUrl = this.cleanReturnUrl(params['returnUrl']) || '/';
2419
2432
  if (params['code'] && params['state']) {
@@ -2435,6 +2448,46 @@ class LoginComponent {
2435
2448
  }
2436
2449
  });
2437
2450
  }
2451
+ handleHashParams() {
2452
+ const hash = window.location.hash;
2453
+ const queryIndex = hash.indexOf('?');
2454
+ if (queryIndex === -1)
2455
+ return;
2456
+ const queryString = hash.substring(queryIndex + 1);
2457
+ const params = new URLSearchParams(queryString);
2458
+ const authCode = params.get('auth_code');
2459
+ const errorParam = params.get('error');
2460
+ if (errorParam) {
2461
+ this.error.set(`ORCID authentication failed: ${errorParam}`);
2462
+ this.cleanHashParams();
2463
+ return;
2464
+ }
2465
+ if (authCode) {
2466
+ this.loading.set(true);
2467
+ this.error.set(null);
2468
+ this.cleanHashParams();
2469
+ this.authService.exchangeAuthCode(authCode).subscribe({
2470
+ next: () => {
2471
+ this.success.set('Login successful!');
2472
+ setTimeout(() => {
2473
+ this.navigateToReturnUrl();
2474
+ }, 1000);
2475
+ },
2476
+ error: (error) => {
2477
+ this.loading.set(false);
2478
+ this.error.set(error.error?.error || error.error?.detail || 'Failed to complete authentication.');
2479
+ }
2480
+ });
2481
+ }
2482
+ }
2483
+ cleanHashParams() {
2484
+ const hash = window.location.hash;
2485
+ const queryIndex = hash.indexOf('?');
2486
+ if (queryIndex !== -1) {
2487
+ const cleanHash = hash.substring(0, queryIndex);
2488
+ window.history.replaceState(null, '', window.location.pathname + cleanHash);
2489
+ }
2490
+ }
2438
2491
  /**
2439
2492
  * Navigate to return URL, properly handling query parameters
2440
2493
  */
@@ -2540,7 +2593,8 @@ class LoginComponent {
2540
2593
  loginWithORCID() {
2541
2594
  this.loading.set(true);
2542
2595
  this.error.set(null);
2543
- this.authService.initiateORCIDLogin().subscribe({
2596
+ const rememberMe = this.loginForm.get('rememberMe')?.value || false;
2597
+ this.authService.initiateORCIDLogin(rememberMe).subscribe({
2544
2598
  next: (response) => {
2545
2599
  sessionStorage.setItem('orcid_state', response.state);
2546
2600
  window.location.href = response.authorizationUrl;
@@ -2593,8 +2647,14 @@ class LoginComponent {
2593
2647
  /**
2594
2648
  * Computed signals for UI display logic
2595
2649
  */
2596
- shouldShowOrcidLogin = computed(() => this.authConfig()?.orcidLoginEnabled === true, ...(ngDevMode ? [{ debugName: "shouldShowOrcidLogin" }] : []));
2597
- shouldShowRegistration = computed(() => this.registrationStatus()?.registrationEnabled === true, ...(ngDevMode ? [{ debugName: "shouldShowRegistration" }] : []));
2650
+ shouldShowOrcidLogin = computed(() => {
2651
+ const config = this.siteConfigService.configSubject.value;
2652
+ return config.enableOrcidLogin === true || this.authConfig()?.orcidLoginEnabled === true;
2653
+ }, ...(ngDevMode ? [{ debugName: "shouldShowOrcidLogin" }] : []));
2654
+ shouldShowRegistration = computed(() => {
2655
+ const config = this.siteConfigService.configSubject.value;
2656
+ return config.allowUserRegistration === true || this.registrationStatus()?.registrationEnabled === true;
2657
+ }, ...(ngDevMode ? [{ debugName: "shouldShowRegistration" }] : []));
2598
2658
  shouldShowRegularLogin = computed(() => this.authConfig()?.regularLoginEnabled !== false, ...(ngDevMode ? [{ debugName: "shouldShowRegularLogin" }] : []));
2599
2659
  registrationMessage = computed(() => this.registrationStatus()?.message || 'Registration is currently enabled', ...(ngDevMode ? [{ debugName: "registrationMessage" }] : []));
2600
2660
  rememberMeDuration = computed(() => {