Sha256: 6dc90339a9613ab1c4d3c41695b70fd5d6fb06ce82a3d58a994c2b0563afa7fc

Contents?: true

Size: 703 Bytes

Versions: 1

Compression:

Stored size: 703 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)
            end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
devise_token_authenticatable-0.1.0 lib/devise_token_authenticatable/controllers/token_authenticatable.rb