omniauth-swoop 0.1.5 → 0.1.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e47bff27db8dc603f3c30e2983518c1a6695266e4c7a29d3404d5895843c3f58
4
- data.tar.gz: 89cfc14d41e10aa4611071b311be486d1ae71a7abadf3d114fa9a5febf9f70da
3
+ metadata.gz: 73289db6ed53654d18e2f9eb61170635d3ca3bb44c11d25903a103e1049a05c0
4
+ data.tar.gz: 92183a1d64ff7e7b4dd32032aab0f3de7032bbd29332a87cc036e475919c7738
5
5
  SHA512:
6
- metadata.gz: 30bd54de5fd21232fd1a9bc6d062481c2b16144d2f174c3b6891df94953642fc17b80ea844281fe8e65e32c0a14e702a3de282256e25cc8ce39494922bc1573a
7
- data.tar.gz: ed33d1c2df631ab694e3655bf874a141d2ed18a9733d7a9e1e948d853111e7351452fb4f1215e92a1474fbbaa17b2655e7ec42d0a43726b729a37119c3584764
6
+ metadata.gz: efe3a6374645bd7f625a1296499d0c9f8dba510a2bc08dfcd415c48d19ca1fd889fe0a55a44b905f2107511e0fe06cc864e5619f2316c37f451b0667189b444b
7
+ data.tar.gz: 9d96523bb978624ac5060586f98b207c63f758f1f1f623cc3b2e1108c38268adc6aa9674bb41e062ac921607e06176941fb97424bab6c771a4fa275165098ec1
@@ -1,2 +1,2 @@
1
1
  require 'omniauth/strategies/swoop'
2
- require 'omniauth/swoop-version'
2
+ require 'omniauth-swoop/version'
@@ -1,5 +1,5 @@
1
1
  module OmniAuth
2
2
  module Swoop
3
- VERSION = "0.1.5"
3
+ VERSION = "0.1.7".freeze
4
4
  end
5
5
  end
@@ -1,11 +1,9 @@
1
1
  require 'omniauth-oauth2'
2
+ require 'jwt'
2
3
 
3
4
  module OmniAuth
4
5
  module Strategies
5
6
  class Swoop < OmniAuth::Strategies::OAuth2
6
-
7
- include OmniAuth::Strategy
8
-
9
7
  option :name, "swoop"
10
8
 
11
9
  option :client_options, {
@@ -14,12 +12,7 @@ module OmniAuth
14
12
  user_info_url: '/oauth2/profile'
15
13
  }
16
14
 
17
- option :user_response_structure, {
18
- attributes: {
19
- email: 'email',
20
- uid: 'sub'
21
- }
22
- }
15
+ option :pkce, true
23
16
 
