5 Commits
1039d66c73
...
1e546aa417
Author | SHA1 | Message | Date |
---|---|---|---|
Yessiest | 1e546aa417 |
JWT cookies
|
3 months ago |
Yessiest | dce0937e2e |
bumped version
|
6 months ago |
Yessiest | eb7e44a537 |
removed an oopsie
|
6 months ago |
Yessiest | 59aa1206ff |
Added more methods to process various types of post forms
|
6 months ago |
Yessiest | 9030b5ef05 |
Modified guidelines, bumped version in library
|
6 months ago |
12 changed files with 186 additions and 50 deletions
-
1.gitignore
-
5HACKING.md
-
55LAYOUT.md
-
BINexamples/uploader/files/lab5.zip
-
2landline.gemspec
-
5lib/landline.rb
-
13lib/landline/dsl/methods_path.rb
-
62lib/landline/dsl/methods_probe.rb
-
2lib/landline/request.rb
-
13lib/landline/util/cookie.rb
-
54lib/landline/util/jwt.rb
-
24lib/landline/util/parseutils.rb
@ -1,3 +1,4 @@ |
|||
/*.gem |
|||
/doc |
|||
/.yardoc |
|||
/examples/uploader/files/* |
@ -0,0 +1,54 @@ |
|||
# frozen_string_literal: true |
|||
|
|||
require 'openssl' |
|||
require 'json' |
|||
require 'base64' |
|||
|
|||
if RUBY_ENGINE == 'jruby' # fix for JRuby |
|||
OpenSSL::HMAC.define_singleton_method(:base64digest) do |*args| |
|||
Base64.strict_encode64(OpenSSL::HMAC.digest(*args)).strip |
|||
end |
|||
end |
|||
|
|||
module Landline |
|||
module Util |
|||
# JSON Web Token construction class |
|||
class JWT |
|||
# Create a new JWT token wrapper |
|||
# @param data [Hash, Array] JSON-formattable data |
|||
# @param halgo [String] Name of the hash algorithm to use |
|||
def initialize(data, halgo = "SHA256") |
|||
@halgo = halgo |
|||
@data = data |
|||
end |
|||
|
|||
# Construct a string representation of the current token |
|||
# @param key [String] |
|||
# @return [String] |
|||
def make(key) |
|||
jsondata = @data.to_json |
|||
[ |
|||
{ |
|||
"hash" => @halgo |
|||
}.to_json, |
|||
jsondata, |
|||
OpenSSL::HMAC.digest(@halgo, key, jsondata) |
|||
].map(&Base64.method(:strict_encode64)).map(&:strip).join "&" |
|||
end |
|||
|
|||
# Construct an object from string |
|||
# @param input [String] |
|||
# @param key [String] |
|||
# @return [JWT, nil] returns nil if verification couldn't complete |
|||
def self.from_string(input, key) |
|||
halgoj, dataj, sig = input.split("&").map(&Base64.method(:strict_decode64)) |
|||
halgo = JSON.parse(halgoj)["hash"] |
|||
return nil if OpenSSL::HMAC.digest(halgo, key, dataj) != sig |
|||
|
|||
new(JSON.parse(dataj), halgo) |
|||
end |
|||
|
|||
attr_accessor :data |
|||
end |
|||
end |
|||
end |
Write
Preview
Loading…
Cancel
Save
Reference in new issue