mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
[AAE-12531] Fix window.location.search is empty when loginCallback is called
This commit is contained in:
@@ -18,9 +18,10 @@
|
|||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
import { RouterModule, Routes } from '@angular/router';
|
import { RouterModule, Routes } from '@angular/router';
|
||||||
import { AuthenticationConfirmationComponent } from './view/authentication-confirmation/authentication-confirmation.component';
|
import { AuthenticationConfirmationComponent } from './view/authentication-confirmation/authentication-confirmation.component';
|
||||||
|
import { OidcAuthGuard } from './oidc-auth.guard';
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{ path: 'view/authentication-confirmation', component: AuthenticationConfirmationComponent }
|
{ path: 'view/authentication-confirmation', component: AuthenticationConfirmationComponent, canActivate: [OidcAuthGuard]}
|
||||||
];
|
];
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
|
@@ -61,7 +61,8 @@ export function loginFactory(oAuthService: OAuthService, storage: OAuthStorage,
|
|||||||
useFactory: loginFactory,
|
useFactory: loginFactory,
|
||||||
deps: [OAuthService, OAuthStorage, AUTH_CONFIG],
|
deps: [OAuthService, OAuthStorage, AUTH_CONFIG],
|
||||||
multi: true
|
multi: true
|
||||||
}
|
},
|
||||||
|
OidcAuthGuard
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class AuthModule {
|
export class AuthModule {
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { TokenResponse } from 'angular-oauth2-oidc';
|
import { LoginOptions, TokenResponse } from 'angular-oauth2-oidc';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,6 +54,6 @@ export abstract class AuthService {
|
|||||||
*
|
*
|
||||||
* @returns Promise, resolve with stored state, reject if unable to reach IdP
|
* @returns Promise, resolve with stored state, reject if unable to reach IdP
|
||||||
*/
|
*/
|
||||||
abstract loginCallback(): Promise<string | undefined>;
|
abstract loginCallback(loginOptions?: LoginOptions): Promise<string | undefined>;
|
||||||
abstract updateIDPConfiguration(...args: any[]): void;
|
abstract updateIDPConfiguration(...args: any[]): void;
|
||||||
}
|
}
|
||||||
|
@@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot, UrlTree } from '@angular/router';
|
import { CanActivate, UrlTree } from '@angular/router';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { AuthService } from './auth.service';
|
import { AuthService } from './auth.service';
|
||||||
|
|
||||||
@@ -25,22 +25,20 @@ export class OidcAuthGuard implements CanActivate {
|
|||||||
constructor(private auth: AuthService) {}
|
constructor(private auth: AuthService) {}
|
||||||
|
|
||||||
canActivate(
|
canActivate(
|
||||||
_route: ActivatedRouteSnapshot,
|
|
||||||
state: RouterStateSnapshot
|
|
||||||
): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
|
): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
|
||||||
return this._isAuthenticated(state);
|
return this._isAuthenticated();
|
||||||
}
|
}
|
||||||
|
|
||||||
canActivateChild(_route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
canActivateChild() {
|
||||||
return this._isAuthenticated(state);
|
return this._isAuthenticated();
|
||||||
}
|
}
|
||||||
|
|
||||||
private _isAuthenticated(state: RouterStateSnapshot) {
|
private _isAuthenticated() {
|
||||||
if (this.auth.authenticated) {
|
if (this.auth.authenticated) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const loginResult = this.auth.login(state.url);
|
const loginResult = this.auth.loginCallback({customHashFragment: window.location.search});
|
||||||
|
|
||||||
if (loginResult instanceof Promise) {
|
if (loginResult instanceof Promise) {
|
||||||
return loginResult.then(() => true).catch(() => false);
|
return loginResult.then(() => true).catch(() => false);
|
||||||
|
@@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Inject, Injectable } from '@angular/core';
|
import { Inject, Injectable } from '@angular/core';
|
||||||
import { AuthConfig, AUTH_CONFIG, OAuthErrorEvent, OAuthService, OAuthStorage, TokenResponse } from 'angular-oauth2-oidc';
|
import { AuthConfig, AUTH_CONFIG, OAuthErrorEvent, OAuthService, OAuthStorage, TokenResponse, LoginOptions } from 'angular-oauth2-oidc';
|
||||||
import { JwksValidationHandler } from 'angular-oauth2-oidc-jwks';
|
import { JwksValidationHandler } from 'angular-oauth2-oidc-jwks';
|
||||||
import { from, Observable } from 'rxjs';
|
import { from, Observable } from 'rxjs';
|
||||||
import { distinctUntilChanged, filter, map, shareReplay } from 'rxjs/operators';
|
import { distinctUntilChanged, filter, map, shareReplay } from 'rxjs/operators';
|
||||||
@@ -127,9 +127,9 @@ export class RedirectAuthService extends AuthService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async loginCallback(): Promise<string | undefined> {
|
async loginCallback(loginOptions?: LoginOptions): Promise<string | undefined> {
|
||||||
return this.ensureDiscoveryDocument()
|
return this.ensureDiscoveryDocument()
|
||||||
.then(() => this.oauthService.tryLogin({ preventClearHashAfterLogin: true }))
|
.then(() => this.oauthService.tryLogin({ ...loginOptions, preventClearHashAfterLogin: true }))
|
||||||
.then(() => this._getRedirectUrl());
|
.then(() => this._getRedirectUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user