ng-rails-csrf 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  module Ng
2
2
  module Rails
3
3
  module Csrf
4
- VERSION = "0.0.1"
4
+ VERSION = "0.1.0"
5
5
  end
6
6
  end
7
7
  end
@@ -1,6 +1,27 @@
1
-
2
- angular.module('ng-rails-csrf', [] ).config(['$httpProvider', function($httpProvider) {
3
- var authToken;
4
- authToken = $('meta[name="csrf-token"]').attr('content');
5
- $httpProvider.defaults.headers.common['X-CSRF-TOKEN'] = authToken;
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.1
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.gemspec
22
+ - lib/ng-rails-csrf.rb
29
23
  - vendor/assets/javascripts/ng-rails-csrf.js
30
24
  homepage: ''
31
25
  licenses: []
data/.gitignore DELETED
@@ -1,17 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in ng-rails-csrf.gemspec
4
- gemspec
@@ -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"
@@ -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