omniauth-yufu 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 76ddd953d6f1345dc483922005bc63382d8946d2
4
+ data.tar.gz: 4278ae6657a3a9bb8ab49d6f69bd6d75a8f4fad7
5
+ SHA512:
6
+ metadata.gz: 77055750c6bf2eebb9b76abc5b71ebc0abfcef446ffbb43e3ee89d4cd9ba84273c221a0a78a7780efac91b3e3b10f10ad5d5e54294bc60bf69f6e86cbf184f49
7
+ data.tar.gz: c3c870fb8b3b0956482c55c17c477f11195f591d2bf4edd26270ddee165ea55462854fa0be844389dd3c64abd4d636f3422e54d1d12562f3228781d13ba45a1c
data/.DS_Store ADDED
Binary file
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - jruby-19mode
6
+ - rbx-19mode
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-yufu.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Michael Bleigh
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # OmniAuth::Yufu
2
+
3
+ OmniAuth::Yufu provides a clean, simple wrapper on top of JWT so that you can easily implement this kind
4
+ of SSO either between your own applications or allow third parties to delegate authentication.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'omniauth-yufu'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install omniauth-yufu
19
+
20
+ ## Usage
21
+
22
+ You use OmniAuth::Yufu just like you do any other OmniAuth strategy:
23
+
24
+ ```ruby
25
+ use OmniAuth::Yufu, 'PUBLIC_KEY', auth_url: 'http://example.com/login'
26
+ ```
27
+
28
+ ### Authentication Process
29
+
30
+ When you authenticate through `omniauth-jwt` you can send users to `/auth/jwt` and it will redirect
31
+ them to the URL specified in the `auth_url` option. From there, the provider must generate a JWT
32
+ and send it to the `/auth/jwt/callback` URL as a "jwt" parameter:
33
+
34
+ /auth/jwt/callback?jwt=ENCODEDJWTGOESHERE
35
+
36
+ The `sub` of the jwt should be the unique email address of the tenant users
37
+
38
+ An example of how to do that in Sinatra:
39
+
40
+ ```ruby
41
+ require 'jwt'
42
+
43
+ get '/login/sso/other-app' do
44
+ # assuming the user is already logged in and this is available as current_user
45
+ claims = {
46
+ id: current_user.id,
47
+ name: current_user.name,
48
+ email: current_user.email,
49
+ iat: Time.now.to_i
50
+ }
51
+
52
+ payload = JWT.encode(claims, ENV['PUBLIC_KEY'])
53
+ redirect "http://other-app.com/auth/jwt/callback?jwt=#{payload}"
54
+ end
55
+ ```
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
data/lib/.DS_Store ADDED
Binary file
Binary file
@@ -0,0 +1,53 @@
1
+ require 'omniauth'
2
+ require 'jwt'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class Yufu
7
+ class ClaimInvalid < StandardError; end
8
+
9
+ include OmniAuth::Strategy
10
+
11
+ args [:public_key]
12
+
13
+ option :public_key, nil
14
+ option :uid_field, 'sub'
15
+ option :required_claims, %w()
16
+ option :info_map, {"name" => "name", "email" => "email"}
17
+ option :auth_url, nil
18
+
19
+ def request_phase
20
+ redirect options.auth_url
21
+ end
22
+
23
+ def decoded
24
+ public_key = String.class_eval(%Q("#{options.public_key}"))
25
+ @decoded ||= ::JWT.decode(request.params['id_token'], OpenSSL::PKey::RSA.new(public_key))
26
+ (options.required_claims || []).each do |field|
27
+ raise ClaimInvalid.new("Missing required '#{field}' claim.") if !@decoded[0].key?(field.to_s)
28
+ end
29
+ raise ClaimInvalid.new("Missing required 'iat' claim.") if options.valid_within && !@decoded["iat"]
30
+ @decoded
31
+ end
32
+
33
+ def callback_phase
34
+ super
35
+ rescue ClaimInvalid => e
36
+ fail! :claim_invalid, e
37
+ end
38
+
39
+ uid do
40
+ decoded[0][options.uid_field]
41
+ end
42
+
43
+ extra do
44
+ {:raw_info => decoded[0]}
45
+ end
46
+
47
+ info do
48
+ # email is required by gitlab
49
+ {:email => decoded[0][options.uid_field]}
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,2 @@
1
+ require "omniauth/yufu/version"
2
+ require "omniauth/strategies/yufu"
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module Yufu
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'omniauth/yufu/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "omniauth-yufu"
8
+ spec.version = Omniauth::Yufu::VERSION
9
+ spec.authors = ["Zheng Li"]
10
+ spec.email = ["312528341@qq.com"]
11
+ spec.description = %q{An OmniAuth strategy to accept JWT-based single sign-on. Let the Ruby service provide to accetp the Yufu JWT idtonken.}
12
+ spec.summary = %q{An OmniAuth strategy to accept JWT-based single sign-on.}
13
+ spec.homepage = "http://github.com/SweenEy1130/omniauth-yufu"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake", '~> 0'
23
+ spec.add_development_dependency "rspec", '~> 0'
24
+ spec.add_development_dependency "guard", '~> 0'
25
+ spec.add_development_dependency "guard-rspec", '~> 0'
26
+ spec.add_development_dependency "rack-test", '~> 0'
27
+
28
+ spec.add_dependency "jwt"
29
+ spec.add_dependency "omniauth", "~> 1.1"
30
+ end
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-yufu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Zheng Li
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-11-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
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: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
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: guard
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: guard-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: rack-test
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: jwt
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: omniauth
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.1'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.1'
125
+ description: An OmniAuth strategy to accept JWT-based single sign-on. Let the Ruby
126
+ service provide to accetp the Yufu JWT idtonken.
127
+ email:
128
+ - 312528341@qq.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".DS_Store"
134
+ - ".rspec"
135
+ - ".travis.yml"
136
+ - Gemfile
137
+ - LICENSE.txt
138
+ - README.md
139
+ - Rakefile
140
+ - lib/.DS_Store
141
+ - lib/omniauth/.DS_Store
142
+ - lib/omniauth/strategies/yufu.rb
143
+ - lib/omniauth/yufu.rb
144
+ - lib/omniauth/yufu/version.rb
145
+ - omniauth-yufu.gemspec
146
+ homepage: http://github.com/SweenEy1130/omniauth-yufu
147
+ licenses:
148
+ - MIT
149
+ metadata: {}
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ requirements: []
165
+ rubyforge_project:
166
+ rubygems_version: 2.5.1
167
+ signing_key:
168
+ specification_version: 4
169
+ summary: An OmniAuth strategy to accept JWT-based single sign-on.
170
+ test_files: []