super_token 1.0.0 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ecc5d2fae093eb6123d5b016b48d1e63977f1f0f
4
- data.tar.gz: 1192d3a13440aff01cbbf43316447db20e5e6f9a
2
+ SHA256:
3
+ metadata.gz: 4ea30d63401a1aeaa7271ac99dfa66e459a76fe645357b2aaabddb3479c77b6e
4
+ data.tar.gz: 30915900f03d12d13ffdd437d2469dd5e038752a252be07c046e6b4128217b25
5
5
  SHA512:
6
- metadata.gz: 4e5d89fc1795b0f6d3350f87ff2ecd22a8b5036b5409d0849cce5123129cdf2cb98f3f27bef37a6190411c52ccf40d11bd906e64fbd4bf15c3af039e2c7ad4b3
7
- data.tar.gz: 9bc9b3e09da2cb9b0b480260dc1028a6b9904366b8fcb4dec8b9881e98f1c2c50e2b3f0e974a796a60f758b6ba0382987093af54a653dc1a851ec01f22ec17cd
6
+ metadata.gz: 9d13341247f9f789251bf40e9d6bca654b5de31d9a4de554afd1e833fe0c8a2dc397c10dffaeb5bb17d7558fbf8eb5539e4a7afe8d16d2025759f76fd85e97be
7
+ data.tar.gz: 9793540bff0d1dee733933da994696d05e5def533d880fe2da4b3958fd8c7dd1f59c79a3c764c8763b64458a0b0da63a6d4467683a2f34dc294f2ff02933967a
data/.travis.yml CHANGED
@@ -4,11 +4,23 @@ rvm:
4
4
  - 2.0.0
5
5
  - 2.1
6
6
  - 2.2
7
+ - 2.3.0
7
8
  gemfile:
8
9
  - gemfiles/rails3.gemfile
9
10
  - gemfiles/rails4_0.gemfile
10
11
  - gemfiles/rails4_1.gemfile
11
12
  - gemfiles/rails4_2.gemfile
13
+ - gemfiles/rails5_0.gemfile
14
+ matrix:
15
+ exclude:
16
+ - rvm: 1.9.3
17
+ gemfile: gemfiles/rails5_0.gemfile
18
+ - rvm: 2.0.0
19
+ gemfile: gemfiles/rails5_0.gemfile
20
+ - rvm: 2.1
21
+ gemfile: gemfiles/rails5_0.gemfile
22
+ - rvm: 2.2
23
+ gemfile: gemfiles/rails5_0.gemfile
12
24
  before_install:
13
25
  - gem update --system
14
26
  - gem install bundler
