api_pack 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1108b79f1495ff944ba4298731ec0c68e030d73d6ecbd031120d312c14620759
4
- data.tar.gz: e56c3cbe722219a0c79307bc964f265aff47fcb6f2f63a46fc211752bb7363cb
3
+ metadata.gz: a3e5a209e75518cbb866df889a9c586fee08e49ab6692182b7634a2beb153d11
4
+ data.tar.gz: df9688d637efbdc1f4e6f2730c88308c68c27a4ee8027cc988463ced75d3e795
5
5
  SHA512:
6
- metadata.gz: 77a5de40fb986ba63ee7b44be5d310ddda4660518843ee1ff9afa3ec2dda22f70e2b0916f2197496b4b1e7b4964860569882866042f6da57e28df6382d217048
7
- data.tar.gz: 5ac7a7d1b8ca6ce1d6069ca1bc3bbcd390e02107678c526835d0da88bbecaad9831610f1caf0f610206a99987676ccbc21f3e65b60d4ebf0504ea442df548620
6
+ metadata.gz: 33bd54ceff27599a5a6ba1c52509bfba9b64d429f22883556df6e9faf097f99b58ce024b8d0fe625552ccbca112cf5d417a0125cd024252920227ff2f7d276b3
7
+ data.tar.gz: 9812e4e582a845e83b11faf83870d3cea76883569f00cc6d059e3de5e9560b21eb70af345a92db1c757455a846fb2259b66d49a9e0b7f050aa6304aed5d06d5c
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
- [![Build Status](https://travis-ci.org/Jllima/api_pack.svg?branch=master)](https://travis-ci.org/Jllima/api_pack)
1
+ [![Gem Version](https://badge.fury.io/rb/api_pack.svg)](https://badge.fury.io/rb/api_pack)
2
+ [![Build Status](https://www.travis-ci.com/Jllima/api_pack.svg?branch=master)](https://www.travis-ci.com/Jllima/api_pack)
2
3
  [![Coverage Status](https://coveralls.io/repos/github/Jllima/api_pack/badge.svg?branch=master)](https://coveralls.io/github/Jllima/api_pack?branch=master)
3
4
 
4
5
  # ApiPack
@@ -23,7 +24,7 @@ ruby >= 2.4
23
24
  Add this line to your application's Gemfile:
24
25
 
25
26
  ```ruby
26
- gem 'api_pack'
27
+ gem 'api_pack', '~> 1.1.2'
27
28
  ```
28
29
 
29
30
  And then execute:
@@ -37,7 +38,12 @@ Or install it yourself as:
37
38
  ## Usage
38
39
 
39
40
  ### JsonWebToken methods
40
-
41
+ - First create file api_pack.rb in initializers in put this code
42
+ ```ruby
43
+ Rails.application.config.to_prepare do
44
+ ApiPack.hmac_secret = 'your_secret_key'
45
+ end
46
+ ```
41
47
  - ApiPack::JsonWebToken.encode({ user_id: user.id }) \
42
48
  returns a valid token with an expiration time of one day
43
49
  - To change o expiration create an initializer api_pack and put this code
@@ -195,6 +201,11 @@ def index
195
201
  end
196
202
  ```
197
203
 
204
+ ## This example project uses gem api_apck
205
+
206
+ https://github.com/Jllima/api_pack_rails
207
+
208
+
198
209
  ## Contributing
199
210
 
200
211
  Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/api_pack.
data/lib/api_pack.rb CHANGED
@@ -10,7 +10,6 @@ require 'api_pack/errors/handle_error'
10
10
  require 'api_pack/errors/api_errors_serializer'
11
11
  require 'api_pack/errors/validation_error_serializer'
12
12
  require 'api_pack/errors/validation_errors_serializer'
13
- require 'api_pack/constants'
14
13
  require 'api_pack/support/helper'
15
14
  require 'api_pack/serializer/parser'
16
15
 
@@ -38,6 +37,14 @@ module ApiPack
38
37
  @exp ||= DEFAULT_EXP
39
38
  end
40
39
 
40
+ def hmac_secret=(value)
41
+ @hmac_secret = value
42
+ end
43
+
44
+ def hmac_secret
45
+ @hmac_secret
46
+ end
47
+
41
48
  def serializer_adapter=(adapter)
42
49
  ApiPack::Serializer::Parser.adapter = adapter
43
50
  end
@@ -4,6 +4,7 @@ module ApiPack
4
4
  class AuthenticationError < StandardError; end
5
5
  class InvalidToken < StandardError; end
6
6
  class MissingToken < StandardError; end
7
+ class MissingHmacSecret < StandardError; end
7
8
  end
8
9
  end
9
10
  end
@@ -1,13 +1,17 @@
1
1
  module ApiPack
2
2
  class JsonWebToken
3
3
  def self.encode(payload, exp: ApiPack.exp)
4
+ raise ApiPack::Errors::Auth::MissingHmacSecret if ApiPack.hmac_secret.nil?
5
+
4
6
  payload[:exp] = exp.to_i
5
7
 
6
- JWT.encode(payload, ApiPack::HMAC_SECRET)
8
+ JWT.encode(payload, ApiPack.hmac_secret)
9
+ rescue ApiPack::Errors::Auth::MissingHmacSecret
10
+ raise ApiPack::Errors::Auth::MissingHmacSecret, 'ApiPach.hmac_secret is missing'
7
11
  end
8
12
 
9
13
  def self.decode(token)
10
- JWT.decode(token, ApiPack::HMAC_SECRET).first
14
+ JWT.decode(token, ApiPack.hmac_secret).first
11
15
  rescue JWT::DecodeError => e
12
16
  raise ApiPack::Errors::Auth::InvalidToken, e.message
13
17
  end
@@ -1,3 +1,3 @@
1
1
  module ApiPack
2
- VERSION = '1.1.1'.freeze
2
+ VERSION = '1.1.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_pack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jorge
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-20 00:00:00.000000000 Z
11
+ date: 2021-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -61,7 +61,6 @@ files:
61
61
  - bin/setup
62
62
  - lib/api_pack.rb
63
63
  - lib/api_pack/api_helper.rb
64
- - lib/api_pack/constants.rb
65
64
  - lib/api_pack/errors/api_errors_serializer.rb
66
65
  - lib/api_pack/errors/auth.rb
67
66
  - lib/api_pack/errors/error_map.rb
@@ -1,3 +0,0 @@
1
- module ApiPack
2
- HMAC_SECRET = '2e484b352b985259601a5f2f2c1712b31d63136bf22d9213303a5b501942723827508038484b9da1ead77a7788799c55e05785f2f148e53d943e6dedf635a291'.freeze
3
- end