Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
web-et-numerique
web-et-numerique-internet
data.grandlyon.com
web-portal
components
custom-apps
web-app
Commits
3792d57e
Commit
3792d57e
authored
Oct 16, 2019
by
FORESTIER Fabien
Browse files
Make angular set a x-xsrf-token header on http requests using its csrf feature
parent
f3c55560
Pipeline
#1764
failed with stages
in 9 minutes and 28 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/app/app.module.ts
View file @
3792d57e
import
{
BrowserModule
}
from
'
@angular/platform-browser
'
;
import
{
BrowserAnimationsModule
}
from
'
@angular/platform-browser/animations
'
;
import
{
NgModule
,
APP_INITIALIZER
}
from
'
@angular/core
'
;
import
{
HttpClientModule
}
from
'
@angular/common/http
'
;
import
{
HttpClientModule
,
HttpClientXsrfModule
}
from
'
@angular/common/http
'
;
import
{
AppComponent
}
from
'
./app.component
'
;
import
{
AppRoutingModule
}
from
'
./app-routing.module
'
;
...
...
@@ -44,6 +44,9 @@ export function initAppConfig(appConfigService: AppConfigService) {
BrowserModule
,
BrowserAnimationsModule
,
HttpClientModule
,
HttpClientXsrfModule
.
withOptions
({
headerName
:
'
x-xsrf-token
'
,
}),
CoreModule
,
EditorialisationModule
,
UserModule
,
...
...
src/app/user/interceptors/auth-interceptor.ts
deleted
100644 → 0
View file @
f3c55560
import
{
HttpInterceptor
,
HttpRequest
,
HttpHandler
,
HttpEvent
}
from
'
@angular/common/http
'
;
import
{
Injectable
}
from
'
@angular/core
'
;
import
{
Observable
}
from
'
rxjs
'
;
@
Injectable
()
export
class
AuthInterceptor
implements
HttpInterceptor
{
intercept
(
req
:
HttpRequest
<
any
>
,
next
:
HttpHandler
,
):
Observable
<
HttpEvent
<
any
>>
{
const
xsrfToken
=
localStorage
.
getItem
(
'
xsrfToken
'
);
let
request
=
req
;
// && req.url.includes('https://data-intothesky.alpha.grandlyon.com/authentication/api/logout'
if
(
xsrfToken
)
{
request
=
req
.
clone
({
headers
:
req
.
headers
.
set
(
'
x-xsrf-token
'
,
xsrfToken
),
});
}
return
next
.
handle
(
request
);
}
}
src/app/user/user.module.ts
View file @
3792d57e
...
...
@@ -4,8 +4,6 @@ import { UserRoutingModule } from './user-routing.module';
import
{
UserServices
}
from
'
./services
'
;
import
{
UserComponents
}
from
'
./components
'
;
import
{
FormsModule
,
ReactiveFormsModule
}
from
'
@angular/forms
'
;
import
{
HTTP_INTERCEPTORS
}
from
'
@angular/common/http
'
;
import
{
AuthInterceptor
}
from
'
./interceptors/auth-interceptor
'
;
import
{
UserGuards
}
from
'
./guards
'
;
import
{
SharedModule
}
from
'
../shared/shared.module
'
;
...
...
@@ -20,11 +18,6 @@ import { SharedModule } from '../shared/shared.module';
providers
:
[
...
UserGuards
,
...
UserServices
,
{
provide
:
HTTP_INTERCEPTORS
,
useClass
:
AuthInterceptor
,
multi
:
true
,
},
],
declarations
:
[...
UserComponents
],
})
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment