miniorange-oauth 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9f78f4cba3bbd5ffac7fe891ec1d19a78762d5120fceefc46f1f09aebaacd32f
4
+ data.tar.gz: e0d7e5513728efaf7e921cd958d1e94c7180d0317c895a9ad2033836f7c74208
5
+ SHA512:
6
+ metadata.gz: d260da2d8bc932c440d410a50fb425ed2fbea4ca4e13f093fdcb3019db1a3ecdeaca6ab1270f4ca5e60b52792ccaf08df21183691bbcf0f25a8ed04ee9d218b9
7
+ data.tar.gz: 9fd28cdc031d60efaa7f8332484b7ee1fe9a482048f9a803abf07f838495d76a493c29801c491ec82d3f214b814629485a5d2013027645161fc7172b5ff16858
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-07-02
4
+
5
+ - Initial release
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # MiniOrange OAuth Connector
2
+
3
+ A Ruby gem for implementing OAuth 2.0 authentication with miniOrange.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'miniorange-oauth'
11
+ ```
12
+
13
+ And then execute:
14
+ ```bash
15
+ bundle install
16
+ ```
17
+
18
+ Or install it yourself as:
19
+ ```bash
20
+ gem install miniorange-oauth
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ 1. Configure the OAuth client:
26
+
27
+ ```ruby
28
+ MiniOrange::Oauth.configure do |config|
29
+ config.client_id = "your_client_id"
30
+ config.client_secret = "your_client_secret"
31
+ config.redirect_uri = "https://your-app.com/sso/callback"
32
+ config.baseUri = "https://miniorange.com"
33
+ config.loginRedirectUri = "https://your-app.com/dashboard"
34
+ config.logoutRedirectUri = "https://your-app.com"
35
+ config.brokerUri = "https://broker.miniorange.com" # Optional
36
+ end
37
+ ```
38
+
39
+ 2. Generate authorization URL:
40
+
41
+ ```ruby
42
+ auth_handler = MiniOrange::Oauth::Handlers::AuthorizationHandler.new
43
+ auth_url = auth_handler.generate_authorization_url
44
+ # Redirect user to auth_url
45
+ ```
46
+
47
+ 3. Handle the callback:
48
+
49
+ ```ruby
50
+ callback_handler = MiniOrange::Oauth::Handlers::CallbackHandler.new
51
+ result = callback_handler.handle_callback(callback_url)
52
+
53
+ if result
54
+ user_info = result[:user_info]
55
+ # Handle user information as needed
56
+ end
57
+ ```
58
+
59
+ ## Development
60
+
61
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
62
+
63
+ To install this gem onto your local machine, run `bundle exec rake install`.
64
+
65
+ ## Contributing
66
+
67
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yourusername/ruby-oauth.
68
+
69
+ ## License
70
+
71
+ The gem is available as open source under the terms of the MIT License.
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MiniOrange
4
+ module Oauth
5
+ module Config
6
+ class Configuration
7
+ def initialize
8
+ end
9
+
10
+ # Client credentials
11
+ attr_accessor :client_id, :client_secret
12
+
13
+ # URIs
14
+ attr_accessor :redirect_uri, :base_uri, :logout_redirect_uri, :broker_uri
15
+
16
+ private
17
+
18
+ def validate_uri(uri)
19
+ URI.parse(uri)
20
+ true
21
+ rescue URI::InvalidURIError
22
+ false
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MiniOrange
4
+ module Oauth
5
+ module Handlers
6
+ class AuthorizationHandler
7
+ def generate_authorization_url
8
+ client_id = config.client_id
9
+ redirect_uri = URI.encode_www_form_component(config.redirect_uri)
10
+ scope = "openid"
11
+
12
+ # Use broker_uri or base_uri
13
+ auth_url = if config.broker_uri && !config.broker_uri.empty?
14
+ config.broker_uri
15
+ else
16
+ Utils::UrlUtils.create_authorization_url(config.base_uri)
17
+ end
18
+
19
+ # Construct full URL
20
+ "#{auth_url}?response_type=code&client_id=#{client_id}&redirect_uri=#{redirect_uri}&scope=#{scope}"
21
+ end
22
+
23
+ private
24
+
25
+ def config
26
+ MiniOrange::Oauth.configuration
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "uri"
4
+ require "json"
5
+
6
+ module MiniOrange
7
+ module Oauth
8
+ module Handlers
9
+ class CallbackHandler
10
+ def initialize(config = MiniOrange::Oauth.configuration)
11
+ @config = config
12
+ end
13
+
14
+ def handle_callback(callback_url)
15
+ uri = URI.parse(callback_url)
16
+ return unless uri.path&.start_with?("/sso/callback")
17
+
18
+ params = URI.decode_www_form(uri.query.to_s).to_h
19
+ code = params["code"]
20
+ raise Error, "No authorization code found in callback URL" unless code
21
+
22
+ access_token = fetch_token(code)
23
+ user_info = fetch_user_info(access_token)
24
+
25
+ { user_info: user_info, access_token: access_token }
26
+ end
27
+
28
+ private
29
+
30
+ def fetch_token(code)
31
+ token_url = MiniOrange::Oauth::Utils::UrlUtils.create_token_url(@config.base_uri)
32
+ response = Faraday.post(token_url) do |req|
33
+ req.headers["Content-Type"] = "application/x-www-form-urlencoded"
34
+ req.body = build_query_string(
35
+ grant_type: "authorization_code",
36
+ code: code,
37
+ client_id: @config.client_id,
38
+ client_secret: @config.client_secret,
39
+ redirect_uri: @config.redirect_uri,
40
+ scope: "openid"
41
+ )
42
+ end
43
+
44
+ raise Error, "Failed to get access token: #{response.body}" unless response.status == 200
45
+
46
+ JSON.parse(response.body)["access_token"]
47
+ end
48
+
49
+ def fetch_user_info(access_token)
50
+ user_info_url = MiniOrange::Oauth::Utils::UrlUtils.get_user_info_url(@config.base_uri)
51
+ response = Faraday.get(user_info_url) do |req|
52
+ req.headers["Authorization"] = "Bearer #{access_token}"
53
+ req.headers["Accept"] = "application/json"
54
+ end
55
+
56
+ raise Error, "Failed to get user info: #{response.body}" unless response.status == 200
57
+
58
+ JSON.parse(response.body)
59
+ end
60
+
61
+ def build_query_string(params)
62
+ params.compact.map { |k, v| "#{k}=#{URI.encode_www_form_component(v)}" }.join("&")
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "uri"
4
+
5
+ module MiniOrange
6
+ module Oauth
7
+ module Handlers
8
+ class LogoutHandler
9
+ def initialize(config = MiniOrange::Oauth.configuration)
10
+ @config = config
11
+ end
12
+
13
+ def generate_logout_url
14
+ base_url = @config.base_uri
15
+ post_logout_redirect_uri = @config.logout_redirect_uri
16
+
17
+ raise Error, "Missing logout_redirect_uri in configuration" unless post_logout_redirect_uri
18
+ raise Error, "Missing base_uri in configuration" unless base_url
19
+
20
+ Utils::UrlUtils.create_logout_url(base_url, post_logout_redirect_uri)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "uri"
4
+
5
+ module MiniOrange
6
+ module Oauth
7
+ module Utils
8
+ class UrlUtils
9
+ class << self
10
+ def create_token_url(base_url)
11
+ "#{base_url}/rest/oauth/token"
12
+ end
13
+
14
+ def create_authorization_url(base_url)
15
+ "#{base_url}/idp/openidsso"
16
+ end
17
+
18
+ def create_revocation_url(base_url)
19
+ "#{base_url}/rest/oauth/revoke"
20
+ end
21
+
22
+ def create_introspection_url(base_url)
23
+ "#{base_url}/rest/oauth/introspect"
24
+ end
25
+
26
+ def get_user_info_url(base_url)
27
+ "#{base_url}/rest/oauth/getuserinfo"
28
+ end
29
+
30
+ def create_logout_url(base_url, logout_redirect_uri)
31
+ "#{base_url}/idp/oidc/logout?post_logout_redirect_uri=#{URI.encode_www_form_component(logout_redirect_uri)}"
32
+ end
33
+
34
+ private
35
+
36
+ def ensure_no_trailing_slash(url)
37
+ url.chomp("/")
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MiniOrange
4
+ module Oauth
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+
5
+ require_relative "oauth/version"
6
+ require_relative "oauth/config/configuration"
7
+ require_relative "oauth/handlers/authorization_handler"
8
+ require_relative "oauth/handlers/callback_handler"
9
+ require_relative "oauth/handlers/logout_handler"
10
+ require_relative "oauth/utils/url_utils"
11
+
12
+ module MiniOrange
13
+ module Oauth
14
+ class Error < StandardError; end
15
+
16
+ class << self
17
+ def configuration
18
+ @configuration ||= Config::Configuration.new
19
+ end
20
+
21
+ def configure
22
+ yield(configuration) if block_given?
23
+ end
24
+
25
+ def reset_configuration!
26
+ @configuration = Config::Configuration.new
27
+ end
28
+ end
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: miniorange-oauth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - miniOrange
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: faraday
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '2.0'
26
+ description: A Ruby gem for implementing OAuth 2.0 authentication with miniOrange
27
+ email:
28
+ - idpsupport@xecurify.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - CHANGELOG.md
34
+ - CODE_OF_CONDUCT.md
35
+ - README.md
36
+ - lib/miniorange/oauth.rb
37
+ - lib/miniorange/oauth/config/configuration.rb
38
+ - lib/miniorange/oauth/handlers/authorization_handler.rb
39
+ - lib/miniorange/oauth/handlers/callback_handler.rb
40
+ - lib/miniorange/oauth/handlers/logout_handler.rb
41
+ - lib/miniorange/oauth/utils/url_utils.rb
42
+ - lib/miniorange/oauth/version.rb
43
+ homepage: https://github.com/miniOrangeDev/ruby-oauth
44
+ licenses:
45
+ - MIT
46
+ metadata: {}
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 3.1.0
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubygems_version: 3.6.7
62
+ specification_version: 4
63
+ summary: Ruby OAuth Connector for miniOrange
64
+ test_files: []