jot-helpers 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5dcde07a6ba725c5951e5d4ab452ffb1e7cd671a447cf0cdc0c42594c36f1627
4
+ data.tar.gz: 8fadc144567b415ae381ce4b412f4f2a2a4649f3ac75d232e6778047a5093185
5
+ SHA512:
6
+ metadata.gz: b8bddc2c27c5edc08e629a500a36f32843e58e7550fcd4503d94b6e15aae56709a85df0b5faf426d9e7cb0460a0fbe213d306c2887d2eb96e1025150ed3611ab
7
+ data.tar.gz: f2b30a100261522e6e39f3aff5977cde6576ca4bcdda7459e7cdd38810f709cdcd05a569371364c2ed20f747f1ba316747c28459c5b57e9ac0adceaf63c0ce8e
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # Jot
2
+
3
+ A light wrapper around the [JWT gem](https://github.com/jwt/ruby-jwt).
4
+
5
+ ## Setup
6
+
7
+ Configure the gem:
8
+
9
+ ```ruby
10
+ Jot.configure do |config|
11
+ config.algorithm = "HS256"
12
+ config.secret = # Something long and complex, such as a value generated by SecureRandom.hex(32)
13
+ end
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ Encode a payload:
19
+
20
+ ```ruby
21
+ JOT.encode({ user_id: 1 }) # => "eyJhbGciOiJIUz..."
22
+ ```
23
+
24
+ Decode a payload:
25
+
26
+ ```ruby
27
+ JOT.decode("eyJhbGciOiJIUz...") # => { "user_id" => 1 }
28
+ ```
29
+
30
+ Exceptions raised for invalid / expired tokens will be the same as those raised by the JWT gem.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
@@ -0,0 +1,7 @@
1
+ class Jot
2
+ class Configuration
3
+ attr_accessor :algorithm, :secret
4
+
5
+
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ class Jot
2
+ module Rails
3
+ module AuthenticationHelper
4
+ def jot_decode(request)
5
+ token = request.headers["Authorization"].split(" ").last
6
+ payload, header = Jot.decode(token)
7
+ payload
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Jot
4
+ VERSION = "1.0.0.beta1"
5
+ end
data/lib/jot.rb ADDED
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "jwt"
4
+ require_relative "jot/version"
5
+ require_relative "jot/configuration"
6
+ require_relative "jot/rails/authentication_helper"
7
+
8
+ class Jot
9
+ class << self
10
+ attr_reader :config
11
+ end
12
+
13
+ def self.configure(&block)
14
+ @config = Configuration.new
15
+ block.call(@config)
16
+ end
17
+
18
+ def self.encode(payload)
19
+ JWT.encode(payload, config.secret, config.algorithm)
20
+ end
21
+
22
+ def self.decode(payload, verify: true)
23
+ JWT.decode(payload, config.secret, verify, { algorithm: config.algorithm })
24
+ end
25
+ end
data/sig/jot.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Jot
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jot-helpers
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.beta1
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Bigg
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-07-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jwt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ description: Provides helper methods for working with JSON Web Tokens (JWTs)
42
+ email:
43
+ - me@ryanbigg.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".rspec"
49
+ - README.md
50
+ - Rakefile
51
+ - lib/jot.rb
52
+ - lib/jot/configuration.rb
53
+ - lib/jot/rails/authentication_helper.rb
54
+ - lib/jot/version.rb
55
+ - sig/jot.rbs
56
+ homepage: https://github.com/radar/jwt
57
+ licenses: []
58
+ metadata:
59
+ homepage_uri: https://github.com/radar/jwt
60
+ source_code_uri: https://github.com/radar/jwt
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 2.6.0
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">"
73
+ - !ruby/object:Gem::Version
74
+ version: 1.3.1
75
+ requirements: []
76
+ rubygems_version: 3.3.16
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: Provides helper methods for working with JSON Web Tokens (JWTs)
80
+ test_files: []