Sha256: 104ec5557b0f66aec7664d7b4986c2f6e40c3afb782ca9886cf70bedb9b52779

Contents?: true

Size: 722 Bytes

Versions: 4

Compression:

Stored size: 722 Bytes

Contents

require 'jwt'

module Devise
  module Controllers
    module TokenAuthenticatable
      extend ActiveSupport::Concern

      included do
        Devise.mappings.keys.each do |mapping|
          class_eval <<-METHODS, __FILE__, __LINE__ + 1
            def set_#{mapping}_access_token!
              return unless #{mapping}_signed_in?
              response.set_header("X-#{mapping.to_s.split('_').map(&:capitalize).join('-')}-Token", current_#{mapping}.access_token(request.remote_ip))
            end

            def token_authenticate_#{mapping}!(opts={})
              authenticate_#{mapping}!(opts)
              set_#{mapping}_access_token!
            end
          METHODS
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
devise_token_authenticatable-0.1.4 lib/devise_token_authenticatable/controllers/token_authenticatable.rb
devise_token_authenticatable-0.1.3 lib/devise_token_authenticatable/controllers/token_authenticatable.rb
devise_token_authenticatable-0.1.2 lib/devise_token_authenticatable/controllers/token_authenticatable.rb
devise_token_authenticatable-0.1.1 lib/devise_token_authenticatable/controllers/token_authenticatable.rb