yonder_sdk 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b832af7298e6689a96053c1175fc41d79397d6d38f64758e9f77100eb5ed5e77
4
+ data.tar.gz: aecdf34656f673b6d1213034b262cdffd7b7c9582d98a45841df2b962bc3f9b9
5
+ SHA512:
6
+ metadata.gz: e471d672ebb34efbd1a0706595d323751af96488acc43de70687a4af21df2895cec6d62805b9025adf2e181a45ac65bcecb1f62f6152b63834a2f1e92ea2538c
7
+ data.tar.gz: 18f841cf2b819748af5ef751e861c2633a472bd3efcd48e22715bcf0117d00816cd0ec696168b2fa378156547e4604fac6981b2def52d1db597002e2d577a96f
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "jwt"
4
+ require "openssl"
5
+
6
+ module YonderSdk
7
+ class AccessToken
8
+ def self.from_authorization_header(header)
9
+ return nil if header.nil? || header.empty?
10
+
11
+ scheme, token = header.split(" ", 2)
12
+ return nil unless scheme&.downcase == "bearer" && token && !token.empty?
13
+
14
+ new(token)
15
+ end
16
+
17
+ def initialize(token)
18
+ @token = JWT::EncodedToken.new(token)
19
+ @payload = {}
20
+ @valid = check_validity
21
+ freeze
22
+ end
23
+
24
+ def valid?
25
+ @valid == :valid
26
+ end
27
+
28
+ def validation
29
+ @valid
30
+ end
31
+
32
+ def payload
33
+ valid? ? @payload : {}
34
+ end
35
+
36
+ private
37
+
38
+ def check_validity
39
+ return :not_configured unless configured?
40
+
41
+ payload, _header = JWT.decode(
42
+ @token.jwt,
43
+ OpenSSL::PKey::RSA.new(YonderSdk.configuration.public_signing_key),
44
+ true,
45
+ {
46
+ algorithm: "RS256",
47
+ iss: YonderSdk.configuration.issuer,
48
+ verify_iss: true,
49
+ verify_expiration: true,
50
+ leeway: 30
51
+ }
52
+ )
53
+
54
+ @payload = payload
55
+ :valid
56
+ rescue JWT::DecodeError, JWT::Base64DecodeError
57
+ :invalid_token
58
+ rescue JWT::ExpiredSignature
59
+ :expired_token
60
+ end
61
+
62
+ def configured?
63
+ YonderSdk.configuration.public_signing_key && YonderSdk.configuration.issuer
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YonderSdk
4
+ class Configuration
5
+ attr_accessor :issuer, :public_signing_key
6
+
7
+ def initialize
8
+ @public_signing_key = nil
9
+ @issuer = nil
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YonderSdk
4
+ VERSION = "0.0.1"
5
+ end
data/lib/yonder_sdk.rb ADDED
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yonder_sdk/configuration"
4
+ require "yonder_sdk/access_token"
5
+ require "yonder_sdk/version"
6
+
7
+ module YonderSdk
8
+ class << self
9
+ # Instantiate the Configuration singleton
10
+ # or return it. Remember that the instance
11
+ # has attribute readers so that we can access
12
+ # the configured values
13
+ def configuration
14
+ @configuration ||= Configuration.new
15
+ end
16
+
17
+ # This is the configure block definition.
18
+ # The configuration method will return the
19
+ # Configuration singleton, which is then yielded
20
+ # to the configure block. Then it's just a matter
21
+ # of using the attribute accessors we previously defined
22
+ def configure
23
+ yield(configuration)
24
+ end
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yonder_sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - James Sherriff
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: jwt
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '3.1'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '3.1'
26
+ description: Helper methods for interacting with Yonder
27
+ email: onliners@widgit.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - lib/yonder_sdk.rb
33
+ - lib/yonder_sdk/access_token.rb
34
+ - lib/yonder_sdk/configuration.rb
35
+ - lib/yonder_sdk/version.rb
36
+ licenses:
37
+ - MIT
38
+ metadata: {}
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 3.1.0
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubygems_version: 4.0.3
54
+ specification_version: 4
55
+ summary: Yonder SDK
56
+ test_files: []