passwordless 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 717a5f675e50cbb57b59ee2138833bd2847dd71c
4
- data.tar.gz: 2487b137a19da048afaabc061f648a7aee659e62
3
+ metadata.gz: b5a2a15ba36dbcd13fb11898d26ed934083be8ba
4
+ data.tar.gz: e66f31f5dd29b2a6ff0813863a8af864e2db59a1
5
5
  SHA512:
6
- metadata.gz: b72b379c9acd55088adabd5f0a0bad5a42f24c1e55c600896e6284e8ff54b1f9e21c0111037c7d112c6bf5df6bdc3c1bed43298e0d6e8c1495a9af8c573a0753
7
- data.tar.gz: 6234dd6216fd0fecd79860b3d3277460a665001e657656c3023dae4a1ea72ae1619750e27e6fde6115e39d5d1ecec712155271effa3a7da7e0595efcf6ae4745
6
+ metadata.gz: 1a1665bf6d15e0b7b8ae88666c8ad6cb50c2032d57ae0aea3a640c32cb5d4c4b9e3e7bc825aaa92c1cda144218ce0c95dd71befb9275b4424ca9bd6cf4ecc636
7
+ data.tar.gz: 1d65cedeada62b9842afabd70d8bd51e56c30a11039f79c3eda668e1cdf2b330cfc8a6dba012e2cc2439d7423804f9c8fd79e5fdbb62cf75ee1b53b1e35928e1
data/README.md CHANGED
@@ -74,6 +74,18 @@ class ApplicationController < ActionController::Base
74
74
  end
75
75
  ```
76
76
 
77
+ Et voilá:
78
+
79
+ ```ruby
80
+ class VerySecretThingsController < ApplicationController
81
+ before_filter :require_user!
82
+
83
+ def index
84
+ @things = current_user.very_secret_things
85
+ end
86
+ end
87
+ ```
88
+
77
89
  ## Providing your own templates
78
90
 
79
91
  Override `passwordless`' bundled views by adding your own. `passwordless` has 2 action views and 1 mailer view:
@@ -113,18 +125,18 @@ class UsersController < ApplicationController
113
125
  end
114
126
  ```
115
127
 
116
- Et voilá:
128
+ ## Generating tokens
129
+
130
+ By default Passwordless generates tokens using Rails' `SecureRandom.urlsafe_base64` but you can change that by setting `Passwordless.token_generator` to something else that responds to `call(session)` eg.:
117
131
 
118
132
  ```ruby
119
- class VerySecretThingsController < ApplicationController
120
- before_filter :require_user!
121
-
122
- def index
123
- @things = current_user.very_secret_things
124
- end
125
- end
133
+ Passwordless.token_generator = -> (session) {
134
+ "probably-stupid-token-#{session.user_agent}-#{Time.current}"
135
+ }
126
136
  ```
127
137
 
138
+ Session is going to keep generating tokens until it finds one that hasn't been used yet. So be sure to use some kind of method where matches are unlikely.
139
+
128
140
  # License
129
141
 
130
142
  MIT
@@ -22,7 +22,7 @@ module Passwordless
22
22
  self.expires_at ||= 1.year.from_now
23
23
  self.timeout_at ||= 1.hour.from_now
24
24
  self.token ||= loop do
25
- token = SecureRandom.urlsafe_base64(32)
25
+ token = Passwordless.token_generator.call(self)
26
26
  break token unless Session.find_by(token: token)
27
27
  end
28
28
  end
@@ -1,5 +1,9 @@
1
- require "passwordless/engine"
1
+ require 'passwordless/engine'
2
+ require 'passwordless/url_safe_base_64_generator'
2
3
 
3
4
  module Passwordless
4
5
  mattr_accessor(:default_from_address) { 'CHANGE_ME@example.com' }
6
+ mattr_accessor(:token_generator) do
7
+ UrlSafeBase64Generator.new
8
+ end
5
9
  end
@@ -0,0 +1,7 @@
1
+ module Passwordless
2
+ class UrlSafeBase64Generator
3
+ def call(_session)
4
+ SecureRandom.urlsafe_base64(32)
5
+ end
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module Passwordless
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: passwordless
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikkel Malmberg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-07 00:00:00.000000000 Z
11
+ date: 2017-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -77,6 +77,7 @@ files:
77
77
  - lib/passwordless/engine.rb
78
78
  - lib/passwordless/model_helpers.rb
79
79
  - lib/passwordless/router_helpers.rb
80
+ - lib/passwordless/url_safe_base_64_generator.rb
80
81
  - lib/passwordless/version.rb
81
82
  - lib/tasks/passwordless_tasks.rake
82
83
  homepage: https://github.com/mikker/passwordless