omniauth-swagger 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c266f0f11e17f0aeb7f34f1b3f2971ef18206ffa
4
- data.tar.gz: 0f9c87ee827001095f6b367bc38a44735dc0c97f
3
+ metadata.gz: e9d3e6a898c3f01e4e7dadf5346a80eadb9f1b43
4
+ data.tar.gz: 2864dd4622faf11d5446adc016fed566085001d6
5
5
  SHA512:
6
- metadata.gz: d87d183a03d750de7271d8d779ba6f639417f77074c0cc1e0e73bdbb4da598c2d6e2ca22cf1821123029d5ed0bf1f5c891a4da319e74f8626c514a870beb329f
7
- data.tar.gz: 7b16a79d6f61e3647591941afe6060e2ca74418b6ec735da239fedc9b3cdad0f98f82ff8dc46594623c9866deff0400c3b21cb70db22cf919965ce99a10c715a
6
+ metadata.gz: 72f09e591ba504b9a0f14ca04965a38105d427555cc5753fef031b529d292b2ae98849600dcfb24fb6a98caf737b26fc4675b25650edb8be198279b7fc65245e
7
+ data.tar.gz: b86613fb5f762a38df03cdd986f92a390eaf2cc8c244c2f50292b81620caab42bf4ae7e9f99448427b95fec568922c9cd6e2439480e7922b3b2b31f9ce17215e
@@ -1,7 +1,8 @@
1
1
  require 'omniauth-oauth2'
2
2
  require 'omniauth/swagger/oauth2_definition'
3
3
  require 'omniauth/swagger/default_provider_lookup'
4
- require 'diesel'
4
+ require 'omniauth/swagger/uid_options'
5
+ require 'apiture'
5
6
 
6
7
  module OmniAuth
7
8
  module Strategies
@@ -9,8 +10,6 @@ module OmniAuth
9
10
  class Swagger < OmniAuth::Strategies::OAuth2
10
11
 
11
12
  OPTION_UID = 'uid'.freeze
12
- OPTION_UID_API = 'api'.freeze
13
- OPTION_UID_PARAM = 'param'.freeze
14
13
  OPTION_SPECIFICATION = 'specification'.freeze
15
14
  OPTION_SUBDOMAIN = 'subdomain'.freeze
16
15
 
@@ -44,17 +43,25 @@ module OmniAuth
44
43
  end
45
44
 
46
45
  uid do
47
- if uid_api
48
- operation, key = uid_api.split('#')
49
- value = key.split('.').reduce(raw_info) { |memo, key| memo[key] }
50
- value.to_s
51
- else
52
- uid_option = provider_options[OPTION_UID]
53
- if uid_option[OPTION_UID_PARAM]
54
- access_token.params[uid_option[OPTION_UID_PARAM]]
46
+ if uid_options.nil?
47
+ raise "Missing #{OPTION_UID} setting for provider '#{provider_name}'"
48
+
49
+ elsif uid_options.api?
50
+ val = uid_options.
51
+ api_value_path.
52
+ split('.').
53
+ reduce(raw_info) { |memo, key| memo && memo[key] }
54
+ if val
55
+ val.to_s
55
56
  else
56
- raise "Unsupported UID option: #{uid_option.inspect}"
57
+ raise "Invalid UID value path #{uid_options.api_value_path}: #{raw_info.inspect}"
57
58
  end
59
+
60
+ elsif uid_options.access_token_param?
61
+ access_token.params[uid_options.param]
62
+
63
+ else
64
+ raise "Unsupported UID option: #{provider_options[OPTION_UID].inspect}"
58
65
  end
59
66
  end
60
67
 
@@ -64,7 +71,12 @@ module OmniAuth
64
71
 
65
72
  protected
66
73
  def provider_name
67
- @provider_name ||= request.params[options[:provider_param]].to_sym
74
+ @provider_name ||= begin
75
+ unless nm = request.params[options[:provider_param]]
76
+ raise OmniAuth::Error, "Unable to determine provider"
77
+ end
78
+ nm.to_sym
79
+ end
68
80
  end
69
81
 
70
82
  def provider_options
@@ -85,21 +97,19 @@ module OmniAuth
85
97
  end
