Sha256: a580e9ba040e2c0d981860b1d197ac26c4130da9d3b58b404d82c941524816ec

Contents?: true

Size: 529 Bytes

Versions: 2

Compression:

Stored size: 529 Bytes

Contents

# Ensures a token is generated
#
# class User < ActiveRecord::Base
#   include SimpleTokenAuth::TokenAuthenticatable
# end
#
module SimpleTokenAuth
  module TokenAuthenticatable
    extend ActiveSupport::Concern

    included do
      before_save :ensure_api_key

      has_one :api_key, as: :token_authenticatable
    end

    def auth_token
      api_key.access_token
    end

    def renew_api_key
      api_key.renew!
    end

    private

    def ensure_api_key
      build_api_key unless api_key.present?
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
simple_token_auth-0.0.4 lib/simple_token_auth/token_authenticatable.rb
simple_token_auth-0.0.3 lib/simple_token_auth/token_authenticatable.rb