vonage-jwt 0.1.3 → 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: 4e64f9df01478c092cf5f950c5fb61d56227a558cba788a693cffad050ed5a66
4
- data.tar.gz: f72bd42ca910f5f6df52781eeb3d8d1ca658c261833bbe5ab68b3ef8f2571014
3
+ metadata.gz: ddf304ba0c31efdaf0da2618355b23f5800cb7dd07ed2d19d613e624bd577131
4
+ data.tar.gz: 1786f96a4dfcad228ee5b6583b0db99806cc545206f5db6eff4832c4fd702ad8
5
5
  SHA512:
6
- metadata.gz: e0fb624c08c1c06db4def2a97b50a10add0392f89f6279de7c5b70c987881f510720202b6b84a3d9365a61b32f43fb3783ed30aa95a31a5adc7d1bf08dcf5444
7
- data.tar.gz: faa02b4e295b2a850191a956dbbe526c7feb498e3a51cd4ada6d9d66823036846e418092b06bf020e8cb7474bfa1f886a4fa47b30e2e746276ce49f62a9b6c43
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
@@ -29,5 +29,18 @@ module Vonage
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Vonage
4
4
  class JWT
5
- VERSION = '0.1.3'
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.3
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: 2023-08-08 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