86
98
  end
87
99
 
88
- def uid_api
89
- opt = provider_options[OPTION_UID]
90
- opt.kind_of?(Hash) ? opt[OPTION_UID_API] : opt
100
+ def uid_options
101
+ @uid_options ||= OmniAuth::Swagger::UIDOptions.from_options(provider_options[OPTION_UID])
91
102
  end
92
103
 
93
104
  def raw_info
94
- if uid_api
105
+ if uid_options
95
106
  api_options = {@definition.oauth2_key => {token: access_token.token}}
96
107
  if provider_options[OPTION_SUBDOMAIN]
97
108
  api_options[:subdomain] = provider_options[OPTION_SUBDOMAIN]
98
109
  end
99
- api_class = Diesel.build_api(specification)
110
+ api_class = Apiture.build_api(specification)
100
111
  api = api_class.new(api_options)
101
- operation, key = uid_api.split('#')
102
- api.__send__(operation, {})
112
+ api.__send__(uid_options.api_operation, uid_options.api_params).body
103
113
  else
104
114
  {}
105
115
  end
@@ -30,7 +30,7 @@ module OmniAuth
30
30
  opts[OmniAuth::Strategies::Swagger::OPTION_SPECIFICATION] = Proc.new{
31
31
  spec = nil
32
32
  open(uri) do |f|
33
- spec = Diesel::Swagger::Parser.new.parse(f)
33
+ spec = Apiture::Swagger::Parser.new.parse(f)
34
34
  end
35
35
  spec
36
36
  }
@@ -0,0 +1,45 @@
1
+ module OmniAuth
2
+ module Swagger
3
+ class UIDOptions
4
+
5
+ OPTION_API = 'api'.freeze
6
+ OPTION_API_PARAMS = 'api_params'.freeze
7
+ OPTION_PARAM = 'param'.freeze
8
+
9
+ attr_accessor :api, :api_params, :param
10
+
11
+ def self.from_options(opts)
12
+ return nil if opts.nil?
13
+ unless opts.kind_of?(Hash)
14
+ opts = {OPTION_API => opts}
15
+ end
16
+ uid_options = new
17
+ uid_options.api = opts[OPTION_API]
18
+ uid_options.api_params = opts[OPTION_API_PARAMS]
19
+ uid_options.param = opts[OPTION_PARAM]
20
+ uid_options
21
+ end
22
+
23
+ def api?
24
+ api != nil
25
+ end
26
+
27
+ def access_token_param?
28
+ param != nil
29
+ end
30
+
31
+ def api_value_path
32
+ @api_value_path ||= api.split("#")[1]
33
+ end
34
+
35
+ def api_operation
36
+ @api_operation ||= api.split("#").first
37
+ end
38
+
39
+ def api_params
40
+ @api_params || {}
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -1,5 +1,5 @@
1
1
  module Omniauth
2
2
  module Swagger
3
- VERSION = "0.1.3"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -23,5 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
 
25
25
  spec.add_dependency "omniauth-oauth2", "~> 1.3.0"
26
- spec.add_dependency "diesel-api-dsl", ">= 0.1.5"
26
+ spec.add_dependency "apiture", "~> 0.2.3"
27
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-swagger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Calvin Yu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-04 00:00:00.000000000 Z
11
+ date: 2016-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -53,19 +53,19 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: 1.3.0
55
55
  - !ruby/object:Gem::Dependency
56
- name: diesel-api-dsl
56
+ name: apiture
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.1.5
61
+ version: 0.2.3
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.1.5
68
+ version: 0.2.3
69
69
  description: Uses a spec's security definition information to build the oauth2 strategy
70
70
  email:
71
71
  - me@sourcebender.com
@@ -99,6 +99,7 @@ files:
99
99
  - lib/omniauth/swagger/oauth2_definition.rb
100
100
  - lib/omniauth/swagger/provider_defaults.rb
101
101
  - lib/omniauth/swagger/providers.yml
102
+ - lib/omniauth/swagger/uid_options.rb
102
103
  - lib/omniauth/swagger/version.rb
103
104
  - omniauth-swagger.gemspec
104
105
  homepage: http://github.com/incominghq/omniauth-swagger