databasedotcom-oauth2 0.2.0 → 0.2.1

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.
data/README.md CHANGED
@@ -20,9 +20,11 @@ Specifically, databasedotcom-oauth2:
20
20
  Demos
21
21
  -------
22
22
 
23
- **<a href="https://db-oauth2-sinatra-basic.herokuapp.com" target="_blank">Simple example using Sinatra</a>**&nbsp;&nbsp;<a href="https://github.com/richardvanhook/databasedotcom-oauth2-sinatra-basic" target="_blank">view source on github</a>
23
+ ### Using Sinatra
24
24
 
25
- **<a href="https://db-oauth2-sinatra-jqm.herokuapp.com" target="_blank">In-depth configuration with JQuery Mobile</a>**&nbsp;&nbsp;<a href="https://github.com/richardvanhook/databasedotcom-oauth2-sinatra-jqm" target="_blank">view source on github</a>
25
+ **<a href="https://db-oauth2-sinatra-basic.herokuapp.com" target="_blank">Simple example</a>**&nbsp;&nbsp;<a href="https://github.com/richardvanhook/databasedotcom-oauth2-sinatra-basic" target="_blank">(view source on github)</a>
26
+
27
+ **<a href="https://db-oauth2-sinatra-jqm.herokuapp.com" target="_blank">Advanced configuration with a JQuery Mobile front-end</a>**&nbsp;&nbsp;<a href="https://github.com/richardvanhook/databasedotcom-oauth2-sinatra-jqm" target="_blank">(view source on github)</a>
26
28
 
27
29
  Usage
28
30
  -------
@@ -49,6 +49,7 @@ module Databasedotcom
49
49
  def initialize(app, options = nil)
50
50
  @app = app
51
51
  unless options.nil?
52
+ self.class.symbolize_keys!(options)
52
53
  @endpoints = self.class.sanitize_endpoints(options[:endpoints])
53
54
  @token_encryption_key = options[:token_encryption_key]
54
55
  @path_prefix = options[:path_prefix]
@@ -119,6 +120,7 @@ module Databasedotcom
119
120
  puts "==================\nauthorize phase\n==================\n" if @debugging
120
121
  #determine endpoint via param; but if blank, use default
121
122
  endpoint = request.params["endpoint"] #get endpoint from http param
123
+ endpoint = endpoint.to_sym unless endpoint.nil?
122
124
  keys = @endpoints[endpoint] #if endpoint not found, default will be used
123
125
  endpoint = @endpoints.invert[keys] #re-lookup endpoint in case original param was bogus
124
126
  mydomain = self.class.sanitize_mydomain(request.params["mydomain"])
@@ -127,7 +129,7 @@ module Databasedotcom
127
129
  request.params["state"] ||= "/"
128
130
  state = Addressable::URI.parse(request.params["state"])
129
131
  state.query_values={} unless state.query_values
130
- state.query_values= state.query_values.merge({:endpoint => endpoint})
132
+ state.query_values= state.query_values.merge({:endpoint => endpoint.to_s})
131
133
 
132
134
  puts "(1) endpoint: #{endpoint}\n(2) mydomain: #{mydomain}\n(3) state: #{state.to_str}" if @debugging
133
135
 
@@ -156,7 +158,7 @@ module Databasedotcom
156
158
  auth_params.merge!(overrides)
157
159
 
158
160
  #do redirect
159
- redirect_url = client(mydomain || endpoint, keys[:key], keys[:secret]).auth_code.authorize_url(auth_params)
161
+ redirect_url = client(mydomain || endpoint.to_s, keys[:key], keys[:secret]).auth_code.authorize_url(auth_params)
160
162
  puts "(4) redirecting to #{redirect_url}..." if @debugging
161
163
  redirect redirect_url
162
164
  end
@@ -181,6 +183,7 @@ module Databasedotcom
181
183
  state.query_values= {} if state.query_values.nil?
182
184
  state_params = state.query_values.dup
183
185
  endpoint = state_params.delete("endpoint")
186
+ endpoint = endpoint.to_sym unless endpoint.nil?
184
187
  keys = @endpoints[endpoint]
185
188
  puts "(1) endpoint #{endpoint}" if @debugging
186
189
  puts "(2) keys #{keys}" if @debugging
@@ -190,7 +193,7 @@ module Databasedotcom
190
193
  puts "(3) endpoint: #{endpoint}\nstate: #{state.to_str}\nretrieving token" if @debugging
191
194
 
192
195
  #do callout to retrieve token
193
- access_token = client(endpoint, keys[:key], keys[:secret]).auth_code.get_token(code,
196
+ access_token = client(endpoint.to_s, keys[:key], keys[:secret]).auth_code.get_token(code,
194
197
  :redirect_uri => "#{full_host}#{@path_prefix}/callback")
195
198
  puts "(4) access_token immediatly post get token call #{access_token.inspect}" if @debugging
196
199
 
@@ -315,7 +318,16 @@ module Databasedotcom
315
318
 
316
319
  class << self
317
320
 
321
+ def symbolize_keys!(hash={})
322
+ hash.keys.each do |key|
323
+ value = hash[(key.to_sym rescue key) || key] = hash.delete(key)
324
+ symbolize_keys!(value) if value.is_a?(Hash)
325
+ end
326
+ hash
327
+ end
328
+
318
329
  def parse_domain(url = nil)
330
+ url = url.to_s if url.is_a?(Symbol)
319
331
  unless url.nil?
320
332
  url = "https://" + url if (url =~ /http[s]?:\/\//).nil?
321
333
  begin
@@ -394,4 +406,4 @@ module Databasedotcom
394
406
  end
395
407
 
396
408
  end
397
- end
409
+ end
@@ -1,5 +1,5 @@
1
1
  module Databasedotcom
2
2
  module OAuth2
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: databasedotcom-oauth2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: