mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 02:24:11 +00:00
Add withCredentials param to request options instead of using http interceptor
This commit is contained in:
@@ -213,7 +213,6 @@ export class AuthInterceptor implements HttpInterceptor {
|
|||||||
|
|
||||||
const token: AuthTokenInfo = authService.getToken();
|
const token: AuthTokenInfo = authService.getToken();
|
||||||
let newReq: HttpRequest<any>;
|
let newReq: HttpRequest<any>;
|
||||||
let updateReq: any = {};
|
|
||||||
let authorization: string;
|
let authorization: string;
|
||||||
|
|
||||||
if (authService.isTokenExpired()) {
|
if (authService.isTokenExpired()) {
|
||||||
@@ -239,10 +238,7 @@ export class AuthInterceptor implements HttpInterceptor {
|
|||||||
// Clone the request to add the new header.
|
// Clone the request to add the new header.
|
||||||
newReq = req.clone({ headers: req.headers.set('authorization', authorization) });
|
newReq = req.clone({ headers: req.headers.set('authorization', authorization) });
|
||||||
} else {
|
} else {
|
||||||
if (this.isAuthRequest(req)) {
|
newReq = req.clone();
|
||||||
updateReq = { withCredentials: true };
|
|
||||||
}
|
|
||||||
newReq = req.clone(updateReq);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pass on the new request instead of the original request.
|
// Pass on the new request instead of the original request.
|
||||||
|
@@ -16,13 +16,7 @@ import { AuthStatus } from './models/auth-status.model';
|
|||||||
import { AuthTokenInfo, TOKENITEM } from './models/auth-token-info.model';
|
import { AuthTokenInfo, TOKENITEM } from './models/auth-token-info.model';
|
||||||
import { isEmpty, isNotEmpty, isNotNull, isNotUndefined } from '../../shared/empty.util';
|
import { isEmpty, isNotEmpty, isNotNull, isNotUndefined } from '../../shared/empty.util';
|
||||||
import { CookieService } from '../services/cookie.service';
|
import { CookieService } from '../services/cookie.service';
|
||||||
import {
|
import { getAuthenticationToken, getRedirectUrl, isAuthenticated, isTokenRefreshing } from './selectors';
|
||||||
getAuthenticationMethods,
|
|
||||||
getAuthenticationToken,
|
|
||||||
getRedirectUrl,
|
|
||||||
isAuthenticated,
|
|
||||||
isTokenRefreshing
|
|
||||||
} from './selectors';
|
|
||||||
import { AppState, routerStateSelector } from '../../app.reducer';
|
import { AppState, routerStateSelector } from '../../app.reducer';
|
||||||
import {
|
import {
|
||||||
CheckAuthenticationTokenAction,
|
CheckAuthenticationTokenAction,
|
||||||
@@ -134,6 +128,7 @@ export class AuthService {
|
|||||||
let headers = new HttpHeaders();
|
let headers = new HttpHeaders();
|
||||||
headers = headers.append('Accept', 'application/json');
|
headers = headers.append('Accept', 'application/json');
|
||||||
options.headers = headers;
|
options.headers = headers;
|
||||||
|
options.withCredentials = true;
|
||||||
return this.authRequestService.getRequest('status', options).pipe(
|
return this.authRequestService.getRequest('status', options).pipe(
|
||||||
map((status: NormalizedAuthStatus) => Object.assign(new AuthStatus(), status))
|
map((status: NormalizedAuthStatus) => Object.assign(new AuthStatus(), status))
|
||||||
);
|
);
|
||||||
@@ -207,6 +202,7 @@ export class AuthService {
|
|||||||
headers = headers.append('Authorization', `Bearer ${token.accessToken}`);
|
headers = headers.append('Authorization', `Bearer ${token.accessToken}`);
|
||||||
}
|
}
|
||||||
options.headers = headers;
|
options.headers = headers;
|
||||||
|
options.withCredentials = true;
|
||||||
return this.authRequestService.postToEndpoint('login', {}, options).pipe(
|
return this.authRequestService.postToEndpoint('login', {}, options).pipe(
|
||||||
map((status: AuthStatus) => {
|
map((status: AuthStatus) => {
|
||||||
if (status.authenticated) {
|
if (status.authenticated) {
|
||||||
|
@@ -91,6 +91,14 @@ export class DSpaceRESTv2Service {
|
|||||||
requestOptions.headers = options.headers;
|
requestOptions.headers = options.headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options && options.params) {
|
||||||
|
requestOptions.params = options.params;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options && options.withCredentials) {
|
||||||
|
requestOptions.withCredentials = options.withCredentials;
|
||||||
|
}
|
||||||
|
|
||||||
if (!requestOptions.headers.has('Content-Type')) {
|
if (!requestOptions.headers.has('Content-Type')) {
|
||||||
// Because HttpHeaders is immutable, the set method returns a new object instead of updating the existing headers
|
// Because HttpHeaders is immutable, the set method returns a new object instead of updating the existing headers
|
||||||
requestOptions.headers = requestOptions.headers.set('Content-Type', DEFAULT_CONTENT_TYPE);
|
requestOptions.headers = requestOptions.headers.set('Content-Type', DEFAULT_CONTENT_TYPE);
|
||||||
|
Reference in New Issue
Block a user