Skip to content

Commit

Permalink
Merge pull request #2 from velu-dev/dev
Browse files Browse the repository at this point in the history
gemscpec changes and add some features in token
  • Loading branch information
velu-dev authored May 25, 2018
2 parents 83614dc + f230a25 commit 5fccd3e
Show file tree
Hide file tree
Showing 9 changed files with 230 additions and 1 deletion.
104 changes: 104 additions & 0 deletions .byebug_history
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
c
decoded_token.present?
decoded_token.present
decoded_token
c
cc
c
decoded_token
c
decoded_token
c
exit
decoded_token
decode_token
c
rescue JWT::ImmatureSignature
rescue JWT::ExpiredSignature
decoded_token = JWT.decode token, nil, false
c
Kernel.const_get(gfd)
Kernel.const_get()
Kernel.const_get("fdgfd")
Kernel.const_get(@model)
Kernel.const_get(@model).find(@data['userid'].to_i)
user = Kernel.const_get(@model).find(@data['userid'].to_i)
time = @data['time'].to_time+ 1.hour > Time.now
c
decoded_token = JWT.decode token, nil, false
@model = model
model
token
exit
Kernel.const_get(classname)
Kernel.const_get(classname).methods
classname = 'Integer'
eval classname + '.methods'
classname = 'Integer'
Model(@data['userid'])
@data['userid']
@data['userid'].capitalize!
@data['userid']
@data['userid'].capitalize!
@data['userid']
@data['userid'].capitalize!
@data['userid'].capitalize!.new
@data['userid'].capitalize!
@data['userid'].Capitalize
@data['userid'].Capitalize!
@data['userid']
@data
@data['time'].to_time+ 1.hour > Time.now
@data['time'].to_time > Time.now
@data['time'].to_time
@data['time']
@data
c
@data = decoded_token[0]['data']
decoded_token = JWT.decode token, nil, false
c
exit
decoded_token = JWT.decode @token, nil, false
token
tokken
c
@token
c
@token
c
@data['userid']
@data.userid
@data
exit
@data['data']
@data
@data'
exit
@data[0]['data']['userid']
@data[0]['data'].userid
@data[0]['data']
@data[0]
@data[0].data
@data[0].dats
@data[0].date
@data[0]
@data
exit
Time.now.to_s
Time.now.to_s.to_i
Time.now.to_s.to_time
Time.now.to_s
Time.now
Date.today + "g"
Date.today
Date.today.to_s.split("-").join("")
Date(Date.today.to_s.split("-").join(""))
Date.today.to_s.split("-").join("").to_date
Date.today.to_s.split("-").join("")
Date.today.to_s.split("-")
Date.today.to_s.split("")
Date.today.to_s
Date.today.to_a
Date.today.to_s
Date.today
@date
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem 'bcrypt', '~> 3.1', '>= 3.1.11'
gem 'bcrypt', '~> 3.1', '>= 3.1.11'
gem 'jwt'
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ GEM
remote: https://rubygems.org/
specs:
bcrypt (3.1.12)
jwt (2.1.0)

PLATFORMS
ruby

DEPENDENCIES
bcrypt (~> 3.1, >= 3.1.11)
jwt

BUNDLED WITH
1.16.2
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,30 @@
# Web Token Gem for simplification of JWT

## Step 1
gem install webtoken

## Step 2

require 'webtoken'
## Step 3

data = WebToken::MakeToken.new( user_id )

data.web_token

### Response

#sample = {"eyJhbGciOiJub25lIn0.eyJkYXRhIjp7InVzZXJpZCI6ImpodiIsImRhdGUiOiIyMDE4LTA1LTI1IiwidGltZSI6IjIwMTgtMDUtMjUgMTI6Mzk6MzIgKzA1MzAifX0."}


## Step 3

validate_token = WebToken::WebtokenValidate.new

validate_token.validate( 'your token' )

### Response
{"userid" : "userid", date: "date", time: "time"} #access token valid

false #access token invalid
31 changes: 31 additions & 0 deletions lib/token/web_token_gen.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require 'active_support'
require 'active_support/all'
require 'fnv'
require 'byebug'
require 'bcrypt'
require 'jwt'
require "date"
module WebToken
class MakeToken
def initialize( user_id )
data = {
userid: user_id,
date: Date.today.to_s,
time: Time.now
}
payload = {:data => data}
@token = JWT.encode payload, nil, 'none'
# decoded_token = JWT.decode @token, nil, false
# @data = decoded_token[0]['data']
end
def web_token
@token
end
# def data
# @data
# end

end
end


41 changes: 41 additions & 0 deletions lib/validation/token_validate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require 'byebug'
require 'bcrypt'
require 'jwt'
require "date"

module WebToken

class WebtokenValidate
# def initialize( token, model )

# end
def validate( token )
begin
decoded_token = JWT.decode token, nil, false
rescue JWT::ExpiredSignature
rescue JWT::ImmatureSignature
rescue JWT::DecodeError

end
if decoded_token.present?
@data = decoded_token[0]['data']
time = @data['time'].to_time+ 1.hour > Time.now
if time
@data
else
false
end
else
false
end

# user = Kernel.const_get(@model).find(@data['userid'].to_i)
# if user.present? && time
# user
# else
# return false
# end
end

end
end
Empty file removed lib/web_token.rb
Empty file.
5 changes: 5 additions & 0 deletions lib/webtoken.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'active_support'
require 'active_support/all'
require 'fnv'
require './lib/token/web_token_gen'
require './lib/validation/token_validate'
16 changes: 16 additions & 0 deletions web_token.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
lib = File.expand_path( '../lib/', __FILE__ )
$LOAD_PATH.unshift( lib ) unless $LOAD_PATH.include?( lib )

Gem::Specification.new do |s|
s.name = 'webtoken'
s.version = '0.0.1'
s.date = '2010-05-25'
s.summary = "WebToken"
s.description = "Simplify web token using JWT"
s.authors = ["velusamy Venkatraman"]
s.email = '[email protected],'
s.files = ["lib/webtoken.rb"]
# s.require_paths = [ "lib" ]
s.homepage =''
s.license = 'MIT'
end

0 comments on commit 5fccd3e

Please sign in to comment.