omniauth-colorgy-oauth2 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -3
- data/{lib → app/controllers/concerns}/colorgy_devise_sso_manager.rb +13 -9
- data/{lib → app/controllers/concerns}/flash_message_reporter.rb +0 -0
- data/lib/omniauth/colorgy_oauth2/version.rb +2 -2
- data/lib/omniauth/colorgy_oauth2.rb +3 -1
- data/lib/omniauth-colorgy-oauth2.rb +5 -2
- data/omniauth-colorgy-oauth2.gemspec +2 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 761943b85e3233140e27f0c47719fed1a005337f
|
4
|
+
data.tar.gz: 6e267348560e44db0f5964d78d8ac6fe22d99272
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49b05775dd6c8e0d83d43301f4e0f7784c3c59872fd8241c400be2e3cbdd5915b18b54f09aa2b1889cec508e425944aa5167b10c79ff67ea73e0d680c4d7da86
|
7
|
+
data.tar.gz: 182a6b13b5c534772d2b45fca99418bc86155e37ba4fa2f3288b4883cc94d06e374dfe922b55a089f9c4083dd7cccdbee2703efc5ddf1f38a7bdc966d71f4c3f
|
data/README.md
CHANGED
@@ -129,13 +129,14 @@ _(Optional)_
|
|
129
129
|
|
130
130
|
The Colorgy SSO system is implemented using **OAuth 2.0** as the authorization protocol and **Sign-on Status Tokens (SST)** as credential of the sign-on status of the user, achieving sign in and out seamlessly controlled by a central server.
|
131
131
|
|
132
|
-
The **Sign-on Status Token (SST)** is stored in an cross-domain cookie (`_sst`) to represent the sign on status of the current user.
|
132
|
+
The **Sign-on Status Token (SST)** is stored in an cross-domain cookie (`_sst`) to represent the sign on status of the current user. **SST**s are trully [JSON Web Tokens (JWT)](https://tools.ietf.org/html/draft-ietf-oauth-json-web-token) containing identification information, signed by a RSA private key. Clients (other services under this SSO system) will be able to decode and verify the infomation using a corresponding RSA public key, and make reasonable reactions (signs in or out the user, reauthorize from the server... etc.) according to the infomation it provided.
|
133
133
|
|
134
134
|
This gem has implemented some solutions to cover certain use cases.
|
135
135
|
|
136
|
-
|
137
136
|
### Using Devise With Rails: `ColorgyDeviseSSOManager`
|
138
137
|
|
138
|
+
_An `ActiveSupport::Concern` to drop into your `ActionController` directly without any configurations to enable SSO support, if you're using devise and omniauth already._
|
139
|
+
|
139
140
|
> Limitations: since this tactic relys on sharing a cookie accross Colorgy core and your app, your app should be running on a subdomain of Colorgy core to make this work.
|
140
141
|
|
141
142
|
First, make sure Devise is setup properly to OmniAuth with Colorgy - clicking the 'Sign in with Colorgy' link will sign you in with no doubts.
|
@@ -177,7 +178,9 @@ end
|
|
177
178
|
|
178
179
|
_`FlashMessageReporter` is optional, include it if you want to relay flash messages from core to your app ._
|
179
180
|
|
180
|
-
|
181
|
+
> This `ActiveSupport::Concern` is zero-configured since we can guess the URL of Core SSO by OmniAuth and Devise configurations, get the RSA public key automatically from the server, and use the User model's `uuid` (or `cid`, `sid`) and `refreshed_at` (or `synced_at`) by convention to perform certain actions like checking the user's identity or last refresh date.
|
182
|
+
|
183
|
+
> You can also manually specify the RSA public key used to verify SSTs. Just pass it in using an environment variable called **`CORE_RSA_PUBLIC_KEY`**. Put it in your `.env` or export it like this: `export CORE_RSA_PUBLIC_KEY='-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3D ... P2QIDAQAB\n-----END PUBLIC KEY-----\n'`. Make sure it's accessible via `ENV['CORE_RSA_PUBLIC_KEY']` in your app.
|
181
184
|
|
182
185
|
Now that users on your app will be signing in/out synchronizedly with Colorgy core, and is automatically reauthorized to get user's new data from core when updated.
|
183
186
|
|
@@ -17,26 +17,30 @@ module ColorgyDeviseSSOManager
|
|
17
17
|
sign_out_url
|
18
18
|
end
|
19
19
|
|
20
|
-
# Override the destroy_user_session_path to logout from core
|
21
|
-
def destroy_user_session_path
|
22
|
-
sign_out_url
|
23
|
-
end
|
24
|
-
|
25
20
|
private
|
26
21
|
|
27
22
|
# Getter of the core domain
|
28
23
|
def core_domain
|
29
|
-
@@core_domain ||= URI.parse(
|
24
|
+
@@core_domain ||= URI.parse(core_url).host
|
30
25
|
end
|
31
26
|
|
32
27
|
# Getter of the core url
|
33
28
|
def core_url
|
34
|
-
@@core_url ||= Devise.omniauth_configs[:colorgy].options[:client_options]
|
29
|
+
@@core_url ||= if Devise.omniauth_configs[:colorgy].options[:client_options].is_a?(Hash)
|
30
|
+
Devise.omniauth_configs[:colorgy].options[:client_options][:site]
|
31
|
+
else
|
32
|
+
OmniAuth::Strategies::Colorgy.new(0).options.client_options.site
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Getter of the core rsa public key string
|
37
|
+
def core_rsa_public_key_string
|
38
|
+
@@core_rsa_public_key_string ||= (ENV['CORE_RSA_PUBLIC_KEY'] || Net::HTTP.get(core_domain, '/_rsa.pub')).gsub(/\\n/, "\n")
|
35
39
|
end
|
36
40
|
|
37
41
|
# Getter of the core rsa public key
|
38
42
|
def core_rsa_public_key
|
39
|
-
@@core_rsa_public_key ||= OpenSSL::PKey::RSA.new(
|
43
|
+
@@core_rsa_public_key ||= OpenSSL::PKey::RSA.new(core_rsa_public_key_string)
|
40
44
|
end
|
41
45
|
|
42
46
|
# Decode the sign-on status token (sst) string and return a hash
|
@@ -107,7 +111,7 @@ module ColorgyDeviseSSOManager
|
|
107
111
|
|
108
112
|
# if the user isn't signed in but the sst isn't blank,
|
109
113
|
# redirect to core authorize path
|
110
|
-
elsif !sst.blank?
|
114
|
+
elsif !sst.blank? && request.get? && is_navigational_format?
|
111
115
|
redirect_to user_omniauth_authorize_path(:colorgy) and return
|
112
116
|
end
|
113
117
|
end
|
File without changes
|
@@ -1,8 +1,10 @@
|
|
1
1
|
require "omniauth/colorgy_oauth2/version"
|
2
2
|
require File.join('omniauth', 'strategies', 'colorgy')
|
3
|
+
OmniAuth.config.add_camelization('colorgy_oauth', 'ColorgyOAuth')
|
4
|
+
OmniAuth.config.add_camelization('colorgy_oauth2', 'ColorgyOAuth2')
|
3
5
|
|
4
6
|
module OmniAuth
|
5
|
-
module
|
7
|
+
module ColorgyOAuth2
|
6
8
|
CORE_URL = 'https://colorgy.io'
|
7
9
|
end
|
8
10
|
end
|
@@ -1,3 +1,6 @@
|
|
1
1
|
require File.join('omniauth', 'colorgy_oauth2')
|
2
|
-
|
3
|
-
|
2
|
+
OmniAuth.config.add_camelization('colorgy_oauth', 'ColorgyOAuth')
|
3
|
+
OmniAuth.config.add_camelization('colorgy_oauth2', 'ColorgyOAuth2')
|
4
|
+
|
5
|
+
require File.expand_path(File.join('..', '..', 'app', 'controllers', 'concerns', 'flash_message_reporter'), __FILE__) if defined? ActiveSupport::Concern
|
6
|
+
require File.expand_path(File.join('..', '..', 'app', 'controllers', 'concerns', 'colorgy_devise_sso_manager'), __FILE__) if defined? Devise && defined? ActiveSupport::Concern
|
@@ -5,7 +5,7 @@ require 'omniauth/colorgy_oauth2/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "omniauth-colorgy-oauth2"
|
8
|
-
spec.version = OmniAuth::
|
8
|
+
spec.version = OmniAuth::ColorgyOAuth2::VERSION
|
9
9
|
spec.authors = ["Neson"]
|
10
10
|
spec.email = ["neson@dex.tw"]
|
11
11
|
|
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
|
|
29
29
|
|
30
30
|
spec.add_runtime_dependency 'omniauth', '>= 1.1.1'
|
31
31
|
spec.add_runtime_dependency 'omniauth-oauth2', '>= 1.1.1'
|
32
|
+
spec.add_runtime_dependency 'jwt', '>= 1.0.0'
|
32
33
|
spec.add_development_dependency "bundler"
|
33
34
|
spec.add_development_dependency "rake"
|
34
35
|
spec.add_development_dependency "rspec"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-colorgy-oauth2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Neson
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 1.1.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: jwt
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.0.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.0.0
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,10 +109,10 @@ files:
|
|
95
109
|
- LICENSE.txt
|
96
110
|
- README.md
|
97
111
|
- Rakefile
|
112
|
+
- app/controllers/concerns/colorgy_devise_sso_manager.rb
|
113
|
+
- app/controllers/concerns/flash_message_reporter.rb
|
98
114
|
- bin/console
|
99
115
|
- bin/setup
|
100
|
-
- lib/colorgy_devise_sso_manager.rb
|
101
|
-
- lib/flash_message_reporter.rb
|
102
116
|
- lib/omniauth-colorgy-oauth2.rb
|
103
117
|
- lib/omniauth/colorgy_oauth2.rb
|
104
118
|
- lib/omniauth/colorgy_oauth2/version.rb
|