24
17
  option :authorize_params, {
25
18
  scope: 'email'
@@ -28,15 +21,16 @@ module OmniAuth
28
21
  option :redirect_url
29
22
 
30
23
  uid do
31
- fetch_user_info(user_paths[:id_path]).to_s
24
+ info["uid"]
32
25
  end
33
26
 
34
27
  info do
35
- user_paths[:attributes].inject({}) do |user_hash, (field, path)|
36
- value = fetch_user_info(path)
37
- user_hash[field] = value if value
38
- user_hash
39
- end
28
+ {
29
+ :uid => raw_info['sub'],
30
+ :email => raw_info['email'],
31
+ :user_meta => raw_info['user_meta']
32
+ }
33
+
40
34
  end
41
35
 
42
36
  extra do
@@ -45,26 +39,52 @@ module OmniAuth
45
39
 
46
40
  def raw_info
47
41
  @raw_info ||= access_token.get(options.client_options[:user_info_url]).parsed
48
- @raw_info["id_token"] = access_token.params["id_token"]
42
+ id_token = access_token.params["id_token"]
43
+
44
+ decoded_token = JWT.decode id_token, options.client_secret, true, { algorithm: 'HS256' }
45
+
46
+ if(decoded_token[0].key?("user_meta"))
47
+ @raw_info["user_meta"] = decoded_token[0]["user_meta"]
48
+ end
49
+
50
+ @raw_info["id_token"] = id_token
51
+ @raw_info
49
52
  end
50
53
 
51
54
  def authorize_params
52
55
  params = super
53
- Hash[params.map { |k, v| [k, v.respond_to?(:call) ? v.call(request) : v] }]
54
- end
56
+ p = Hash[params.map { |k, v| [k, v.respond_to?(:call) ? v.call(request) : v] }]
55
57
 
56
- private
58
+ request_params = request.params
59
+ property_meta = {}
60
+ if request_params.key?("property_method")
61
+ property_meta["method"] = request_params["property_method"]
62
+ request_params.delete("property_method")
63
+ end
64
+ if request_params.key?("property_name")
65
+ property_meta["name"] = request_params["property_name"]
66
+ request_params.delete("property_name")
67
+ end
68
+ if request_params.key?("property_logo_url")
69
+ property_meta["logo_url"] = request_params["property_logo_url"]
70
+ request_params.delete("property_logo_url")
71
+ end
72
+ if request_params.key?("property_primary_color")
73
+ property_meta["primary_color"] = request_params["property_primary_color"]
74
+ request_params.delete("property_primary_color")
75
+ end
57
76
 
58
- def user_paths
59
- options.user_response_structure
60
- end
77
+ if property_meta.length > 0
78
+ property_meta = JWT.encode property_meta, options.client_secret, 'HS256'
79
+ p["property_meta"] = property_meta
80
+ end
61
81
 
62
- def fetch_user_info(path)
63
- return nil unless path
64
- full_path = path.is_a?(Array) ? path : Array(user_paths[:root_path]) + [path]
65
- full_path.inject(raw_info) { |info, key| info[key] rescue nil }
82
+ p = p.merge(request_params)
83
+ p
66
84
  end
67
85
 
86
+ private
87
+
68
88
  def callback_url
69
89
  options.redirect_url || (full_host + script_name + callback_path)
70
90
  end
@@ -1,8 +1,12 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "omniauth-swoop/version"
5
+
2
6
  Gem::Specification.new do |s|
3
7
  s.name = 'omniauth-swoop'
4
- s.version = '0.1.5'
5
- s.date = '2021-01-19'
8
+ s.version = OmniAuth::Swoop::VERSION
9
+ s.date = '2021-01-21'
6
10
  s.homepage = "https://github.com/swoop-password-free/omniauth-swoop"
7
11
  s.description = %q{OmniAuth strategy for Swoop passwordless authentication}
8
12
  s.summary = s.description
@@ -14,5 +18,6 @@ Gem::Specification.new do |s|
14
18
  s.require_paths = ["lib"]
15
19
  s.required_ruby_version = Gem::Requirement.new('>= 1.9.3')
16
20
  s.add_dependency 'omniauth-oauth2', '~> 1.7.1'
21
+ s.add_dependency 'jwt', '~> 2.2.2'
17
22
  s.add_development_dependency 'bundler', '~> 1.0'
18
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-swoop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Trebitowski
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-01-19 00:00:00.000000000 Z
12
+ date: 2021-01-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: omniauth-oauth2
@@ -25,6 +25,20 @@ dependencies:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
27
  version: 1.7.1
28
+ - !ruby/object:Gem::Dependency
29
+ name: jwt
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: 2.2.2
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 2.2.2
28
42
  - !ruby/object:Gem::Dependency
29
43
  name: bundler
30
44
  requirement: !ruby/object:Gem::Requirement
@@ -48,8 +62,8 @@ files:
48
62
  - ".gitignore"
49
63
  - README.md
50
64
  - lib/omniauth-swoop.rb
65
+ - lib/omniauth-swoop/version.rb
51
66
  - lib/omniauth/strategies/swoop.rb
52
- - lib/omniauth/swoop-version.rb
53
67
  - omniauth-swoop.gemspec
54
68
  homepage: https://github.com/swoop-password-free/omniauth-swoop
55
69
  licenses: []