openid_config_parser 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 +4 -4
- data/CHANGELOG.md +6 -3
- data/README.md +5 -5
- data/lib/openid_config_parser/version.rb +1 -1
- data/lib/openid_config_parser.rb +46 -4
- metadata +2 -2
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/CHANGELOG.md
CHANGED
@@ -1,10 +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
|
4
7
|
- Add support for ruby >=2.7
|
5
8
|
|
6
|
-
## [0.1.1] - 2024-05-
|
9
|
+
## [0.1.1] - 2024-05-25
|
7
10
|
- Update readme
|
8
11
|
|
9
|
-
## [0.1.0] - 2024-05-
|
12
|
+
## [0.1.0] - 2024-05-25
|
10
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
|
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
|