omniauth-qualtrics 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +167 -0
- data/Rakefile +16 -0
- data/lib/omniauth-qualtrics.rb +2 -0
- data/lib/omniauth-qualtrics/version.rb +5 -0
- data/lib/omniauth/strategies/qualtrics.rb +44 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4e547cc2a8845f20bfccd272c57e7f5fbe8e6461cd249e0221193dd0d5cba3b2
|
4
|
+
data.tar.gz: a4b5d6caee4fa545284f1e0135024e293a663dfc85c78d4282729fba8c0a037c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 495d24603adb303e8219efbd23cbf91279c85dfdd2a0d3fc1d399bde42a0139a9e303257cd825dc6d502f6a967f194cc72bac8fc3ca8126b8d720085e7625b9b
|
7
|
+
data.tar.gz: 5ccbb3f91ffb510beaafbb83ce5dd4e43780637fcf28229339ff73f3d95eca1a64da854cc12d77496794d128a47900332330f7b18e79fffbe1e6f17c9d598d1e
|
data/README.md
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
# OmniAuth Qualtrics [![Build Status](https://travis-ci.org/atomicjolt/omniauth-qualtrics.svg?branch=master)](https://travis-ci.org/atomicjolt/omniauth-qualtrics)
|
2
|
+
Gem to authenticate with Qualtrics via OAuth2
|
3
|
+
|
4
|
+
# Setup
|
5
|
+
Contact Qualtrics administrator to get an OAuth key and secret and OAuth endpoint
|
6
|
+
https://api.qualtrics.com/instructions/docs/Instructions/oauth-authentication-authorization-code.md
|
7
|
+
|
8
|
+
|
9
|
+
**NOTE**: you will need to set `env['rack.session']['oauth_site']` to the current
|
10
|
+
Qualtrics instance that you wish to OAuth with. By default this is https://co1.qualtrics.com
|
11
|
+
|
12
|
+
-- OR --
|
13
|
+
|
14
|
+
to dynamically set the qualtrics site url do one of the following.
|
15
|
+
|
16
|
+
## Standard setup
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
use OmniAuth::Builder do
|
20
|
+
provider :qualtrics, 'qualtrics_key', 'qualtrics_secret', :setup => lambda{|env|
|
21
|
+
request = Rack::Request.new(env)
|
22
|
+
env['omniauth.strategy'].options[:client_options].site = env['rack.session']['oauth_site']
|
23
|
+
}
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
## Setup with Devise
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
config.omniauth :qualtrics, 'qualtrics_key', 'qualtrics_secret', :setup => lambda{|env|
|
31
|
+
request = Rack::Request.new(env)
|
32
|
+
env['omniauth.strategy'].options[:client_options].site = env['rack.session']['oauth_site']
|
33
|
+
}
|
34
|
+
```
|
35
|
+
|
36
|
+
## Alternative Setup
|
37
|
+
|
38
|
+
In this setup, you do not have to set `env['rack.session']['oauth_site']`
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
42
|
+
provider :qualtrics, APP_CONFIG['qualtrics_client_id'], APP_CONFIG['qualtrics_client_secret'],
|
43
|
+
{
|
44
|
+
:client_options => {
|
45
|
+
:site => APP_CONFIG['qualtrics_host']
|
46
|
+
}
|
47
|
+
}
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
# State
|
52
|
+
|
53
|
+
In most cases your application will need to restore state after handling the OAuth process
|
54
|
+
with Qualtrics. Since many applications that integrate with Qualtrics will be launched via the LTI
|
55
|
+
protocol inside of an iframe sessions may not be available. To restore application state the
|
56
|
+
omniauth-qualtrics gem uses the "state" parameter provided by the LTI proctocol. You will need
|
57
|
+
to add the following code to your application to take advantage of this functionality:
|
58
|
+
|
59
|
+
|
60
|
+
Add the following initializer in `config/initializers/omniauth.rb`:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
OmniAuth.config.before_request_phase do |env|
|
64
|
+
request = Rack::Request.new(env)
|
65
|
+
state = "#{SecureRandom.hex(24)}#{DateTime.now.to_i}"
|
66
|
+
OauthState.create!(state: state, payload: request.params.to_json)
|
67
|
+
env["omniauth.strategy"].options[:authorize_params].state = state
|
68
|
+
|
69
|
+
# Bye default omniauth will store all params in the session. The code above
|
70
|
+
# stores the values in the database so we remove the values from the session
|
71
|
+
# since the amount of data in the original params object will overflow the
|
72
|
+
# allowed cookie size
|
73
|
+
env["rack.session"].delete("omniauth.params")
|
74
|
+
end
|
75
|
+
```
|
76
|
+
|
77
|
+
Add the following middleware to `lib/middlware/oauth_state_middleware.rb`:
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
class OauthStateMiddleware
|
81
|
+
def initialize(app)
|
82
|
+
@app = app
|
83
|
+
end
|
84
|
+
|
85
|
+
def call(env)
|
86
|
+
request = Rack::Request.new(env)
|
87
|
+
if request.params["state"] && request.params["code"]
|
88
|
+
if oauth_state = OauthState.find_by(state: request.params["state"])
|
89
|
+
# Restore the param from before the OAuth dance
|
90
|
+
state_params = JSON.parse(oauth_state.payload) || {}
|
91
|
+
state_params.each do |key, value|
|
92
|
+
request.update_param(key, value)
|
93
|
+
end
|
94
|
+
application_instance = ApplicationInstance.find_by(lti_key: state_params["oauth_consumer_key"])
|
95
|
+
env["qualtrics.url"] = application_instance.lti_consumer_uri
|
96
|
+
oauth_state.destroy
|
97
|
+
else
|
98
|
+
raise OauthStateMiddlewareException, "Invalid state in OAuth callback"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
@app.call(env)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
class OauthStateMiddlewareException < RuntimeError
|
106
|
+
end
|
107
|
+
```
|
108
|
+
|
109
|
+
This middleware relies upon two models - OauthState and ApplicationInstance. OauthState is used to
|
110
|
+
store relevant state before sending the user to Qualtrics to finish the OAuth. ApplicationInstance is
|
111
|
+
model used in Atomic Jolt projects that is used to store the Qualtrics Url so that it can be reset in
|
112
|
+
the environment. You don't need to implement the same model, but you will need to store the user's
|
113
|
+
Qualtrics URL somewhere before sending the user to OAuth with Qualtrics. Change the following lines in the
|
114
|
+
above code to recover the Qualtrics URL from where ever it is stored:
|
115
|
+
|
116
|
+
```
|
117
|
+
application_instance = ApplicationInstance.find_by(lti_key: state_params["oauth_consumer_key"])
|
118
|
+
env["qualtrics.url"] = application_instance.lti_consumer_uri
|
119
|
+
```
|
120
|
+
|
121
|
+
The OauthState model looks like this:
|
122
|
+
```
|
123
|
+
class OauthState < ActiveRecord::Base
|
124
|
+
validates :state, presence: true, uniqueness: true
|
125
|
+
end
|
126
|
+
```
|
127
|
+
|
128
|
+
With the following schema:
|
129
|
+
```
|
130
|
+
create_table "oauth_states", force: :cascade do |t|
|
131
|
+
t.string "state"
|
132
|
+
t.text "payload"
|
133
|
+
t.datetime "created_at", null: false
|
134
|
+
t.datetime "updated_at", null: false
|
135
|
+
t.index ["state"], name: "index_oauth_states_on_state", using: :btree
|
136
|
+
end
|
137
|
+
```
|
138
|
+
|
139
|
+
Last, enable the middleware by adding the following to `config/application.rb`:
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
# Middleware that can restore state after an OAuth request
|
143
|
+
config.middleware.insert_before 0, "OauthStateMiddleware"
|
144
|
+
```
|
145
|
+
|
146
|
+
|
147
|
+
# License
|
148
|
+
|
149
|
+
Copyright (C) 2012-2021 Atomic Jolt.
|
150
|
+
|
151
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
152
|
+
of this software and associated documentation files (the "Software"), to deal
|
153
|
+
in the Software without restriction, including without limitation the rights
|
154
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
155
|
+
copies of the Software, and to permit persons to whom the Software is
|
156
|
+
furnished to do so, subject to the following conditions:
|
157
|
+
|
158
|
+
The above copyright notice and this permission notice shall be included in
|
159
|
+
all copies or substantial portions of the Software.
|
160
|
+
|
161
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
162
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
163
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
164
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
165
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
166
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
167
|
+
THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
$: << File.dirname(__FILE__)
|
3
|
+
|
4
|
+
require 'bundler'
|
5
|
+
require 'rake'
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
|
8
|
+
Bundler::GemHelper.install_tasks
|
9
|
+
|
10
|
+
task :default => [:spec]
|
11
|
+
task :test => [:spec]
|
12
|
+
|
13
|
+
desc "run spec tests"
|
14
|
+
RSpec::Core::RakeTask.new('spec') do |t|
|
15
|
+
t.pattern = 'spec/**/*_spec.rb'
|
16
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "omniauth-oauth2"
|
2
|
+
|
3
|
+
module OmniAuth
|
4
|
+
module Strategies
|
5
|
+
class Qualtrics < OmniAuth::Strategies::OAuth2
|
6
|
+
|
7
|
+
option :name, "qualtrics"
|
8
|
+
|
9
|
+
option :client_options,
|
10
|
+
site: "https://co1.qualtrics.com",
|
11
|
+
authorize_url: "/oauth2/auth",
|
12
|
+
token_url: "/oauth2/token"
|
13
|
+
|
14
|
+
# Qualtrics does use state but we want to control it rather than letting
|
15
|
+
# omniauth-oauth2 handle it.
|
16
|
+
option :provider_ignores_state, true
|
17
|
+
|
18
|
+
option :token_params, parse: :json
|
19
|
+
|
20
|
+
info do
|
21
|
+
{
|
22
|
+
"url" => access_token.client.site
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
# Override authorize_params so that we can be deliberate about the value for state
|
27
|
+
# and not use the session which is unavailable inside of an iframe for some
|
28
|
+
# browsers (ie Safari)
|
29
|
+
def authorize_params
|
30
|
+
# Only set state if it hasn't already been set
|
31
|
+
options.authorize_params[:state] ||= SecureRandom.hex(24)
|
32
|
+
params = options.authorize_params.merge(options_for("authorize"))
|
33
|
+
if OmniAuth.config.test_mode
|
34
|
+
@env ||= {}
|
35
|
+
@env["rack.session"] ||= {}
|
36
|
+
end
|
37
|
+
params
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
OmniAuth.config.add_camelization "qualtrics", "Qualtrics"
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-qualtrics
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Justin Ball
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-04-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: omniauth
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: omniauth-oauth2
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.4'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rack-test
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
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: byebug
|
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
|
+
description: OmniAuth Oauth2 strategy for Qualtrics.
|
98
|
+
email: justin.ball@atomicjolt.com
|
99
|
+
executables: []
|
100
|
+
extensions: []
|
101
|
+
extra_rdoc_files: []
|
102
|
+
files:
|
103
|
+
- README.md
|
104
|
+
- Rakefile
|
105
|
+
- lib/omniauth-qualtrics.rb
|
106
|
+
- lib/omniauth-qualtrics/version.rb
|
107
|
+
- lib/omniauth/strategies/qualtrics.rb
|
108
|
+
homepage: https://github.com/atomicjolt/omniauth-qualtrics
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '2.0'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubygems_version: 3.1.4
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: OmniAuth Oauth2 strategy for Qualtrics.
|
131
|
+
test_files: []
|