data/README.md CHANGED
@@ -1,19 +1,18 @@
1
- [![Build Status](https://travis-ci.org/robertomiranda/has_secure_token.png)](https://travis-ci.org/robertomiranda/has_secure_token)
2
- [![Gem Version](https://badge.fury.io/rb/has_secure_token.svg)](http://badge.fury.io/rb/has_secure_token)
3
- [![Dependency Status](https://gemnasium.com/robertomiranda/has_secure_token.svg)](https://gemnasium.com/robertomiranda/has_secure_token)
4
- [![Code Climate](https://codeclimate.com/github/robertomiranda/has_secure_token/badges/gpa.svg)](https://codeclimate.com/github/robertomiranda/has_secure_token)
1
+ [![Build Status](https://travis-ci.org/ecleel/super_token.svg?branch=master)](https://travis-ci.org/ecleel/super_token)
2
+ [![Gem Version](https://badge.fury.io/rb/super_token.svg)](https://badge.fury.io/rb/super_token)
3
+ [![Dependency Status](https://gemnasium.com/ecleel/super_token.svg)](https://gemnasium.com/ecleel/super_token)
4
+ [![Code Climate](https://codeclimate.com/github/ecleel/super_token/badges/gpa.svg)](https://codeclimate.com/github/ecleel/super_token)
5
+ [![Test Coverage](https://codeclimate.com/github/ecleel/super_token/badges/coverage.svg)](https://codeclimate.com/github/ecleel/super_token/coverage)
5
6
 
6
- # HasSecureToken
7
+ # SuperToken
7
8
 
8
- HasSecureToken provides an easy way to generate uniques random tokens for any model in ruby on rails. **SecureRandom::base58** is used to generate the 24-character unique tokens, so collisions are highly unlikely.
9
-
10
- **Note** If you're worried about possible collissions, there's a way to generate a race condition in the database in the same way that [validates_uniqueness_of](http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html) can. You're encouraged to add an unique index in the database to deal with this even more unlikely scenario.
9
+ SuperToken is a fork of [HasSecureToken](https://github.com/robertomiranda/has_secure_token) module which is provides an easy way to generate uniques random tokens for any model in ruby on rails. SuperToken gives you a way to prefix token with string and change token length.
11
10
 
12
11
  ## Installation
13
12
 
14
13
  Add this line to your application's Gemfile:
15
14
 
16
- gem 'has_secure_token'
15
+ gem 'super_token'
17
16
 
18
17
  And then run:
19
18
 
@@ -21,45 +20,50 @@ And then run:
21
20
 
22
21
  Or install it yourself as:
23
22
 
24
- $ gem install has_secure_token
23
+ $ gem install super_token
25
24
 
26
25
  ## Setting your Model
27
26
 
28
27
  The first step is to generate a migration in order to add the token key field.
29
28
 
30
29
  ```ruby
31
- rails g migration AddTokenToUsers token:string
30
+ rails g migration AddTokenToAPIKey token:string secret_key:string public_key:string
32
31
  =>
33
32
  invoke active_record
34
- create db/migrate/20150424010931_add_token_to_users.rb
33
+ create db/migrate/20150424010931_add_token_to_api_key_.rb
35
34
  ```
36
35
 
37
36
  Then run `rake db:migrate` in order to update users table in the database. The next step is to add `has_secure_token`
38
37
  to the model:
39
38
  ```ruby
40
- # Schema: User(token:string, auth_token:string)
41
- class User < ActiveRecord::Base
39
+ # Schema: APIKey(token:string, secret_key:string, public_key:string)
40
+ class APIKey < ActiveRecord::Base
42
41
  has_secure_token
43
42
  end
44
43
 
45
- user = User.new
46
- user.save
47
- user.token # => "pX27zsMN2ViQKta1bGfLmVJE"
48
- user.regenerate_token # => true
44
+ # test regular has_secure_token features
45
+ api_key = APIKey.new
46
+ api_key.save
47
+ api_key.token # => "pX27zsMN2ViQKta1bGfLmVJE"
48
+ api_key.regenerate_token # => true
49
49
  ```
50
50
 
51
51
  To use a custom column to store the token key field you can specify the column_name option. See example above (e.g: auth_token):
52
52
 
53
53
  ```ruby
54
- # Schema: User(token:string, auth_token:string)
55
- class User < ActiveRecord::Base
56
- has_secure_token :auth_token
54
+ # Schema: APIKey(token:string, secret_key:string, public_key:string)
55
+ class APIKey < ActiveRecord::Base
56
+ # super_token add two options for has_secure_token (prefix and length)
57
+ has_secure_token :secret_key, prefix: 'sk_', length: 48
58
+ has_secure_token :public_key, prefix: 'pk_', length: 48
57
59
  end
58
60
 
59
- user = User.new
60
- user.save
61
- user.auth_token # => "pX27zsMN2ViQKta1bGfLmVJE"
62
- user.regenerate_auth_token # => true
61
+
62
+ api_key = APIKey.new
63
+ api_key.save
64
+ api_key.secret_key # => "sk_pX27zsMN2ViQKta1bGfLmVJEiQKta1bGfLmVJE"
65
+ api_key.public_key # => "pk_pX27zsMN2ViQKta1bGfLmVJEiQKta1bGfLmVJE"
66
+ api_key.regenerate_secret_key # => true
63
67
  ```
64
68
 
65
69
  ## Running tests
@@ -73,12 +77,12 @@ $ rake test
73
77
  Should return
74
78
 
75
79
  ```shell
76
- 5 runs, 9 assertions, 0 failures, 0 errors, 0 skips
80
+ 9 runs, 17 assertions, 0 failures, 0 errors, 0 skips
77
81
  ```
78
82
 
79
83
  ## Contributing
80
84
 
81
- 1. Fork it ( https://github.com/robertomiranda/has_secure_token/fork )
85
+ 1. Fork it ( https://github.com/ecleel/super_token/fork )
82
86
  2. Create your feature branch (`git checkout -b my-new-feature`)
83
87
  3. Commit your changes (`git commit -am 'Add some feature'`)
84
88
  4. Push to the branch (`git push origin my-new-feature`)
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+ gemspec :path => '../'
3
+
4
+ group :development, :test do
5
+ gem 'activerecord', '~> 5.0.0.rc1'
6
+ end
@@ -1,4 +1,4 @@
1
- require 'securerandom'
1
+ # frozen_string_literal: true
2
2
 
3
3
  module SecureRandom
4
4
  BASE58_ALPHABET = ('0'..'9').to_a + ('A'..'Z').to_a + ('a'..'z').to_a - ['0', 'O', 'I', 'l']
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SuperToken
2
- VERSION = "1.0.0"
4
+ VERSION = "1.1.0"
3
5
  end
data/lib/super_token.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_record'
2
4
  module ActiveRecord
3
5
  module SecureToken
@@ -28,12 +30,12 @@ module ActiveRecord
28
30
  # You're encouraged to add a unique index in the database to deal with this even more unlikely scenario.
29
31
  def has_secure_token(attribute = :token, length: 24, prefix: '')
30
32
  # Load securerandom only when has_secure_token is used.
31
- require 'active_support/core_ext/securerandom'
32
- define_method("regenerate_#{attribute}") { update! attribute => self.class.generate_unique_secure_token(length, prefix) }
33
- before_create { self.send("#{attribute}=", self.class.generate_unique_secure_token(length, prefix)) unless self.send("#{attribute}?")}
33
+ require 'active_support/core_ext/securerandom' unless SecureRandom.respond_to?(:base58)
34
+ define_method("regenerate_#{attribute}") { update! attribute => self.class.generate_unique_secure_token_with_prefix(length, prefix) }
35
+ before_create { self.send("#{attribute}=", self.class.generate_unique_secure_token_with_prefix(length, prefix)) unless self.send("#{attribute}?")}
34
36
  end
35
37
 
36
- def generate_unique_secure_token(length, prefix)
38
+ def generate_unique_secure_token_with_prefix(length, prefix)
37
39
  token_length = length - prefix.length
38
40
  prefix + SecureRandom.base58(token_length)
39
41
  end
data/super_token.gemspec CHANGED
@@ -6,10 +6,10 @@ require 'super_token/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "super_token"
8
8
  spec.version = SuperToken::VERSION
9
- spec.authors = ["Roberto Miranda Altamar", "Abdulaziz Alshetwi"]
10
- spec.email = ["rjmaltamar@gmail.com", "e@ecleel.com"]
9
+ spec.authors = ["Abdulaziz Alshetwi", "Roberto Miranda Altamar"]
10
+ spec.email = ["e@ecleel.com", "rjmaltamar@gmail.com"]
11
11
  spec.summary = %q{HasSecureToken with more options}
12
- spec.description = %q{SecureToken provides you an easily way to geneatre uniques random tokens for any model in ruby on rails. **SecureRandom::base58** is used to generate the 24-character unique token, so collisions are highly unlikely.}
12
+ spec.description = %q{SuperToken provides you an easily way to geneatre uniques random tokens for any model in ruby on rails and gives you ability to add prefix of token and change length.}
13
13
  spec.homepage = "https://github.com/ecleel/super_token"
14
14
  spec.license = "MIT"
15
15
 
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency "activerecord", ">= 3.0"
22
22
 
23
- spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "bundler", "~> 2.2"
24
24
  spec.add_development_dependency "rake"
25
25
  spec.add_development_dependency "minitest"
26
26
  spec.add_development_dependency 'sqlite3'
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: super_token
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
- - Roberto Miranda Altamar
8
7
  - Abdulaziz Alshetwi
8
+ - Roberto Miranda Altamar
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-05-07 00:00:00.000000000 Z
12
+ date: 2022-01-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -31,14 +31,14 @@ dependencies:
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '1.3'
34
+ version: '2.2'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '1.3'
41
+ version: '2.2'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: rake
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -81,12 +81,12 @@ dependencies:
81
81
  - - ">="
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
- description: SecureToken provides you an easily way to geneatre uniques random tokens
85
- for any model in ruby on rails. **SecureRandom::base58** is used to generate the
86
- 24-character unique token, so collisions are highly unlikely.
84
+ description: SuperToken provides you an easily way to geneatre uniques random tokens
85
+ for any model in ruby on rails and gives you ability to add prefix of token and
86
+ change length.
87
87
  email:
88
- - rjmaltamar@gmail.com
89
88
  - e@ecleel.com
89
+ - rjmaltamar@gmail.com
90
90
  executables: []
91
91
  extensions: []
92
92
  extra_rdoc_files: []
@@ -101,6 +101,7 @@ files:
101
101
  - gemfiles/rails4_0.gemfile
102
102
  - gemfiles/rails4_1.gemfile
103
103
  - gemfiles/rails4_2.gemfile
104
+ - gemfiles/rails5_0.gemfile
104
105
  - lib/active_support/core_ext/securerandom.rb
105
106
  - lib/super_token.rb
106
107
  - lib/super_token/version.rb
@@ -129,8 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
130
  - !ruby/object:Gem::Version
130
131
  version: '0'
131
132
  requirements: []
132
- rubyforge_project:
133
- rubygems_version: 2.4.5.1
133
+ rubygems_version: 3.1.6
134
134
  signing_key:
135
135
  specification_version: 4
136
136
  summary: HasSecureToken with more options