ng-rails-csrf 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ng-rails-csrf/version.rb +1 -1
- data/vendor/assets/javascripts/ng-rails-csrf.js +26 -5
- metadata +2 -8
- data/.gitignore +0 -17
- data/Gemfile +0 -4
- data/LICENSE.txt +0 -22
- data/README.md +0 -33
- data/Rakefile +0 -1
- data/ng-rails-csrf.gemspec +0 -19
@@ -1,6 +1,27 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
angular.module('ng-rails-csrf', [] ).config(['$httpProvider', function($httpProvider) {
|
2
|
+
var getToken = function() {
|
3
|
+
// Rails 3+
|
4
|
+
var el = document.querySelector('meta[name="csrf-token"]');
|
5
|
+
if (el) {
|
6
|
+
el = el.getAttribute('content');
|
7
|
+
} else {
|
8
|
+
// Rails 2
|
9
|
+
el = document.querySelector('input[name="authenticity_token"]');
|
10
|
+
if (el) {
|
11
|
+
el = el.value;
|
12
|
+
}
|
13
|
+
}
|
14
|
+
return el;
|
15
|
+
};
|
16
|
+
var updateToken = function() {
|
17
|
+
var headers = $httpProvider.defaults.headers.common, token = getToken();
|
18
|
+
if (token) {
|
19
|
+
headers['X-CSRF-TOKEN'] = getToken();
|
20
|
+
headers['X-Requested-With'] = 'XMLHttpRequest';
|
21
|
+
}
|
22
|
+
};
|
23
|
+
updateToken();
|
24
|
+
if (window['Turbolinks']) {
|
25
|
+
$(document).bind('page:change', updateToken);
|
26
|
+
}
|
6
27
|
}]);
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ng-rails-csrf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -18,14 +18,8 @@ executables: []
|
|
18
18
|
extensions: []
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
|
-
- .gitignore
|
22
|
-
- Gemfile
|
23
|
-
- LICENSE.txt
|
24
|
-
- README.md
|
25
|
-
- Rakefile
|
26
|
-
- lib/ng-rails-csrf.rb
|
27
21
|
- lib/ng-rails-csrf/version.rb
|
28
|
-
- ng-rails-csrf.
|
22
|
+
- lib/ng-rails-csrf.rb
|
29
23
|
- vendor/assets/javascripts/ng-rails-csrf.js
|
30
24
|
homepage: ''
|
31
25
|
licenses: []
|
data/.gitignore
DELETED
data/Gemfile
DELETED
data/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2012 Chris Dawson
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
# ng-rails-csrf
|
2
|
-
|
3
|
-
Using AngularJS and Rails together? If you are making any HTTP requests then the "ng-rails-csrf" gem can help by automatically adding the CSRF token to HTTP headers. Rails will not accept requests without this token if you are using CSRF protection.
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
gem 'ng-rails-csrf', :git => "git://github.com/xrd/ng-rails-csrf.git""
|
10
|
-
|
11
|
-
And then execute:
|
12
|
-
|
13
|
-
$ bundle
|
14
|
-
|
15
|
-
In your module definition, include the "ng-rails-csrf" module
|
16
|
-
|
17
|
-
var module = angular.module( 'mySpecialModule', [ 'ngResource', 'ng-rails-csrf' ] ).
|
18
|
-
|
19
|
-
Then, add the asset to your application.js. The following line should go *before* any module which uses it and *after* angular is included in your asset list.
|
20
|
-
|
21
|
-
//= require ng-rails-csrf
|
22
|
-
|
23
|
-
See the sample project if you need an example: https://github.com/xrd/ng-rails-csrf-sample (application.js: https://raw.github.com/xrd/ng-rails-csrf-sample/master/app/assets/javascripts/application.js)
|
24
|
-
|
25
|
-
Now all HTTP requests (both those made with the raw $http object and those created with $resource) will get the CSRF token properly included in the request headers.
|
26
|
-
|
27
|
-
## Contributing
|
28
|
-
|
29
|
-
1. Fork it
|
30
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
-
5. Create new Pull Request
|
data/Rakefile
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
data/ng-rails-csrf.gemspec
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'ng-rails-csrf/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |gem|
|
7
|
-
gem.name = "ng-rails-csrf"
|
8
|
-
gem.version = Ng::Rails::Csrf::VERSION
|
9
|
-
gem.authors = ["Chris Dawson"]
|
10
|
-
gem.email = ["xrdawson@gmail.com"]
|
11
|
-
gem.description = %q{AngularJS for using CSRF token with http requests}
|
12
|
-
gem.summary = %q{AngularJS rails gem which you can load into any rails project to make sure CSRF token is used with Angular http requests}
|
13
|
-
gem.homepage = ""
|
14
|
-
|
15
|
-
gem.files = `git ls-files`.split($/)
|
16
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
-
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
-
gem.require_paths = ["lib"]
|
19
|
-
end
|