Skip to content
This repository was archived by the owner on Dec 12, 2025. It is now read-only.
Open
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
#spring-security-csrf-token-interceptor
# spring-security-csrf-token-interceptor-extended

> An AngularJS interceptor that will include the CSRF token header in HTTP requests.

> It does this by doing an AJAX HTTP HEAD call to / by default, and then retrieves the HTTP header 'X-CSRF-TOKEN' and sets this
same token on all HTTP requests.

`spring-security-csrf-token-interceptor` also supports configuring the CSRF header name, number of retries allowed in-case of Forbidden errors, restrict adding the CSRF tokens to some HTTP types etc.
`spring-security-csrf-token-interceptor-extended` also supports configuring the CSRF header name, number of retries allowed in-case of Forbidden errors, restrict adding the CSRF tokens to some HTTP types etc.

#Installing
###Via Bower
> This package is actually forked from [aditzel](https://github.com/aditzel/spring-security-csrf-token-interceptor) to continuing the support for latest versions.

# Installing
### Via Bower
````
$ bower install spring-security-csrf-token-interceptor
$ bower install spring-security-csrf-token-interceptor-extended
````
###Via NPM
### Via NPM
````
$ npm install spring-security-csrf-token-interceptor
$ npm install spring-security-csrf-token-interceptor-extended
````

#Usage
# Usage
Include this as a dependency on your application:

````javascript
Expand All @@ -28,7 +30,7 @@ Use the `configProvider` to customize the interceptor behavior. Check [Configura
````javascript
csrfProvider.config({});
````
#Configuration
# Configuration
The following options are available for configuring the interceptor,

````
Expand All @@ -47,7 +49,7 @@ Note: All these below configurations are optional.

- `options.csrfTokenHeader` (String) - Customize the name of the CSRF header on the requests. Default: `X-CSRF-TOKEN`.

###Example
### Example

```js
angular
Expand All @@ -65,4 +67,4 @@ Note: All these below configurations are optional.
});
}).run(function() {
});
```
```
9 changes: 5 additions & 4 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{
"name": "spring-security-csrf-token-interceptor",
"version": "0.2.0",
"name": "spring-security-csrf-token-interceptor-extended",
"version": "0.2.1",
"authors": [
"Allan Ditzel <allan@allanditzel.com>"
],
"description": "An AngularJS interceptor for the HTTP service that adds the Spring Security CSRF token to all requests (if available).",
"main": "src/spring-security-csrf-token-interceptor.js",
"main": "dist/spring-security-csrf-token-interceptor-extended.min.js",
"keywords": [
"spring-security",
"csrf",
"token",
"http",
"interceptor"
"interceptor",
"angularJS"
],
"license": "Apache 2.0",
"homepage": "https://github.com/aditzel/spring-security-csrf-token-interceptor",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion dist/spring-security-csrf-token-interceptor.min.js

This file was deleted.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "spring-security-csrf-token-interceptor",
"version": "0.2.0",
"name": "spring-security-csrf-token-interceptor-extended",
"version": "0.2.1",
"description": "An AngularJS interceptor for the HTTP service that adds the Spring Security CSRF token to all requests (if available).",
"main": "src/spring-security-csrf-token-interceptor.js",
"main": "dist/spring-security-csrf-token-interceptor-extended.min.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand All @@ -15,7 +15,8 @@
"csrf",
"token",
"http",
"interceptor"
"interceptor",
"angularJS"
],
"author": "Allan Ditzel",
"license": "Apache 2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
function($injector) {
var $q = $injector.get('$q'),
csrf = $injector.get('csrf'),
// initialize the csrf provider service which in-turn invokes the injected csrfService
// initialize the csrf provider service which in-turn invokes the injected csrfService
// to fire the synchronous XHR call to get the CSRF token
csrfService = csrf.init();

Expand All @@ -40,7 +40,7 @@
responseError: function(response) {
var $http,
newToken = response.headers(csrfService.settings.csrfTokenHeader);

if (response.status === 403 && csrfService.numRetries < csrfService.settings.maxRetries) {
csrfService.getTokenData();
$http = $injector.get('$http');
Expand Down Expand Up @@ -78,7 +78,6 @@
init: function(options) {
this.settings = angular.extend({}, defaults, options);
this.getTokenData();
console.log(this.settings, this.defaults, options);
},
getTokenData: function() {
var xhr = new XMLHttpRequest();
Expand Down