oauth_im 0.1.0.beta2 → 0.4.6
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/README.md +70 -13
- data/app/controllers/concerns/oauth_im/authenticable.rb +5 -6
- data/app/controllers/oauth_im/client_controller.rb +1 -1
- data/lib/oauth_im/version.rb +1 -1
- metadata +49 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e28d71eba7b82be12370b581d9d18e1586c306f9289b652c01840b5741c390b1
|
4
|
+
data.tar.gz: a00df7c4945ba074f7493f727bed3a9b7b2404743d5f7b41f240e2042242530b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbcb705e404198de143fc4be4cfc0d3e61565d8e65786e856b0d0b562d86071cd686288ebb262db4d1b0e5433a2b7cf05da0d03746619114510f0e04e719cae8
|
7
|
+
data.tar.gz: fde29ac8263407ec2cce0d17d90ef85fa916e8d92ae8cc97b26335206b8b6c30c517c60b2af256ccdf16eea50fba7f8e94f1d727a77f6704002b62a3a4a2b313
|
data/README.md
CHANGED
@@ -1,28 +1,85 @@
|
|
1
1
|
# OauthIm
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
The IIAB apps use an OAuth service provider (currently FusionAuth). This gem
|
3
|
+
serves to standardize integration with this service. The hope is that,
|
4
|
+
at some point, we can add this service to the CMS, Kamaji, and related
|
5
|
+
apps.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
Add this line to your application's Gemfile:
|
9
9
|
|
10
10
|
```ruby
|
11
|
-
gem 'oauth_im'
|
11
|
+
gem 'oauth_im', '0.x.y' # e.g., '0.1.2'
|
12
12
|
```
|
13
13
|
|
14
|
-
|
14
|
+
Then run:
|
15
15
|
```bash
|
16
16
|
$ bundle
|
17
17
|
```
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
## Configuration
|
20
|
+
Once the gem is installed, add an initializer. Here is an example:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
# config/initializers/oauth_im.rb
|
24
|
+
module OauthIm
|
25
|
+
configure do |config|
|
26
|
+
config.api_key = ENV['FUSION_AUTH_API_KEY']
|
27
|
+
config.callback_path = ENV['FUSION_CALLBACK_PATH'] || DEFAULT_CALLBACK_PATH
|
28
|
+
config.client_id = ENV['FUSION_AUTH_CLIENT_ID']
|
29
|
+
config.client_secret = ENV['FUSION_AUTH_CLIENT_SECRET']
|
30
|
+
config.domain = ENV['FUSION_AUTH_DOMAIN']
|
31
|
+
config.hmac = ENV['FUSION_AUTH_HMAC']
|
32
|
+
config.iss_domain = ENV['FUSION_AUTH_ISS_DOMAIN']
|
33
|
+
config.tenant_id = ENV['FUSION_AUTH_TENANT_ID']
|
34
|
+
config.authorize_url = ENV['FUSION_AUTH_AUTHORIZE_URL'] || DEFAULT_AUTHORIZE_URL
|
35
|
+
config.token_url = ENV['FUSION_AUTH_TOKEN_URL'] || DEFAULT_TOKEN_URL
|
36
|
+
end
|
37
|
+
end
|
22
38
|
```
|
23
39
|
|
24
|
-
|
25
|
-
|
40
|
+
* The `ENV` variable values can be obtained from the OAuth provider.
|
41
|
+
* The `callback_path` setting is used in two related ways:
|
42
|
+
* It [defines a route](https://github.com/illustrativemathematics/oauth_im/blob/main/config/routes.rb#L4) to the [`OAuthIm::ClientController#callback`
|
43
|
+
action](https://github.com/illustrativemathematics/oauth_im/blob/main/app/controllers/oauth_im/client_controller.rb#L7-L12).
|
44
|
+
* It defines a [callback URL](https://github.com/illustrativemathematics/oauth_im/blob/main/app/controllers/oauth_im/client_controller.rb#L69) used by the OAuth provider.
|
45
|
+
* Note that this callback URL must be whitelisted at the provider.
|
46
|
+
At FusionAuth, this is done under the `Applications|OAuth` tab.
|
47
|
+
* For instance, for the app `staging-kh-iiab.herokuapp.com`, if
|
48
|
+
`config.callback_path` is set to `callback` (the default), then
|
49
|
+
the URL `https://staging-kh-iiab.herokuapp.com/oauth_im/callback`
|
50
|
+
must be entered in the OAuth provider's list of authorized
|
51
|
+
redirect URLs.
|
52
|
+
|
53
|
+
## Usage
|
54
|
+
### Helpers for Logging in and Out
|
55
|
+
The engine provides [two endpoints](https://github.com/illustrativemathematics/oauth_im/blob/main/config/routes.rb#L5-L6) for logging in and out, and exposes
|
56
|
+
corresponding view helpers. These are accessible from the main app as:
|
57
|
+
|
58
|
+
| path | url |
|
59
|
+
|------|-----|
|
60
|
+
| `oauth_im.login_path` | `oauth_im.login_url` |
|
61
|
+
| `oauth_im.logout_path` | `oauth_im.logout_url` |
|
62
|
+
|
63
|
+
* Note that the helpers are namespaced to the engine.
|
64
|
+
|
65
|
+
The [controller actions](https://github.com/illustrativemathematics/oauth_im/blob/main/app/controllers/oauth_im/client_controller.rb#L14-L21) for these routes are provided and should "just
|
66
|
+
work." Note that there are no view templates associated with these
|
67
|
+
actions, since requests to them are redirected to the OAuth provider.
|
68
|
+
|
69
|
+
### Helpers for User ID and Authentication
|
70
|
+
The gem provides a controller concern, `OauthIm::Authenticable`, that
|
71
|
+
exposes [two helper methods](https://github.com/illustrativemathematics/oauth_im/blob/main/app/controllers/concerns/oauth_im/authenticable.rb#L9-L10) for use in views:
|
72
|
+
* `authenticated?`: returns `true` if the user has been authenticated
|
73
|
+
by the OAuth service, false otherwise.
|
74
|
+
* `email`: returns the current user's authenticated email address.
|
26
75
|
|
27
|
-
|
28
|
-
|
76
|
+
You can include this concern in your app's `ApplicationController` or
|
77
|
+
some other appropriate location, e.g.:
|
78
|
+
``` ruby
|
79
|
+
class ApplicationController < ActionController::Base
|
80
|
+
include OauthIm::Authenticable
|
81
|
+
|
82
|
+
# etc. etc. etc.
|
83
|
+
end
|
84
|
+
|
85
|
+
```
|
@@ -5,7 +5,6 @@ module OauthIm
|
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
7
|
included do
|
8
|
-
before_action :auth_uid
|
9
8
|
helper_method :authenticated?
|
10
9
|
helper_method :email
|
11
10
|
end
|
@@ -20,10 +19,6 @@ module OauthIm
|
|
20
19
|
@email ||= jwt_token['email']
|
21
20
|
end
|
22
21
|
|
23
|
-
def auth_uid
|
24
|
-
gon.user_id = session[:user_jwt]['value'].first['jti'] if authenticated?
|
25
|
-
end
|
26
|
-
|
27
22
|
def user_jwt
|
28
23
|
@user_jwt ||= session[:user_jwt] || {}
|
29
24
|
end
|
@@ -48,7 +43,11 @@ module OauthIm
|
|
48
43
|
end
|
49
44
|
|
50
45
|
def logged_in?
|
51
|
-
current_user.present?
|
46
|
+
current_user.present? || local_login?
|
47
|
+
end
|
48
|
+
|
49
|
+
def local_login?
|
50
|
+
session[:userinfo].present?
|
52
51
|
end
|
53
52
|
end
|
54
53
|
end
|
@@ -21,7 +21,7 @@ module OauthIm
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def local_login
|
24
|
-
raise 'Disallowed'
|
24
|
+
raise 'Disallowed' if Rails.env.production?
|
25
25
|
|
26
26
|
session[:userinfo] = { info: { email: 'local_login@example.com' } }
|
27
27
|
redirect_back(fallback_location: main_app.root_path)
|
data/lib/oauth_im/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oauth_im
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Connally
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-02-
|
11
|
+
date: 2022-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jwt
|
@@ -66,6 +66,48 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.23.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.23.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-rails
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.21'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.21'
|
69
111
|
description: Include this gem in Gemfile, add an initializer, and you are good to
|
70
112
|
go.
|
71
113
|
email:
|
@@ -98,7 +140,7 @@ metadata:
|
|
98
140
|
homepage_uri: https://github.com/illustrativemathematics/oauth_im
|
99
141
|
source_code_uri: https://github.com/illustrativemathematics/oauth_im
|
100
142
|
changelog_uri: https://github.com/illustrativemathematics/oauth_im
|
101
|
-
post_install_message:
|
143
|
+
post_install_message:
|
102
144
|
rdoc_options: []
|
103
145
|
require_paths:
|
104
146
|
- lib
|
@@ -109,12 +151,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
109
151
|
version: 2.6.6
|
110
152
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
153
|
requirements:
|
112
|
-
- - "
|
154
|
+
- - ">="
|
113
155
|
- !ruby/object:Gem::Version
|
114
|
-
version:
|
156
|
+
version: '0'
|
115
157
|
requirements: []
|
116
158
|
rubygems_version: 3.0.3
|
117
|
-
signing_key:
|
159
|
+
signing_key:
|
118
160
|
specification_version: 4
|
119
161
|
summary: Provide oauth functionality for IM apps.
|
120
162
|
test_files: []
|