vonage-jwt 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e83f93abf55574d8da1dc73a55e89a17597275911927a9200b3e51be71655e3f
4
- data.tar.gz: 4772db0876bc1129f2f038d1ee3d235852e763a8b9f7bf457acdb823acefafc7
3
+ metadata.gz: ddf304ba0c31efdaf0da2618355b23f5800cb7dd07ed2d19d613e624bd577131
4
+ data.tar.gz: 1786f96a4dfcad228ee5b6583b0db99806cc545206f5db6eff4832c4fd702ad8
5
5
  SHA512:
6
- metadata.gz: ee524f8242fe11c48d7ca420bf7d57115f88c6ff0fad19c1b4bd85163ca132b6b7b0e147138e16977ed5ded7c0b89b10291b805f2627e75fcef3e92150ae002c
7
- data.tar.gz: e5f64c2947797813e9c450d71f7a9a16fed6f22c515521f026607de0ce7d34807f0e933674c8e035b3301f57c86f023e16a4ae5f92c179bbbca6441cf70c2185
6
+ metadata.gz: a2ff24275b3b26cb6c47ab9b50c8279ceef69286d1628919f062c29356f936bf35552cf06371727073dfcd959fb699f79b4fa3cdd94e0f7353bca372d945c24e
7
+ data.tar.gz: eea38e2c24d80c04b75e1ff293ff3110743224cd948f2016c5b6640db7ec4ab7ee5a488e09e1f382e45dd4e69086177ab6359def24e6dc9f6c76eb063f75e630
data/README.md CHANGED
@@ -27,9 +27,11 @@ Alternatively you can clone the repository:
27
27
 
28
28
  ## Usage
29
29
 
30
+ ### Generating a JWT
31
+
30
32
  By default the Vonage JWT generator creates a short lived JWT (15 minutes) per request.
31
33
  To generate a long lived JWT for multiple requests, specify a longer value in the `exp`
32
- parameter during initialization.
34
+ parameter during initialization.
33
35
 
34
36
  Example with no custom configuration:
35
37
 
@@ -51,10 +53,10 @@ Example providing custom configuration options:
51
53
  "/messages": {
52
54
  "methods": ["POST", "GET"],
53
55
  "filters": {
54
- "from": "447977271009"
55
- }
56
- }
57
- }
56
+ "from": "447977271009"
57
+ }
58
+ }
59
+ }
58
60
  }
59
61
  },
60
62
  subject: 'My_Custom_Subject'
@@ -62,6 +64,28 @@ Example providing custom configuration options:
62
64
  @token = @builder.jwt.generate
63
65
  ```
64
66
 
67
+ ### Decoding a JWT
68
+
69
+ You can decode a JWT like so:
70
+
71
+ ```ruby
72
+ Vonage::JWT.decode(token, nil, false)
73
+ ```
74
+
75
+ where `token` is the JWT that you want to decode. The `Vonage::JWT::decode` method is essentially just a wrapper around the `ruby-jwt` library method of the same name, and usage is identical to what is [documented for that library](https://github.com/jwt/ruby-jwt#algorithms-and-usage).
76
+
77
+ ### Verifying a Signature
78
+
79
+ For JWTs that are signed, you can verify a JWT signature like so:
80
+
81
+ ```ruby
82
+ Vonage::JWT.verify_signature(token, signature_secret, algorithm)
83
+ ```
84
+
85
+ where `token` is the signed JWT, `signature_secret` is the secret or key required by whichever algorithm was used to sign the JWT, and `algorithm` is a string indicating the algorithm that was used to sign the JWT (e.g. `'HS256'`, `'RS256'`, etc)
86
+
87
+ The method will return `true` if the signature is verified and `false` if it is not.
88
+
65
89
  ## Documentation
66
90
 
67
91
  Vonage Ruby JWT documentation: https://www.rubydoc.info/github/Vonage/vonage-jwt
@@ -21,13 +21,26 @@ module Vonage
21
21
  iat: iat,
22
22
  jti: generator.jti,
23
23
  exp: generator.exp || iat + generator.ttl,
24
- sub: generator.subject,
25
24
  application_id: generator.application_id
26
25
  }
27
26
  hash.merge!(generator.paths) if generator.paths
27
+ hash.merge!(sub: generator.subject) if generator.subject
28
28
  hash.merge!(nbf: generator.nbf) if generator.nbf
29
29
  hash.merge!(generator.additional_claims) if !generator.additional_claims.empty?
30
30
  hash
31
31
  end
32
+
33
+ def self.decode(token, secret = nil, verify = true, opts = {}, &block)
34
+ ::JWT.decode(token, secret, verify, opts, &block)
35
+ end
36
+
37
+ def self.verify_signature(token, signature_secret, algorithm)
38
+ begin
39
+ decode(token, signature_secret, true, {algorithm: algorithm})
40
+ return true
41
+ rescue ::JWT::VerificationError
42
+ return false
43
+ end
44
+ end
32
45
  end
33
46
  end
@@ -54,7 +54,7 @@ module Vonage
54
54
  @exp = params.fetch(:exp, nil)
55
55
  @alg = params.fetch(:alg, 'RS256')
56
56
  @paths = params.fetch(:paths, nil)
57
- @subject = params.fetch(:subject, 'Subject')
57
+ @subject = params.fetch(:subject, nil)
58
58
  @additional_claims = set_additional_claims(params)
59
59
  @jwt = Vonage::JWT.new(generator: self)
60
60
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Vonage
4
4
  class JWT
5
- VERSION = '0.1.2'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vonage-jwt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vonage
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-28 00:00:00.000000000 Z
11
+ date: 2023-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt