openid_config_parser 0.1.1 → 0.2.0
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 +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +8 -2
- data/README.md +5 -5
- data/lib/openid_config_parser/version.rb +1 -1
- data/lib/openid_config_parser.rb +46 -4
- data/openid_config_parser.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef26b5603ae4f1d25d2b725a051751a8e217d589cab6c534cb8dce4b253f59c0
|
4
|
+
data.tar.gz: e583224a784aeccb0a0531b5e16874e9d6caa6d90e6716b8178fbf820c3e1ce2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a8889bf8260c9e26118543dbd0b1f9cff8ca702b629eada04f501248d6ef3ee1cd90ce4467c3cf54581302bb8ce3ede93189a86569e8a7bbc69c4e3dafab3f9
|
7
|
+
data.tar.gz: e7c4ca292deacca681b3e9767c22b2df064fe8761cb7eb9cc209dd954f16bff023b98cbfb14c0436e294e2b9878963bbb3ff93bb1928c815023b3548b9b5bfb6
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
## [Released]
|
2
2
|
|
3
|
-
## [0.
|
3
|
+
## [0.2.0] - 2024-06-04
|
4
|
+
- Add retryable, add support to access response values as methods
|
5
|
+
|
6
|
+
## [0.1.2] - 2024-05-25
|
7
|
+
- Add support for ruby >=2.7
|
8
|
+
|
9
|
+
## [0.1.1] - 2024-05-25
|
4
10
|
- Update readme
|
5
11
|
|
6
|
-
## [0.1.0] - 2024-05-
|
12
|
+
## [0.1.0] - 2024-05-25
|
7
13
|
- Initial release
|
data/README.md
CHANGED
@@ -35,11 +35,11 @@ class ApplicationController < ActionController::Base
|
|
35
35
|
config = OpenidConfigParser.fetch_openid_configuration(endpoint)
|
36
36
|
|
37
37
|
if config
|
38
|
-
issuer = config[:issuer]
|
39
|
-
auth_endpoint = config[:authorization_endpoint]
|
40
|
-
token_endpoint = config[:token_endpoint]
|
41
|
-
jwks_uri = config[:]
|
42
|
-
userinfo_endpoint = config[:userinfo_endpoint]
|
38
|
+
issuer = config.issuer # or config[:issuer]
|
39
|
+
auth_endpoint = config.authorization_endpoint # or config[:authorization_endpoint]
|
40
|
+
token_endpoint = config.token_endpoint # or config[:token_endpoint]
|
41
|
+
jwks_uri = config.jwks_uri # or config[:jwks_uri]
|
42
|
+
userinfo_endpoint = config.userinfo_endpoint # or config[:userinfo_endpoint]
|
43
43
|
# and so on
|
44
44
|
else
|
45
45
|
Rails.logger.error "Failed to fetch OpenID configuration"
|
data/lib/openid_config_parser.rb
CHANGED
@@ -4,6 +4,8 @@ require_relative "openid_config_parser/version"
|
|
4
4
|
require "net/http"
|
5
5
|
require "json"
|
6
6
|
require "uri"
|
7
|
+
require "retryable"
|
8
|
+
require "ostruct"
|
7
9
|
|
8
10
|
# OpenidConfigParser is a module that fetches and parses OpenID Connect
|
9
11
|
# configuration data from a specified endpoint URL and returns a Hash object.
|
@@ -12,6 +14,28 @@ require "uri"
|
|
12
14
|
module OpenidConfigParser
|
13
15
|
class Error < StandardError; end
|
14
16
|
|
17
|
+
# Config is a class that extends OpenStruct to provide a flexible object
|
18
|
+
# for accessing OpenID Connect configuration data. It allows access to
|
19
|
+
# configuration values both as methods (e.g., config.issuer) and as hash
|
20
|
+
# keys (e.g., config[:issuer]).
|
21
|
+
#
|
22
|
+
# Example usage:
|
23
|
+
# config = OpenidConfigParser.fetch_openid_configuration(endpoint)
|
24
|
+
# puts config.issuer # Method access
|
25
|
+
# puts config[:issuer] # Hash-like access
|
26
|
+
#
|
27
|
+
# This class is designed to be used internally by the OpenidConfigParser module
|
28
|
+
# and is not intended to be instantiated directly by users.
|
29
|
+
class Config < OpenStruct
|
30
|
+
def [](key)
|
31
|
+
send(key)
|
32
|
+
end
|
33
|
+
|
34
|
+
def []=(key, value)
|
35
|
+
send("#{key}=", value)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
15
39
|
class << self
|
16
40
|
# Recursively converts keys of a hash to symbols while retaining the original string keys.
|
17
41
|
def deep_symbolize_keys(hash)
|
@@ -24,11 +48,29 @@ module OpenidConfigParser
|
|
24
48
|
result
|
25
49
|
end
|
26
50
|
|
51
|
+
def fetch_user_info(access_token)
|
52
|
+
Retryable.retryable(tries: 3, on: [Net::ReadTimeout, Net::OpenTimeout]) do
|
53
|
+
response = HTTParty.get(ENV["CLOUDFLARE_USERINFO_ENDPOINT"], {
|
54
|
+
headers: {
|
55
|
+
"Authorization" => "Bearer #{access_token}",
|
56
|
+
"Content-Type" => "application/json"
|
57
|
+
},
|
58
|
+
timeout: 10
|
59
|
+
})
|
60
|
+
return response.parsed_response
|
61
|
+
end
|
62
|
+
rescue Net::ReadTimeout, Net::OpenTimeout => e
|
63
|
+
puts "Timeout error: #{e.message}"
|
64
|
+
nil
|
65
|
+
end
|
66
|
+
|
27
67
|
def fetch_openid_configuration(endpoint_url)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
68
|
+
Retryable.retryable(tries: 3, on: [Net::ReadTimeout, Net::OpenTimeout]) do
|
69
|
+
response = Net::HTTP.get(URI(endpoint_url))
|
70
|
+
config = JSON.parse(response)
|
71
|
+
symbolized_config = deep_symbolize_keys(config)
|
72
|
+
return Config.new(symbolized_config)
|
73
|
+
end
|
32
74
|
rescue JSON::ParserError => e
|
33
75
|
raise Error, "Failed to parse JSON response: #{e.message}"
|
34
76
|
rescue URI::InvalidURIError => e
|
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
|
|
15
15
|
this gem provides a simple and efficient way to retrieve and handle the necessary configuration details."
|
16
16
|
spec.homepage = "https://github.com/msuliq/openid_config_parser"
|
17
17
|
spec.license = "MIT"
|
18
|
-
spec.required_ruby_version = ">=
|
18
|
+
spec.required_ruby_version = ">= 2.7.0"
|
19
19
|
|
20
20
|
spec.metadata["homepage_uri"] = spec.homepage
|
21
21
|
spec.metadata["source_code_uri"] = "https://github.com/msuliq/openid_config_parser"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openid_config_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Suleyman Musayev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |-
|
14
14
|
`openid_config_parser` is a lightweight Ruby gem designed to fetch and parse
|
@@ -46,14 +46,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
46
46
|
requirements:
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version:
|
49
|
+
version: 2.7.0
|
50
50
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
requirements: []
|
56
|
-
rubygems_version: 3.
|
56
|
+
rubygems_version: 3.1.6
|
57
57
|
signing_key:
|
58
58
|
specification_version: 4
|
59
59
|
summary: Fetch data from OpenID Connect (OIDC) configuration endpoint and parse it
|