module GrapeTokenAuth::LookupToken::ClassMethods
Public Instance Methods
digest(column, value)
click to toggle source
# File lib/grape_token_auth/lookup_token.rb, line 27 def digest(column, value) return unless value.present? key = key_for(column) OpenSSL::HMAC.hexdigest(open_ssl_digest, key, value) end
friendly_token(length = 20)
click to toggle source
copied from devise, creates a token that is url safe without ambigous characters
# File lib/grape_token_auth/lookup_token.rb, line 12 def friendly_token(length = 20) rlength = (length * 3) / 4 SecureRandom.urlsafe_base64(rlength).tr('lIO0', 'sxyz') end
generate(authenticatable_klass, column)
click to toggle source
# File lib/grape_token_auth/lookup_token.rb, line 17 def generate(authenticatable_klass, column) loop do raw = friendly_token enc = digest(column, raw) unless authenticatable_klass.exists_in_column?(column, enc) break [raw, enc] end end end
open_ssl_digest()
click to toggle source
# File lib/grape_token_auth/lookup_token.rb, line 33 def open_ssl_digest GrapeTokenAuth.configuration.digest end
Private Instance Methods
key_for(column)
click to toggle source
# File lib/grape_token_auth/lookup_token.rb, line 39 def key_for(column) GrapeTokenAuth.configuration.key_generator .generate_key("GTA column #{column}") end