mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
Use status request to check an existing token and to retrieve auth methods available
This commit is contained in:
@@ -16,7 +16,13 @@ import { AuthStatus } from './models/auth-status.model';
|
||||
import { AuthTokenInfo, TOKENITEM } from './models/auth-token-info.model';
|
||||
import { isEmpty, isNotEmpty, isNotNull, isNotUndefined } from '../../shared/empty.util';
|
||||
import { CookieService } from '../services/cookie.service';
|
||||
import { getAuthenticationToken, getRedirectUrl, isAuthenticated, isTokenRefreshing } from './selectors';
|
||||
import {
|
||||
getAuthenticationMethods,
|
||||
getAuthenticationToken,
|
||||
getRedirectUrl,
|
||||
isAuthenticated,
|
||||
isTokenRefreshing
|
||||
} from './selectors';
|
||||
import { AppState, routerStateSelector } from '../../app.reducer';
|
||||
import {
|
||||
CheckAuthenticationTokenAction,
|
||||
@@ -28,6 +34,7 @@ import { Base64EncodeUrl } from '../../shared/utils/encode-decode.util';
|
||||
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
||||
import { RouteService } from '../services/route.service';
|
||||
import { AuthMethod } from './models/auth.method';
|
||||
import { NormalizedAuthStatus } from './models/normalized-auth-status.model';
|
||||
|
||||
export const LOGIN_ROUTE = '/login';
|
||||
export const LOGOUT_ROUTE = '/logout';
|
||||
@@ -121,7 +128,14 @@ export class AuthService {
|
||||
* Checks if token is present into the request cookie
|
||||
*/
|
||||
public checkAuthenticationCookie(): Observable<AuthStatus> {
|
||||
return this.authRequestService.postToEndpoint('login');
|
||||
// Determine if the user has an existing auth session on the server
|
||||
const options: HttpOptions = Object.create({});
|
||||
let headers = new HttpHeaders();
|
||||
headers = headers.append('Accept', 'application/json');
|
||||
options.headers = headers;
|
||||
return this.authRequestService.getRequest('status', options).pipe(
|
||||
map((status: NormalizedAuthStatus) => Object.assign(new AuthStatus(), status))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -158,7 +172,13 @@ export class AuthService {
|
||||
* Checks if token is present into browser storage and is valid. (NB Check is done only on SSR)
|
||||
*/
|
||||
public checkAuthenticationToken() {
|
||||
this.store.dispatch(new CheckAuthenticationTokenAction());
|
||||
this.store.pipe(
|
||||
select(getAuthenticationMethods),
|
||||
filter((authMethods: AuthMethod[]) => isEmpty(authMethods)),
|
||||
take(1)
|
||||
).subscribe(() => {
|
||||
this.store.dispatch(new CheckAuthenticationTokenAction());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user