artsy-auth 0.1.5 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +22 -15
- data/app/views/artsy_auth/sessions/new.erb +20 -0
- data/config/routes.rb +1 -0
- data/lib/artsy-auth.rb +3 -2
- data/lib/artsy-auth/{application_controller.rb → authenticated.rb} +11 -5
- data/lib/artsy-auth/config.rb +0 -2
- data/lib/artsy-auth/session_controller.rb +5 -4
- data/lib/artsy-auth/version.rb +1 -1
- metadata +71 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3ba60006edb2e37220a6ba341de9ac26e26e3b4bcec129775a7f08552d40627a
|
4
|
+
data.tar.gz: da6c9ececb084317e0a8745a128e1c0a24ef3c680fb79b3b086c8c1830ff6d5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb51d56f276740c9268942c544452e2d82f5b07781a1e471a49ae05df13366fe3095c9e6fc926bf196e1287c249af9e89f6fd27f5b86199f4d7db766a393807c
|
7
|
+
data.tar.gz: cab76d066dddfd593a6670bdc56921d744c97173728e156304bbd5f209534b055eb24791c0dfeee6f19372b5ecc738d5785674906e9926461039b5c317649ddb
|
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
# Artsy Authentication [![
|
1
|
+
# Artsy Authentication [![CircleCI](https://circleci.com/gh/artsy/artsy-auth/tree/master.svg?style=shield)](https://circleci.com/gh/artsy/artsy-auth/tree/master)
|
2
2
|
|
3
3
|
Ruby Gem for adding Artsy's omniauth based authentication to your app.
|
4
4
|
|
5
5
|
## Installation
|
6
|
-
Add following line to your Gemfile
|
6
|
+
Add following line to your Gemfile.
|
7
7
|
|
8
8
|
```
|
9
9
|
gem 'artsy-auth'
|
@@ -13,14 +13,13 @@ gem 'artsy-auth'
|
|
13
13
|
Artsy Auth is based on [`Rails::Engine`](http://api.rubyonrails.org/classes/Rails/Engine.html).
|
14
14
|
|
15
15
|
### Configure
|
16
|
-
Add `artsy_auth.rb` under `config/initializers`. We need to configure `ArtsyAuth` to use proper Artsy `application_id` and `application_secret`. Also it needs `
|
16
|
+
Add `artsy_auth.rb` under `config/initializers`. We need to configure `ArtsyAuth` to use proper Artsy `application_id` and `application_secret`. Also it needs `artsy_api_url` which will be used to redirect `sign_in` and `sign_out` to proper location.
|
17
17
|
`callback_url` defines after a successful omniauth handshake, where should we get redirected to.
|
18
18
|
|
19
19
|
```ruby
|
20
|
-
# config/
|
20
|
+
# config/initializers/artsy_auth.rb
|
21
21
|
ArtsyAuth.configure do |config|
|
22
22
|
config.artsy_api_url = 'https://stagingapi.artsy.net' # required
|
23
|
-
config.artsy_url = 'https://staging.artsy.net' # required
|
24
23
|
config.callback_url = '/admin' # optional
|
25
24
|
config.application_id = '321322131' # required
|
26
25
|
config.application_secret = '123123asdasd' # required
|
@@ -33,26 +32,34 @@ You also need to mount session related endpoints to your app, in your `config/ro
|
|
33
32
|
mount ArtsyAuth::Engine => '/'
|
34
33
|
```
|
35
34
|
|
36
|
-
In order to force authentication, you need to
|
35
|
+
In order to force authentication, you need to include 'ArtsyAuth::Authenticated' in your controller, you also need to add (override) `authorized_artsy_token?` method there which gets a token and in your app you need to define how do you authorize that token, for example:
|
37
36
|
```ruby
|
38
|
-
class ApplicationController <
|
37
|
+
class ApplicationController < ActionController::Base
|
39
38
|
# Prevent CSRF attacks by raising an exception.
|
40
39
|
protect_from_forgery with: :exception
|
41
40
|
|
42
|
-
#
|
43
|
-
|
41
|
+
# This will make sure calls to this controller have proper session data
|
42
|
+
# if they don't it will redirect them to oauth url and once authenticated
|
43
|
+
# on successful authentication we'll call authorized_artsy_token
|
44
|
+
include ArtsyAuth::Authenticated
|
45
|
+
|
46
|
+
# override application to decode token and allow only users with `tester` role
|
47
|
+
def authorized_artsy_token?(token)
|
44
48
|
decoded_token, _headers = JWT.decode(token, 'some-secret')
|
45
49
|
decoded_token['roles'].include? 'tester'
|
46
50
|
end
|
47
51
|
end
|
48
52
|
```
|
49
|
-
Note that this will add authentication to all of your controllers, if you want to skip Artsy's authentication for specific controller you can skip it in your controller by adding:
|
50
|
-
```ruby
|
51
|
-
class TestController
|
52
|
-
skip_before_action :require_artsy_authentication
|
53
|
-
end
|
54
|
-
```
|
55
53
|
|
54
|
+
# Decoding the JWT
|
55
|
+
|
56
|
+
The JWT is signed using a different secret from the client secret for OAuth. For Artsy engineers: get it from the `internal_secret` on your corresponding `ClientApplication` model.
|
57
|
+
|
58
|
+
The JWT contains user information that you can get from an API call to get the `me` user account, you can work around not having the secret by making a request for that against the API.
|
59
|
+
|
60
|
+
|
61
|
+
# Update From Version < 0.1.7
|
62
|
+
In previous versions you would change your `ApplicationController` to inherit from `ArtsyAuth::ApplicationController`, with versions > `0.1.7` you need to `include ArtsyAuth::Authenticated` like the example above.
|
56
63
|
|
57
64
|
# Contributing
|
58
65
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<title>Artsy Auth</title>
|
6
|
+
</head>
|
7
|
+
<body>
|
8
|
+
<p id="placeholder" style="visibility: hidden; text-align: center;">Authenticating...</p>
|
9
|
+
<div style="display: none;">
|
10
|
+
<%= button_to 'Log in via Artsy', '/auth/artsy', form: { id: 'artsy-auth-login-form' } %>
|
11
|
+
</div>
|
12
|
+
|
13
|
+
<script>
|
14
|
+
document.getElementById("artsy-auth-login-form").submit();
|
15
|
+
setTimeout(function() {
|
16
|
+
document.getElementById("placeholder").style.visibility = "visible";
|
17
|
+
}, 1000);
|
18
|
+
</script>
|
19
|
+
</body>
|
20
|
+
</html>
|
data/config/routes.rb
CHANGED
data/lib/artsy-auth.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
+
require 'artsy-auth/authenticated'
|
1
2
|
require 'artsy-auth/config'
|
2
3
|
require 'artsy-auth/engine'
|
3
|
-
require 'artsy-auth/version'
|
4
|
-
require 'artsy-auth/application_controller'
|
5
4
|
require 'artsy-auth/session_controller'
|
5
|
+
require 'artsy-auth/version'
|
6
|
+
require 'omniauth/rails_csrf_protection'
|
6
7
|
|
7
8
|
module ArtsyAuth
|
8
9
|
end
|
@@ -1,10 +1,16 @@
|
|
1
1
|
module ArtsyAuth
|
2
|
-
|
3
|
-
|
2
|
+
module Authenticated
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
before_action :require_artsy_authentication
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
4
10
|
|
5
11
|
def require_artsy_authentication
|
6
12
|
if session[:access_token]
|
7
|
-
head(:forbidden) unless
|
13
|
+
head(:forbidden) unless authorized_artsy_token? session[:access_token]
|
8
14
|
else
|
9
15
|
clear_session_and_reauth! unless session[:access_token]
|
10
16
|
end
|
@@ -13,10 +19,10 @@ module ArtsyAuth
|
|
13
19
|
def clear_session_and_reauth!
|
14
20
|
reset_session
|
15
21
|
session[:redirect_to] = request.url
|
16
|
-
redirect_to '/auth/artsy'
|
22
|
+
redirect_to '/auth/artsy/new'
|
17
23
|
end
|
18
24
|
|
19
|
-
def
|
25
|
+
def authorized_artsy_token?(token)
|
20
26
|
raise NotImplementedError
|
21
27
|
end
|
22
28
|
end
|
data/lib/artsy-auth/config.rb
CHANGED
@@ -3,14 +3,12 @@ module ArtsyAuth
|
|
3
3
|
extend self
|
4
4
|
|
5
5
|
attr_accessor :artsy_api_url
|
6
|
-
attr_accessor :artsy_url
|
7
6
|
attr_accessor :application_id
|
8
7
|
attr_accessor :application_secret
|
9
8
|
attr_accessor :callback_url
|
10
9
|
|
11
10
|
def reset
|
12
11
|
self.artsy_api_url = nil
|
13
|
-
self.artsy_url = nil
|
14
12
|
self.callback_url = '/'
|
15
13
|
self.application_id = nil
|
16
14
|
self.application_secret = nil
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module ArtsyAuth
|
2
|
-
class SessionsController <
|
3
|
-
|
2
|
+
class SessionsController < ActionController::Base
|
3
|
+
def new; end
|
4
|
+
|
4
5
|
def create
|
5
6
|
session[:user_id] = auth_hash['uid']
|
6
7
|
session[:email] = auth_hash['info']['raw_info']['email']
|
@@ -10,7 +11,7 @@ module ArtsyAuth
|
|
10
11
|
|
11
12
|
def destroy
|
12
13
|
reset_session
|
13
|
-
redirect_to "#{ArtsyAuth.config.
|
14
|
+
redirect_to "#{ArtsyAuth.config.artsy_api_url}/users/sign_out"
|
14
15
|
end
|
15
16
|
|
16
17
|
protected
|
@@ -19,4 +20,4 @@ module ArtsyAuth
|
|
19
20
|
request.env['omniauth.auth']
|
20
21
|
end
|
21
22
|
end
|
22
|
-
end
|
23
|
+
end
|
data/lib/artsy-auth/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: artsy-auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artsy
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: omniauth-artsy
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.4.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.4.0
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: omniauth-oauth2
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -25,19 +39,19 @@ dependencies:
|
|
25
39
|
- !ruby/object:Gem::Version
|
26
40
|
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: omniauth-
|
42
|
+
name: omniauth-rails_csrf_protection
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - ">="
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
47
|
+
version: 1.0.0
|
34
48
|
type: :runtime
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
54
|
+
version: 1.0.0
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rails
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,7 +67,21 @@ dependencies:
|
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: 4.2.0
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: capybara
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard-rubocop
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
58
86
|
requirements:
|
59
87
|
- - ">="
|
@@ -80,6 +108,20 @@ dependencies:
|
|
80
108
|
- - ">="
|
81
109
|
- !ruby/object:Gem::Version
|
82
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
83
125
|
- !ruby/object:Gem::Dependency
|
84
126
|
name: rspec-rails
|
85
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -109,7 +151,21 @@ dependencies:
|
|
109
151
|
- !ruby/object:Gem::Version
|
110
152
|
version: '0'
|
111
153
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
154
|
+
name: selenium-webdriver
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: webdrivers
|
113
169
|
requirement: !ruby/object:Gem::Requirement
|
114
170
|
requirements:
|
115
171
|
- - ">="
|
@@ -131,18 +187,19 @@ extra_rdoc_files: []
|
|
131
187
|
files:
|
132
188
|
- README.md
|
133
189
|
- Rakefile
|
190
|
+
- app/views/artsy_auth/sessions/new.erb
|
134
191
|
- config/initializers/omniauth.rb
|
135
192
|
- config/routes.rb
|
136
193
|
- lib/artsy-auth.rb
|
137
|
-
- lib/artsy-auth/
|
194
|
+
- lib/artsy-auth/authenticated.rb
|
138
195
|
- lib/artsy-auth/config.rb
|
139
196
|
- lib/artsy-auth/engine.rb
|
140
197
|
- lib/artsy-auth/session_controller.rb
|
141
198
|
- lib/artsy-auth/version.rb
|
142
|
-
homepage:
|
199
|
+
homepage: https://www.artsy.net
|
143
200
|
licenses: []
|
144
201
|
metadata: {}
|
145
|
-
post_install_message:
|
202
|
+
post_install_message:
|
146
203
|
rdoc_options: []
|
147
204
|
require_paths:
|
148
205
|
- lib
|
@@ -157,10 +214,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
214
|
- !ruby/object:Gem::Version
|
158
215
|
version: '0'
|
159
216
|
requirements: []
|
160
|
-
|
161
|
-
|
162
|
-
signing_key:
|
217
|
+
rubygems_version: 3.2.23
|
218
|
+
signing_key:
|
163
219
|
specification_version: 4
|
164
|
-
summary: ArtsyAuth is a
|
220
|
+
summary: ArtsyAuth is a Rails engine that adds Artsy authentication with authorization
|
165
221
|
to your app.
|
166
222
|
test_files: []
|