omniauth-eklase 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 +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +78 -0
- data/Rakefile +6 -0
- data/bin/console +10 -0
- data/bin/server +39 -0
- data/bin/setup +6 -0
- data/lib/omniauth-eklase.rb +1 -0
- data/lib/omniauth-eklase/form_mime_type_fix_middleware.rb +23 -0
- data/lib/omniauth-eklase/version.rb +5 -0
- data/lib/omniauth/strategies/eklase.rb +62 -0
- data/omniauth-eklase.gemspec +24 -0
- metadata +157 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0c1aa44222e3da647a81c7855d4c27a8b62b0271
|
4
|
+
data.tar.gz: a7073b8cb83dc0389147894f4d92168230098711
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 93296b244d49f61bce0f64e60a764aaa40baed97dd3058bbdac61aa845a03e46dd124c43ec2f7f4ff6ddec7bcfaabd2ea4f3fbe3dbce33757457fef850f87d6d
|
7
|
+
data.tar.gz: 46b6cb772ec1464753fdbb94649a0e6ac208eb9d5645125334bb7ab8eed29ebca92880c870e645b2e7809544e51993f9895c330618e4a9f438095d65c0f0ead6
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Edgars Beigarts
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# OmniAuth e-klase.lv
|
2
|
+
|
3
|
+
[](http://travis-ci.org/mak-it/omniauth-eklase)
|
4
|
+
|
5
|
+
OmniAuth strategy for authenticating to [e-klase.lv](https://www.e-klase.lv/).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add to your `Gemfile`:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'omniauth-eklase'
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
Here's a quick example, adding the middleware to a Rails app
|
18
|
+
in `config/initializers/omniauth.rb`:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
22
|
+
provider :eklase, "CLIENT_ID", "CLIENT_SECRET"
|
23
|
+
end
|
24
|
+
```
|
25
|
+
|
26
|
+
You can also see a simplified Rack example in [bin/server](bin/server).
|
27
|
+
|
28
|
+
## Auth Hash
|
29
|
+
|
30
|
+
Here's an example Auth Hash available in `request.env['omniauth.auth']`:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
{
|
34
|
+
provider: "eklase",
|
35
|
+
uid: "skolens123456789",
|
36
|
+
info: {
|
37
|
+
"id" => "99895d09-a454-4f46-9a26-35b4d038c6fe",
|
38
|
+
"first_name" => "Ivo",
|
39
|
+
"last_name" => "Paraugs",
|
40
|
+
"person_type" => "Student",
|
41
|
+
"user_name" => "skolens123456789",
|
42
|
+
"school_id" => "IDACC-ORG-20111012-BBBF04AC",
|
43
|
+
"school" => "Testa skola",
|
44
|
+
"class_number" => "8",
|
45
|
+
"class_number_postfix" => "b",
|
46
|
+
"class_alias" => "8.b (PĢ)"
|
47
|
+
},
|
48
|
+
credentials: {
|
49
|
+
"token" => "99895d09-a454-4f46-9a26-35b4d038c6fe",
|
50
|
+
"expires_at" => 1452258538,
|
51
|
+
"expires" => true
|
52
|
+
},
|
53
|
+
extra: {
|
54
|
+
raw_info: {
|
55
|
+
"Person" => {
|
56
|
+
"ID" => "99895d09-a454-4f46-9a26-35b4d038c6fe",
|
57
|
+
"FirstName" => "Ivo",
|
58
|
+
"LastName" => "Paraugs",
|
59
|
+
"PersonType" => "Student",
|
60
|
+
"UserName" => "skolens123456789",
|
61
|
+
"SchoolId" => "IDACC-ORG-20111012-BBBF04AC",
|
62
|
+
"School" => "Testa skola",
|
63
|
+
"ClassNumber" => "8",
|
64
|
+
"ClassNumberPostfix" => "b",
|
65
|
+
"ClassAlias" => "8.b (PĢ)"
|
66
|
+
}
|
67
|
+
}
|
68
|
+
}
|
69
|
+
}
|
70
|
+
```
|
71
|
+
|
72
|
+
## Contributing
|
73
|
+
|
74
|
+
1. Fork it ( https://github.com/mak-it/omniauth-eklase/fork )
|
75
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
76
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
77
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
78
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/server
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
unless ENV['CLIENT_ID'] && ENV['CLIENT_SECRET']
|
4
|
+
STDERR.puts "Environment variables CLIENT_ID and CLIENT_SECRET are missing."
|
5
|
+
exit 1
|
6
|
+
end
|
7
|
+
|
8
|
+
require "bundler/setup"
|
9
|
+
require "omniauth-eklase"
|
10
|
+
require "rack"
|
11
|
+
require "byebug"
|
12
|
+
|
13
|
+
class App
|
14
|
+
def call(env)
|
15
|
+
req = Rack::Request.new(env)
|
16
|
+
puts req.path_info
|
17
|
+
case req.path_info
|
18
|
+
when %r{^/$}
|
19
|
+
[200, {"Content-Type" => "text/html"}, ["<a href='/auth/eklase'>Sign in with e-klase</a>"]]
|
20
|
+
when %r{^/auth/eklase/callback}
|
21
|
+
auth = req.env['omniauth.auth']
|
22
|
+
[200, {"Content-Type" => "text/html"}, [auth.to_hash.inspect]]
|
23
|
+
else
|
24
|
+
[404, {"Content-Type" => "text/html"}, ["Not found"]]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
app = Rack::Builder.new do
|
30
|
+
use Rack::CommonLogger
|
31
|
+
use Rack::ShowExceptions
|
32
|
+
use Rack::Session::Cookie
|
33
|
+
use OmniAuth::Builder do
|
34
|
+
provider :eklase, ENV['CLIENT_ID'], ENV['CLIENT_SECRET']
|
35
|
+
end
|
36
|
+
run App.new
|
37
|
+
end
|
38
|
+
|
39
|
+
Rack::Server.start(app: app)
|
data/bin/setup
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'omniauth/strategies/eklase'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module OmniAuth
|
2
|
+
module Eklase
|
3
|
+
# Override the content-type of the response
|
4
|
+
# with "application/x-www-form-urlencoded"
|
5
|
+
# if the response body looks like it might be a query, e.g.
|
6
|
+
#
|
7
|
+
# access_token=74e81934-2a6c-4b91-8e76-f9a616223ed9&expires=3600
|
8
|
+
#
|
9
|
+
class FormMimeTypeFixMiddleware < Faraday::Middleware
|
10
|
+
CONTENT_TYPE = 'Content-Type'.freeze
|
11
|
+
MIME_TYPE = 'application/x-www-form-urlencoded'.freeze
|
12
|
+
QUERY_REGEX = /^(\&?[\w\_]+\=[\w\_\-]+)+$/
|
13
|
+
|
14
|
+
def call(request_env)
|
15
|
+
@app.call(request_env).on_complete do |response_env|
|
16
|
+
if response_env[:body].to_s =~ QUERY_REGEX
|
17
|
+
response_env[:response_headers][CONTENT_TYPE] = MIME_TYPE
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require "omniauth-oauth2"
|
2
|
+
require "omniauth-eklase/version"
|
3
|
+
require "omniauth-eklase/form_mime_type_fix_middleware"
|
4
|
+
|
5
|
+
module OmniAuth
|
6
|
+
module Strategies
|
7
|
+
class Eklase < OmniAuth::Strategies::OAuth2
|
8
|
+
option :name, "eklase"
|
9
|
+
|
10
|
+
option :client_options,
|
11
|
+
site: "https://login.e-klase.lv",
|
12
|
+
authorize_url: '/Auth/OAuth/',
|
13
|
+
token_url: '/Auth/OAuth/GetAccessToken/',
|
14
|
+
token_method: :get
|
15
|
+
|
16
|
+
uid { info["user_name"] }
|
17
|
+
|
18
|
+
info do
|
19
|
+
raw_info["Person"].inject({}) do |h, (k, v)|
|
20
|
+
h[underscore(k)] = v
|
21
|
+
h
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
extra do
|
26
|
+
{ raw_info: raw_info }
|
27
|
+
end
|
28
|
+
|
29
|
+
# Log everything.
|
30
|
+
# Fix content-type for query string responses.
|
31
|
+
def client
|
32
|
+
super.tap do |c|
|
33
|
+
c.connection.response :logger, OmniAuth.logger
|
34
|
+
c.connection.use OmniAuth::Eklase::FormMimeTypeFixMiddleware
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# The callback should match the redirect_uri that was passed
|
39
|
+
# in request phase, so ?code=:code must be removed.
|
40
|
+
def callback_url
|
41
|
+
full_host + script_name + callback_path
|
42
|
+
end
|
43
|
+
|
44
|
+
def raw_info
|
45
|
+
@raw_info ||= begin
|
46
|
+
response = access_token.get("/Auth/OAuth/API/Me?access_token=#{access_token.token}")
|
47
|
+
MultiXml.parse(response.body)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def underscore(str)
|
54
|
+
str.
|
55
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
56
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
57
|
+
tr("-", "_").
|
58
|
+
downcase
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path('../lib/omniauth-eklase/version', __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "omniauth-eklase"
|
5
|
+
spec.version = Omniauth::Eklase::VERSION
|
6
|
+
spec.authors = ["Edgars Beigarts"]
|
7
|
+
spec.email = ["edgars.beigarts@gmail.com"]
|
8
|
+
spec.description = "e-klase.lv strategy for OmniAuth."
|
9
|
+
spec.summary = spec.description
|
10
|
+
spec.homepage = "https://github.com/mak-it/omniauth-eklase"
|
11
|
+
spec.license = "MIT"
|
12
|
+
|
13
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
14
|
+
spec.require_paths = ["lib"]
|
15
|
+
|
16
|
+
spec.add_runtime_dependency "omniauth-oauth2", "~> 1.2"
|
17
|
+
|
18
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
19
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
20
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
21
|
+
spec.add_development_dependency "byebug", "~> 8.0"
|
22
|
+
spec.add_development_dependency "webmock", '~> 1.0'
|
23
|
+
spec.add_development_dependency "rack-test"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-eklase
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Edgars Beigarts
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: omniauth-oauth2
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.11'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.11'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '8.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '8.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rack-test
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: e-klase.lv strategy for OmniAuth.
|
112
|
+
email:
|
113
|
+
- edgars.beigarts@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".travis.yml"
|
121
|
+
- Gemfile
|
122
|
+
- LICENSE.txt
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- bin/console
|
126
|
+
- bin/server
|
127
|
+
- bin/setup
|
128
|
+
- lib/omniauth-eklase.rb
|
129
|
+
- lib/omniauth-eklase/form_mime_type_fix_middleware.rb
|
130
|
+
- lib/omniauth-eklase/version.rb
|
131
|
+
- lib/omniauth/strategies/eklase.rb
|
132
|
+
- omniauth-eklase.gemspec
|
133
|
+
homepage: https://github.com/mak-it/omniauth-eklase
|
134
|
+
licenses:
|
135
|
+
- MIT
|
136
|
+
metadata: {}
|
137
|
+
post_install_message:
|
138
|
+
rdoc_options: []
|
139
|
+
require_paths:
|
140
|
+
- lib
|
141
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
requirements: []
|
152
|
+
rubyforge_project:
|
153
|
+
rubygems_version: 2.2.2
|
154
|
+
signing_key:
|
155
|
+
specification_version: 4
|
156
|
+
summary: e-klase.lv strategy for OmniAuth.
|
157
|
+
test_files: []
|