omniauth-open-edx 1.0.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: 9bb707284e879a220930aee4a98fa14c4a4e06a4067b8d87719ad4045628eb6d
4
+ data.tar.gz: fd39ed5c00099c6dd0fe100da9f95d436f5e92be21eec266ef254765115e6df9
5
+ SHA512:
6
+ metadata.gz: 2ee47db6426bfa6c05725e6e08b24b97bf89def9bfa886ef64350a56653a1bba9e83d050af520f81d7172b51d65607dccaf002da7f42933cc41e8bed2ae03f5e
7
+ data.tar.gz: 97796ee6bca64e35c4418549dc6c2c6497aeffa7ab26a2a93ea973d1206fb51cc8fe468e1a4a80e21b38fcca9ea0f0853eb12a2309b3429ce26bfae8f1b642d8
data/.editorconfig ADDED
@@ -0,0 +1,12 @@
1
+ # EditorConfig is awesome: https://EditorConfig.org
2
+
3
+ # top-most EditorConfig file
4
+ root = true
5
+
6
+ [*]
7
+ indent_style = space
8
+ indent_size = 2
9
+ end_of_line = lf
10
+ charset = utf-8
11
+ trim_trailing_whitespace = true
12
+ insert_final_newline = true
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ Gemfile.lock
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.prettierrc.yml ADDED
@@ -0,0 +1 @@
1
+ rubySingleQuote: false
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,5 @@
1
+ inherit_gem:
2
+ prettier: rubocop.yml
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in omniauth-open-edx.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) International Business Machines Corporation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # OmniAuth::OpenEdx
2
+
3
+ This is the OmniAuth stragegy for authenticaing to Open edX.
4
+
5
+ Note, this strategy only works with Open edX `juniper` release or above.
6
+
7
+ ## Installation
8
+
9
+ Add to your `Gemfile`:
10
+
11
+ ```ruby
12
+ gem "omniauth-open-edx"
13
+ ```
14
+
15
+ ## Open edX OAuth2 Toolkit Setup
16
+
17
+ - Go to `${LMS_URL}/admin/oauth2_provider/application`
18
+ - Add a new application
19
+ - Enter redirect url, this depends on your setup, learn more from [examples](./examples)
20
+ - Select `Confidential` client type, `Authorization code` authorization grant type
21
+ - Get the `Client id` and `Client secret` and configure them in your ruby application
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ use OmniAuth::Builder do
27
+ provider :open_edx,
28
+ ENV["OPEN_EDX_OAUTH_CLIENT_ID"],
29
+ ENV["OPEN_EDX_OAUTH_CLIENT_SECRET"],
30
+ {
31
+ scope: "profile email",
32
+ client_options: {
33
+ site: "https://courses.edx.org",
34
+ },
35
+ }
36
+ end
37
+ ```
38
+
39
+ ## License
40
+
41
+ [MIT License](./LICENSE).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "omniauth-open-edx"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gem "omniauth-open-edx", path: "../../"
@@ -0,0 +1,38 @@
1
+ begin
2
+ require "sinatra"
3
+ require "omniauth"
4
+ require "omniauth-open-edx"
5
+ rescue LoadError
6
+ require "rubygems"
7
+ require "sinatra"
8
+ require "omniauth"
9
+ require "omniauth-open-edx"
10
+ end
11
+
12
+ use Rack::Session::Cookie
13
+ use OmniAuth::Builder do
14
+ provider :open_edx,
15
+ ENV["OPEN_EDX_OAUTH_CLIENT_ID"],
16
+ ENV["OPEN_EDX_OAUTH_CLIENT_SECRET"],
17
+ {
18
+ scope: "profile email",
19
+ client_options: {
20
+ site: "https://courses.edx.org"
21
+ }
22
+ }
23
+ end
24
+
25
+ get "/" do
26
+ <<-HTML
27
+ <a href='/auth/open_edx'>Sign in with Open edX</a>
28
+ HTML
29
+ end
30
+
31
+ get "/auth/:name/callback" do
32
+ auth = request.env["omniauth.auth"]
33
+ <<-HTML
34
+ <h1>You are logged in as #{auth["info"]["email"]}</h1>
35
+ <div>OmniAuth::AuthHash::InfoHash</div>
36
+ <span>#{auth["info"].to_json}</span>
37
+ HTML
38
+ end
@@ -0,0 +1,2 @@
1
+ require "omniauth-open-edx/version"
2
+ require "omniauth/strategies/open_edx"
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module OpenEdx
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Learn more about the Open edX JWT Oauth2 flow
4
+ # https://github.com/edx/edx-platform/blob/master/openedx/core/djangoapps/oauth_dispatch/docs/decisions/0003-use-jwt-as-oauth-tokens-remove-openid-connect.rst
5
+
6
+ require "omniauth-oauth2"
7
+ require "jwt"
8
+
9
+ module OmniAuth
10
+ module Strategies
11
+ class OpenEdx < OmniAuth::Strategies::OAuth2
12
+ DEFAULT_SCOPE = "profile email"
13
+
14
+ option :name, "open_edx"
15
+ option :client_options,
16
+ site: "https://courses.edx.org",
17
+ authorize_url: "/oauth2/authorize",
18
+ token_url: "/oauth2/access_token"
19
+ option :scope, DEFAULT_SCOPE
20
+ option :authorize_options, [:scope]
21
+
22
+ option :token_options, [:token_type]
23
+ option :token_params, token_type: "jwt"
24
+
25
+ uid { raw_info["sub"] }
26
+
27
+ info do
28
+ {
29
+ name: raw_info["name"],
30
+ email: raw_info["email"],
31
+ username: raw_info["preferred_username"],
32
+ first_name: raw_info["given_name"],
33
+ last_name: raw_info["family_name"]
34
+ }
35
+ end
36
+
37
+ extra { { raw_info: raw_info } }
38
+
39
+ def raw_info
40
+ @raw_info ||= jwt_payload
41
+ end
42
+
43
+ def callback_url
44
+ # overwrite this function from omniauth
45
+ # https://github.com/omniauth/omniauth/blob/c2380ae848ce4e0e39b4bb94c5b8e3fd0a544825/lib/omniauth/strategy.rb#L444
46
+ # edx greatly dislikes when query_string is part of the callback_url
47
+ full_host + callback_path
48
+ end
49
+
50
+ def authorize_params
51
+ super.tap do |params|
52
+ %w[scope].each do |v|
53
+ params[v.to_sym] = request.params[v] if request.params[v]
54
+ end
55
+
56
+ params[:scope] ||= DEFAULT_SCOPE
57
+ end
58
+ end
59
+
60
+ private
61
+
62
+ def jwt_payload
63
+ JWT.decode(access_token.token, nil, false)[0]
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,42 @@
1
+ require_relative "lib/omniauth-open-edx/version"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "omniauth-open-edx"
5
+ spec.version = OmniAuth::OpenEdx::VERSION
6
+ spec.authors = ["Michael Lin"]
7
+ spec.email = ["mlzc@hey.com"]
8
+
9
+ spec.summary = "Open edX strategy for OmniAuth"
10
+ spec.description = "Open edX strategy for OmniAuth"
11
+ spec.homepage = "https://github.com/ibm-skills-network/omniauth-open-edx"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] =
17
+ "https://github.com/ibm-skills-network/omniauth-open-edx"
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files =
22
+ Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject do |f|
24
+ f.match(%r{^(test|spec|features)/})
25
+ end
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_dependency "jwt", ">= 2.0"
32
+ spec.add_dependency "omniauth", [">= 1.9", "< 2"]
33
+ spec.add_dependency "omniauth-oauth2", ">= 1.4"
34
+
35
+ spec.add_development_dependency "bundler", ">= 2.0"
36
+ spec.add_development_dependency "prettier"
37
+ spec.add_development_dependency "rack-test"
38
+ spec.add_development_dependency "rake"
39
+ spec.add_development_dependency "rspec", ">= 3.0"
40
+ spec.add_development_dependency "simplecov"
41
+ spec.add_development_dependency "webmock"
42
+ end
metadata ADDED
@@ -0,0 +1,208 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-open-edx
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Lin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-04-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jwt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: omniauth
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '1.9'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '2'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '1.9'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '2'
47
+ - !ruby/object:Gem::Dependency
48
+ name: omniauth-oauth2
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '1.4'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '1.4'
61
+ - !ruby/object:Gem::Dependency
62
+ name: bundler
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '2.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '2.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: prettier
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rack-test
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rake
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: rspec
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '3.0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '3.0'
131
+ - !ruby/object:Gem::Dependency
132
+ name: simplecov
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ - !ruby/object:Gem::Dependency
146
+ name: webmock
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ type: :development
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ description: Open edX strategy for OmniAuth
160
+ email:
161
+ - mlzc@hey.com
162
+ executables: []
163
+ extensions: []
164
+ extra_rdoc_files: []
165
+ files:
166
+ - ".editorconfig"
167
+ - ".gitignore"
168
+ - ".prettierrc.yml"
169
+ - ".rspec"
170
+ - ".rubocop.yml"
171
+ - Gemfile
172
+ - LICENSE
173
+ - README.md
174
+ - Rakefile
175
+ - bin/console
176
+ - bin/setup
177
+ - examples/sinatra/Gemfile
178
+ - examples/sinatra/app.rb
179
+ - lib/omniauth-open-edx.rb
180
+ - lib/omniauth-open-edx/version.rb
181
+ - lib/omniauth/strategies/open_edx.rb
182
+ - omniauth-open-edx.gemspec
183
+ homepage: https://github.com/ibm-skills-network/omniauth-open-edx
184
+ licenses:
185
+ - MIT
186
+ metadata:
187
+ homepage_uri: https://github.com/ibm-skills-network/omniauth-open-edx
188
+ source_code_uri: https://github.com/ibm-skills-network/omniauth-open-edx
189
+ post_install_message:
190
+ rdoc_options: []
191
+ require_paths:
192
+ - lib
193
+ required_ruby_version: !ruby/object:Gem::Requirement
194
+ requirements:
195
+ - - ">="
196
+ - !ruby/object:Gem::Version
197
+ version: 2.3.0
198
+ required_rubygems_version: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - ">="
201
+ - !ruby/object:Gem::Version
202
+ version: '0'
203
+ requirements: []
204
+ rubygems_version: 3.1.2
205
+ signing_key:
206
+ specification_version: 4
207
+ summary: Open edX strategy for OmniAuth
208
+ test_files: []