oa-more 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,5 +4,6 @@ module OmniAuth
4
4
  module Strategies
5
5
  autoload :WindowsLive, 'omniauth/strategies/windows_live'
6
6
  autoload :Flickr, 'omniauth/strategies/flickr'
7
+ autoload :Yupoo, 'omniauth/strategies/yupoo'
7
8
  end
8
9
  end
@@ -14,7 +14,7 @@ module OmniAuth
14
14
  class Flickr
15
15
  include OmniAuth::Strategy
16
16
  attr_accessor :api_key, :secret_key, :options
17
-
17
+
18
18
  # error catching, based on OAuth2 callback
19
19
  class CallbackError < StandardError
20
20
  attr_accessor :error, :error_reason
@@ -36,30 +36,30 @@ module OmniAuth
36
36
  end
37
37
 
38
38
  protected
39
-
39
+
40
40
  def request_phase
41
41
  params = { :api_key => api_key, :perms => options[:scope] }
42
42
  params[:api_sig] = flickr_sign(params)
43
43
  query_string = params.collect{ |key,value| "#{key}=#{Rack::Utils.escape(value)}" }.join('&')
44
44
  redirect "http://flickr.com/services/auth/?#{query_string}"
45
45
  end
46
-
46
+
47
47
  def callback_phase
48
48
  params = { :api_key => api_key, :method => 'flickr.auth.getToken', :frob => request.params['frob'], :format => 'json', :nojsoncallback => '1' }
49
49
  params[:api_sig] = flickr_sign(params)
50
-
50
+
51
51
  response = RestClient.get('http://api.flickr.com/services/rest/', { :params => params })
52
52
  auth = MultiJson.decode(response.to_s)
53
53
  raise CallbackError.new(auth['code'],auth['message']) if auth['stat'] == 'fail'
54
-
54
+
55
55
  @user = auth['auth']['user']
56
56
  @access_token = auth['auth']['token']['_content']
57
-
57
+
58
58
  super
59
59
  rescue CallbackError => e
60
60
  fail!(:invalid_response, e)
61
61
  end
62
-
62
+
63
63
  def auth_hash
64
64
  OmniAuth::Utils.deep_merge(super, {
65
65
  'uid' => @user['nsid'],
@@ -68,7 +68,7 @@ module OmniAuth
68
68
  'extra' => { 'user_hash' => @user }
69
69
  })
70
70
  end
71
-
71
+
72
72
  def user_info
73
73
  name = @user['fullname']
74
74
  name = @user['username'] if name.nil? || name.empty?
@@ -77,7 +77,7 @@ module OmniAuth
77
77
  'name' => name,
78
78
  }
79
79
  end
80
-
80
+
81
81
  def flickr_sign(params)
82
82
  Digest::MD5.hexdigest(secret_key + params.sort{|a,b| a[0].to_s <=> b[0].to_s }.flatten.join)
83
83
  end
@@ -5,9 +5,9 @@ module OmniAuth
5
5
  module Strategies
6
6
  class WindowsLive
7
7
  include OmniAuth::Strategy
8
-
8
+
9
9
  attr_accessor :app_id, :app_secret
10
-
10
+
11
11
  # Initialize the strategy by providing
12
12
  #
13
13
  # @param app_id [String] The application ID from your registered app with Microsoft.
@@ -1,9 +1,9 @@
1
1
  #######################################################################
2
- # FILE: windowslivelogin.rb
3
- #
4
- # DESCRIPTION: Sample implementation of Web Authentication and
5
- # Delegated Authentication protocol in Ruby. Also
6
- # includes trusted sign-in and application verification
2
+ # FILE: windowslivelogin.rb
3
+ #
4
+ # DESCRIPTION: Sample implementation of Web Authentication and
5
+ # Delegated Authentication protocol in Ruby. Also
6
+ # includes trusted sign-in and application verification
7
7
  # sample implementations.
8
8
  #
9
9
  # VERSION: 1.1
@@ -26,7 +26,7 @@ module OmniAuth; module Strategies; class WindowsLive; class WindowsLiveLogin
26
26
  # By default, debug information will be printed to the standard
27
27
  # error output and should be visible in the web server logs.
28
28
  #####################################################################
29
- def setDebug(flag)
29
+ def setDebug(flag)
30
30
  @debug = flag
31
31
  end
32
32
 
@@ -39,7 +39,7 @@ module OmniAuth; module Strategies; class WindowsLive; class WindowsLiveLogin
39
39
  return unless @debug
40
40
  return if error.nil? or error.empty?
41
41
  warn("Windows Live ID Authentication SDK #{error}")
42
- nil
42
+ nil
43
43
  end
44
44
 
45
45
  #####################################################################
@@ -52,7 +52,7 @@ module OmniAuth; module Strategies; class WindowsLive; class WindowsLiveLogin
52
52
 
53
53
  #####################################################################
54
54
  # Initialize the WindowsLiveLogin module with the application ID,
55
- # secret key, and security algorithm.
55
+ # secret key, and security algorithm.
56
56
  #
57
57
  # We recommend that you employ strong measures to protect the
58
58
  # secret key. The secret key should never be exposed to the Web
@@ -65,16 +65,16 @@ module OmniAuth; module Strategies; class WindowsLive; class WindowsLiveLogin
65
65
  # For Delegated Authentication, you may optionally specify the
66
66
  # privacy policy URL and return URL. If you do not specify these
67
67
  # values here, the default values that you specified when you
68
- # registered your application will be used.
68
+ # registered your application will be used.
69
69
  #
70
70
  # The 'force_delauth_nonprovisioned' flag also indicates whether
71
- # your application is registered for Delegated Authentication
72
- # (that is, whether it uses an application ID and secret key). We
73
- # recommend that your Delegated Authentication application always
71
+ # your application is registered for Delegated Authentication
72
+ # (that is, whether it uses an application ID and secret key). We
73
+ # recommend that your Delegated Authentication application always
74
74
  # be registered for enhanced security and functionality.
75
75
  #####################################################################
76
- def initialize(appid=nil, secret=nil, securityalgorithm=nil,
77
- force_delauth_nonprovisioned=nil,
76
+ def initialize(appid=nil, secret=nil, securityalgorithm=nil,
77
+ force_delauth_nonprovisioned=nil,
78
78
  policyurl=nil, returnurl=nil)
79
79
  self.force_delauth_nonprovisioned = force_delauth_nonprovisioned
80
80
  self.appid = appid if appid
@@ -85,7 +85,7 @@ module OmniAuth; module Strategies; class WindowsLive; class WindowsLiveLogin
85
85
  end
86
86
 
87
87
  #####################################################################
88
- # Initialize the WindowsLiveLogin module from a settings file.
88
+ # Initialize the WindowsLiveLogin module from a settings file.
89
89
  #
90
90
  # 'settingsFile' specifies the location of the XML settings file
91
91
  # that contains the application ID, secret key, and security
@@ -102,7 +102,7 @@ module OmniAuth; module Strategies; class WindowsLive; class WindowsLiveLogin
102
102
  # Delegated Authentication samples.
103
103
  #
104
104
  # We recommend that you store the WindowsLiveLogin settings file
105
- # in an area on your server that cannot be accessed through the
105
+ # in an area on your server that cannot be accessed through the
106
106
  # Internet. This file contains important confidential information.
107
107
  #####################################################################
108
108
  def self.initFromXml(settingsFile)
@@ -110,7 +110,7 @@ module OmniAuth; module Strategies; class WindowsLive; class WindowsLiveLogin
110
110
  settings = o.parseSettings(settingsFile)
111
111
 
112
112
  o.setDebug(settings['debug'] == 'true')
113
- o.force_delauth_nonprovisioned =
113
+ o.force_delauth_nonprovisioned =
114
114
  (settings['force_delauth_nonprovisioned'] == 'true')
115
115
 
116
116
  o.appid = settings['appid']
@@ -133,7 +133,7 @@ module OmniAuth; module Strategies; class WindowsLive; class WindowsLiveLogin
133
133
  def appid=(appid)
134
134
  if (appid.nil? or appid.empty?)
135
135
  return if force_delauth_nonprovisioned
136
- fatal("Error: appid: Null application ID.")
136
+ fatal("Error: appid: Null application ID.")
137
137
  end
138
138
  if (not appid =~ /^\w+$/)
139
139
  fatal("Error: appid: Application ID must be alpha-numeric: " + appid)
@@ -142,7 +142,7 @@ module OmniAuth; module Strategies; class WindowsLive; class WindowsLiveLogin
142
142
  end
143
143
 
144
144
  #####################################################################
145
- # Returns the application ID.
145
+ # Returns the application ID.
146
146
  #####################################################################
147
147
  def appid
148
148
  if (@appid.nil? or @appid.empty?)
@@ -158,10 +158,10 @@ module OmniAuth; module Strategies; class WindowsLive; class WindowsLiveLogin
158
158
  def secret=(secret)
159
159
  if (secret.nil? or secret.empty?)
160
160
  return if force_delauth_nonprovisioned
161
- fatal("Error: secret=: Secret must be non-null.")
161
+ fatal("Error: secret=: Secret must be non-null.")
162
162
  end
163
163
  if (secret.size < 16)
164
- fatal("Error: secret=: Secret must be at least 16 characters.")
164
+ fatal("Error: secret=: Secret must be at least 16 characters.")
165
165
  end
166
166
  @signkey = derive(secret, "SIGNATURE")
167
167
  @cryptkey = derive(secret, "ENCRYPTION")
@@ -171,20 +171,20 @@ module OmniAuth; module Strategies; class WindowsLive; class WindowsLiveLogin
171
171
  # Sets your old secret key.
172
172
  #
173
173
  # Use this property to set your old secret key if you are in the
174
- # process of transitioning to a new secret key. You may need this
175
- # property because the Windows Live ID servers can take up to
176
- # 24 hours to propagate a new secret key after you have updated
174
+ # process of transitioning to a new secret key. You may need this
175
+ # property because the Windows Live ID servers can take up to
176
+ # 24 hours to propagate a new secret key after you have updated
177
177
  # your application settings.
178
178
  #
179
179
  # If an old secret key is specified here and has not expired
180
180
  # (as determined by the oldsecretexpiry setting), it will be used
181
- # as a fallback if token decryption fails with the new secret
181
+ # as a fallback if token decryption fails with the new secret
182
182
  # key.
183
183
  #####################################################################
184
184
  def oldsecret=(secret)
185
185
  return if (secret.nil? or secret.empty?)
186
186
  if (secret.size < 16)
187
- fatal("Error: oldsecret=: Secret must be at least 16 characters.")
187
+ fatal("Error: oldsecret=: Secret must be at least 16 characters.")
188
188
  end
189
189
  @oldsignkey = derive(secret, "SIGNATURE")
190
190
  @oldcryptkey = derive(secret, "ENCRYPTION")
@@ -197,7 +197,7 @@ module OmniAuth; module Strategies; class WindowsLive; class WindowsLiveLogin
197
197
  # used even if token decryption fails with the new secret key.
198
198
  #
199
199
  # The old secret expiry time is represented as the number of seconds
200
- # elapsed since January 1, 1970.
200
+ # elapsed since January 1, 1970.
201
201
  #####################################################################
202
202
  def oldsecretexpiry=(timestamp)
203
203
  return if (timestamp.nil? or timestamp.empty?)
@@ -255,10 +255,10 @@ module OmniAuth; module Strategies; class WindowsLive; class WindowsLiveLogin
255
255
  end
256
256
 
257
257
  #####################################################################
258
- # Sets the return URL--the URL on your site to which the consent
259
- # service redirects users (along with the action, consent token,
260
- # and application context) after they have successfully provided
261
- # consent information for Delegated Authentication. This value will
258
+ # Sets the return URL--the URL on your site to which the consent
259
+ # service redirects users (along with the action, consent token,
260
+ # and application context) after they have successfully provided
261
+ # consent information for Delegated Authentication. This value will
262
262
  # override the return URL specified during registration.
263
263
  #####################################################################
264
264
  def returnurl=(returnurl)
@@ -281,7 +281,7 @@ module OmniAuth; module Strategies; class WindowsLive; class WindowsLiveLogin
281
281
 
282
282
  #####################################################################
283
283
  # Sets or gets the base URL to use for the Windows Live Login server. You
284
- # should not have to change this property. Furthermore, we recommend
284
+ # should not have to change this property. Furthermore, we recommend
285
285
  # that you use the Sign In control instead of the URL methods
286
286
  # provided here.
287
287
  #####################################################################
@@ -296,7 +296,7 @@ module OmniAuth; module Strategies; class WindowsLive; class WindowsLiveLogin
296
296
  end
297
297
 
298
298
  #####################################################################
299
- # Sets or gets the secure (HTTPS) URL to use for the Windows Live Login
299
+ # Sets or gets the secure (HTTPS) URL to use for the Windows Live Login
300
300
  # server. You should not have to change this property.
301
301
  #####################################################################
302
302
  attr_accessor :secureurl
@@ -310,7 +310,7 @@ module OmniAuth; module Strategies; class WindowsLive; class WindowsLiveLogin
310
310
  end
311
311
 
312
312
  #####################################################################
313
- # Sets or gets the Consent Base URL to use for the Windows Live Consent
313
+ # Sets or gets the Consent Base URL to use for the Windows Live Consent
314
314
  # server. You should not have to use or change this property directly.
315
315
  #####################################################################
316
316
  attr_accessor :consenturl
@@ -329,9 +329,9 @@ end
329
329
  #######################################################################
330
330
  class WindowsLiveLogin
331
331
  #####################################################################
332
- # Returns the sign-in URL to use for the Windows Live Login server.
332
+ # Returns the sign-in URL to use for the Windows Live Login server.
333
333
  # We recommend that you use the Sign In control instead.
334
- #
334
+ #
335
335
  # If you specify it, 'context' will be returned as-is in the sign-in
336
336
  # response for site-specific use.
337
337
  #####################################################################
@@ -344,7 +344,7 @@ class WindowsLiveLogin
344
344
  end
345
345
 
346
346
  #####################################################################
347
- # Returns the sign-out URL to use for the Windows Live Login server.
347
+ # Returns the sign-out URL to use for the Windows Live Login server.
348
348
  # We recommend that you use the Sign In control instead.
349
349
  #####################################################################
350
350
  def getLogoutUrl(market=nil)
@@ -360,8 +360,8 @@ class WindowsLiveLogin
360
360
  # 'id' is the pairwise unique ID for the user.
361
361
  # 'context' is the application context that was originally passed to
362
362
  # the sign-in request, if any.
363
- # 'token' is the encrypted Web Authentication token that contains the
364
- # UID. This can be cached in a cookie and the UID can be retrieved by
363
+ # 'token' is the encrypted Web Authentication token that contains the
364
+ # UID. This can be cached in a cookie and the UID can be retrieved by
365
365
  # calling the processToken method.
366
366
  # 'usePersistentCookie?' indicates whether the application is
367
367
  # expected to store the user token in a session or persistent
@@ -373,8 +373,8 @@ class WindowsLiveLogin
373
373
  def usePersistentCookie?
374
374
  @usePersistentCookie
375
375
  end
376
-
377
-
376
+
377
+
378
378
  #####################################################################
379
379
  # Initialize the User with time stamp, userid, flags, context and token.
380
380
  #####################################################################
@@ -426,7 +426,7 @@ class WindowsLiveLogin
426
426
  # returned by CGI.params or Rails. (The unprocessed POST string
427
427
  # could also be used here but we do not recommend it).
428
428
  #
429
- # This method returns a User object on successful sign-in; otherwise
429
+ # This method returns a User object on successful sign-in; otherwise
430
430
  # it returns nil.
431
431
  #####################################################################
432
432
  def processLogin(query)
@@ -446,8 +446,8 @@ class WindowsLiveLogin
446
446
  end
447
447
 
448
448
  #####################################################################
449
- # Decodes and validates a Web Authentication token. Returns a User
450
- # object on success. If a context is passed in, it will be returned
449
+ # Decodes and validates a Web Authentication token. Returns a User
450
+ # object on success. If a context is passed in, it will be returned
451
451
  # as the context field in the User object.
452
452
  #####################################################################
453
453
  def processToken(token, context=nil)
@@ -467,7 +467,7 @@ class WindowsLiveLogin
467
467
  return
468
468
  end
469
469
  begin
470
- user = User.new(stoken['ts'], stoken['uid'], stoken['flags'],
470
+ user = User.new(stoken['ts'], stoken['uid'], stoken['flags'],
471
471
  context, token)
472
472
  return user
473
473
  rescue Exception => e
@@ -477,10 +477,10 @@ class WindowsLiveLogin
477
477
  end
478
478
 
479
479
  #####################################################################
480
- # Returns an appropriate content type and body response that the
481
- # application handler can return to signify a successful sign-out
480
+ # Returns an appropriate content type and body response that the
481
+ # application handler can return to signify a successful sign-out
482
482
  # from the application.
483
- #
483
+ #
484
484
  # When a user signs out of Windows Live or a Windows Live
485
485
  # application, a best-effort attempt is made at signing the user out
486
486
  # from all other Windows Live applications the user might be signed
@@ -511,7 +511,7 @@ class WindowsLiveLogin
511
511
  # If you specify it, 'context' will be returned as-is in the consent
512
512
  # response for site-specific use.
513
513
  #
514
- # The registered/configured return URL can also be overridden by
514
+ # The registered/configured return URL can also be overridden by
515
515
  # specifying 'ru' here.
516
516
  #
517
517
  # You can change the language in which the consent page is displayed
@@ -534,9 +534,9 @@ class WindowsLiveLogin
534
534
  end
535
535
 
536
536
  #####################################################################
537
- # Returns the URL to use to download a new consent token, given the
537
+ # Returns the URL to use to download a new consent token, given the
538
538
  # offers and refresh token.
539
- # The registered/configured return URL can also be overridden by
539
+ # The registered/configured return URL can also be overridden by
540
540
  # specifying 'ru' here.
541
541
  #####################################################################
542
542
  def getRefreshConsentTokenUrl(offers, refreshtoken, ru)
@@ -546,7 +546,7 @@ class WindowsLiveLogin
546
546
  if (refreshtoken.nil? or refreshtoken.empty?)
547
547
  fatal("Error: getRefreshConsentTokenUrl: Invalid refresh token.")
548
548
  end
549
- url = consenturl + "RefreshToken.aspx?ps=#{CGI.escape(offers)}"
549
+ url = consenturl + "RefreshToken.aspx?ps=#{CGI.escape(offers)}"
550
550
  url += "&reft=#{refreshtoken}"
551
551
  ru = returnurl if (ru.nil? or ru.empty?)
552
552
  url += "&ru=#{CGI.escape(ru)}" if ru
@@ -578,9 +578,9 @@ class WindowsLiveLogin
578
578
  return false unless delegationtoken
579
579
  return ((Time.now.to_i-300) < expiry.to_i)
580
580
  end
581
-
581
+
582
582
  #####################################################################
583
- # Refreshes the current token and replace it. If operation succeeds
583
+ # Refreshes the current token and replace it. If operation succeeds
584
584
  # true is returned to signify success.
585
585
  #####################################################################
586
586
  def refresh
@@ -591,9 +591,9 @@ class WindowsLiveLogin
591
591
  end
592
592
 
593
593
  #####################################################################
594
- # Initialize the ConsentToken module with the WindowsLiveLogin,
595
- # delegation token, refresh token, session key, expiry, offers,
596
- # location ID, context, decoded token, and raw token.
594
+ # Initialize the ConsentToken module with the WindowsLiveLogin,
595
+ # delegation token, refresh token, session key, expiry, offers,
596
+ # location ID, context, decoded token, and raw token.
597
597
  #####################################################################
598
598
  def initialize(wll, delegationtoken, refreshtoken, sessionkey, expiry,
599
599
  offers, locationid, context, decodedtoken, token)
@@ -608,7 +608,7 @@ class WindowsLiveLogin
608
608
  self.decodedtoken = decodedtoken
609
609
  self.token = token
610
610
  end
611
-
611
+
612
612
  private
613
613
  attr_writer :delegationtoken, :refreshtoken, :sessionkey, :expiry
614
614
  attr_writer :offers, :offers_string, :locationid, :context
@@ -619,7 +619,7 @@ class WindowsLiveLogin
619
619
  #####################################################################
620
620
  def delegationtoken=(delegationtoken)
621
621
  if (delegationtoken.nil? or delegationtoken.empty?)
622
- raise("Error: ConsentToken: Null delegation token.")
622
+ raise("Error: ConsentToken: Null delegation token.")
623
623
  end
624
624
  @delegationtoken = delegationtoken
625
625
  end
@@ -694,10 +694,10 @@ class WindowsLiveLogin
694
694
  end
695
695
 
696
696
  #####################################################################
697
- # Processes the POST response from the Delegated Authentication
697
+ # Processes the POST response from the Delegated Authentication
698
698
  # service after a user has granted consent. The processConsent
699
- # function extracts the consent token string and returns the result
700
- # of invoking the processConsentToken method.
699
+ # function extracts the consent token string and returns the result
700
+ # of invoking the processConsentToken method.
701
701
  #####################################################################
702
702
  def processConsent(query)
703
703
  query = parse query
@@ -721,8 +721,8 @@ class WindowsLiveLogin
721
721
  end
722
722
 
723
723
  #####################################################################
724
- # Processes the consent token string that is returned in the POST
725
- # response by the Delegated Authentication service after a
724
+ # Processes the consent token string that is returned in the POST
725
+ # response by the Delegated Authentication service after a
726
726
  # user has granted consent.
727
727
  #####################################################################
728
728
  def processConsentToken(token, context=nil)
@@ -747,7 +747,7 @@ class WindowsLiveLogin
747
747
  decodedtoken = CGI.escape(decodedtoken)
748
748
  end
749
749
  begin
750
- consenttoken = ConsentToken.new(self,
750
+ consenttoken = ConsentToken.new(self,
751
751
  parsedtoken['delt'],
752
752
  parsedtoken['reft'],
753
753
  parsedtoken['skey'],
@@ -763,7 +763,7 @@ class WindowsLiveLogin
763
763
  end
764
764
 
765
765
  #####################################################################
766
- # Attempts to obtain a new, refreshed token and return it. The
766
+ # Attempts to obtain a new, refreshed token and return it. The
767
767
  # original token is not modified.
768
768
  #####################################################################
769
769
  def refreshConsentToken(consenttoken, ru=nil)
@@ -853,7 +853,7 @@ class WindowsLiveLogin
853
853
  end
854
854
 
855
855
  #####################################################################
856
- # Creates a signature for the given string by using the signature
856
+ # Creates a signature for the given string by using the signature
857
857
  # key.
858
858
  #####################################################################
859
859
  def signToken(token, signkey=@signkey)
@@ -890,12 +890,12 @@ class WindowsLiveLogin
890
890
  end
891
891
 
892
892
  #######################################################################
893
- # Implementation of the methods needed to perform Windows Live
893
+ # Implementation of the methods needed to perform Windows Live
894
894
  # application verification as well as trusted sign-in.
895
895
  #######################################################################
896
896
  class WindowsLiveLogin
897
897
  #####################################################################
898
- # Generates an application verifier token. An IP address can
898
+ # Generates an application verifier token. An IP address can
899
899
  # optionally be included in the token.
900
900
  #####################################################################
901
901
  def getAppVerifier(ip=nil)
@@ -906,16 +906,16 @@ class WindowsLiveLogin
906
906
  end
907
907
 
908
908
  #####################################################################
909
- # Returns the URL that is required to retrieve the application
909
+ # Returns the URL that is required to retrieve the application
910
910
  # security token.
911
911
  #
912
- # By default, the application security token is generated for
913
- # the Windows Live site; a specific Site ID can optionally be
914
- # specified in 'siteid'. The IP address can also optionally be
912
+ # By default, the application security token is generated for
913
+ # the Windows Live site; a specific Site ID can optionally be
914
+ # specified in 'siteid'. The IP address can also optionally be
915
915
  # included in 'ip'.
916
916
  #
917
- # If 'js' is nil, a JavaScript Output Notation (JSON) response is
918
- # returned in the following format:
917
+ # If 'js' is nil, a JavaScript Output Notation (JSON) response is
918
+ # returned in the following format:
919
919
  #
920
920
  # {"token":"<value>"}
921
921
  #
@@ -935,7 +935,7 @@ class WindowsLiveLogin
935
935
 
936
936
  #####################################################################
937
937
  # Retrieves the application security token for application
938
- # verification from the application sign-in URL.
938
+ # verification from the application sign-in URL.
939
939
  #
940
940
  # By default, the application security token will be generated for
941
941
  # the Windows Live site; a specific Site ID can optionally be
@@ -962,7 +962,7 @@ class WindowsLiveLogin
962
962
  debug("Error: getAppSecurityToken: Failed to extract token: #{body}")
963
963
  rescue Exception => e
964
964
  debug("Error: getAppSecurityToken: Failed to get token: #{e}")
965
- end
965
+ end
966
966
  return
967
967
  end
968
968
 
@@ -983,13 +983,13 @@ class WindowsLiveLogin
983
983
  # may have to be escaped if you are inserting them in code such as
984
984
  # an HTML form.
985
985
  #
986
- # The user to be trusted on the local site is passed in as string
986
+ # The user to be trusted on the local site is passed in as string
987
987
  # 'user'.
988
988
  #
989
989
  # Optionally, 'retcode' specifies the resource to which successful
990
990
  # sign-in is redirected, such as Windows Live Mail, and is typically
991
991
  # a string in the format 'id=2000'. If you pass in the value from
992
- # getAppRetCode instead, sign-in will be redirected to the
992
+ # getAppRetCode instead, sign-in will be redirected to the
993
993
  # application. Otherwise, an HTTP 200 response is returned.
994
994
  #####################################################################
995
995
  def getTrustedParams(user, retcode=nil)
@@ -1022,7 +1022,7 @@ class WindowsLiveLogin
1022
1022
 
1023
1023
  #####################################################################
1024
1024
  # Returns the trusted sign-in URL to use for the Windows Live Login
1025
- # server.
1025
+ # server.
1026
1026
  #####################################################################
1027
1027
  def getTrustedLoginUrl
1028
1028
  secureurl + "wlogin.srf"
@@ -1041,10 +1041,10 @@ end
1041
1041
  # Helper methods.
1042
1042
  #######################################################################
1043
1043
  class WindowsLiveLogin
1044
-
1044
+
1045
1045
  #######################################################################
1046
1046
  # Function to parse the settings file.
1047
- #######################################################################
1047
+ #######################################################################
1048
1048
  def parseSettings(settingsFile)
1049
1049
  settings = {}
1050
1050
  begin
@@ -1077,12 +1077,12 @@ class WindowsLiveLogin
1077
1077
  end
1078
1078
 
1079
1079
  #####################################################################
1080
- # Parses query string and return a table
1080
+ # Parses query string and return a table
1081
1081
  # {String=>String}
1082
1082
  #
1083
1083
  # If a table is passed in from CGI.params, we convert it from
1084
1084
  # {String=>[]} to {String=>String}. I believe Rails uses symbols
1085
- # instead of strings in general, so we convert from symbols to
1085
+ # instead of strings in general, so we convert from symbols to
1086
1086
  # strings here also.
1087
1087
  #####################################################################
1088
1088
  def parse(input)
@@ -0,0 +1,67 @@
1
+ require 'omniauth/core'
2
+ require 'digest/md5'
3
+ require 'rest-client'
4
+ require 'multi_json'
5
+
6
+ module OmniAuth
7
+ module Strategies
8
+ class Yupoo
9
+ include OmniAuth::Strategy
10
+ attr_accessor :api_key, :secret_key, :options
11
+
12
+
13
+ class CallbackError < StandardError
14
+ attr_accessor :error, :error_reason
15
+ def initialize(error, error_reason)
16
+ self.error = error
17
+ self.error_reason = error_reason
18
+ end
19
+ end
20
+
21
+ def initialize(app, api_key, secret_key, options = {})
22
+ super(app, :yupoo)
23
+ @api_key = api_key
24
+ @secret_key = secret_key
25
+ @options = {:scope => 'read'}.merge(options)
26
+ end
27
+
28
+ protected
29
+
30
+ def request_phase
31
+ params = { :api_key => api_key, :perms => options[:scope] }
32
+ params[:api_sig] = yupoo_sign(params)
33
+ query_string = params.collect{ |key,value| "#{key}=#{Rack::Utils.escape(value)}" }.join('&')
34
+ redirect "http://www.yupoo.com/services/auth/?#{query_string}"
35
+ end
36
+
37
+ def callback_phase
38
+ params = { :api_key => api_key, :method => 'yupoo.auth.getToken', :frob => request.params['frob'], :format => 'json', :nojsoncallback => '1' }
39
+ params[:api_sig] = yupoo_sign(params)
40
+
41
+ response = RestClient.get('http://www.yupoo.com/api/rest/', { :params => params })
42
+ auth = MultiJson.decode(response.to_s)
43
+ raise CallbackError.new(auth['code'],auth['message']) if auth['stat'] == 'fail'
44
+
45
+ @user = auth['auth']['user']
46
+ @access_token = auth['auth']['token']['_content']
47
+
48
+ super
49
+ rescue CallbackError => e
50
+ fail!(:invalid_response, e)
51
+ end
52
+
53
+ def auth_hash
54
+ OmniAuth::Utils.deep_merge(super, {
55
+ 'uid' => @user['nsid'],
56
+ 'credentials' => { 'token' => @access_token },
57
+ 'user_info' => @user,
58
+ 'extra' => { 'user_hash' => @user }
59
+ })
60
+ end
61
+
62
+ def yupoo_sign(params)
63
+ Digest::MD5.hexdigest(secret_key + params.sort{|a,b| a[0].to_s <=> b[0].to_s }.flatten.join)
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,19 @@
1
+ module OmniAuth
2
+ module Version
3
+ unless defined?(::OmniAuth::Version::MAJOR)
4
+ MAJOR = 0
5
+ end
6
+ unless defined?(::OmniAuth::Version::MINOR)
7
+ MINOR = 2
8
+ end
9
+ unless defined?(::OmniAuth::Version::PATCH)
10
+ PATCH = 5
11
+ end
12
+ unless defined?(::OmniAuth::Version::PRE)
13
+ PRE = nil
14
+ end
15
+ unless defined?(::OmniAuth::Version::STRING)
16
+ STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
17
+ end
18
+ end
19
+ end
@@ -1,21 +1,24 @@
1
1
  # -*- encoding: utf-8 -*-
2
- require File.expand_path('../../omniauth/lib/omniauth/version', __FILE__)
2
+ require File.expand_path('../lib/omniauth/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
- gem.add_dependency 'oa-core', Omniauth::VERSION.dup
6
- gem.add_dependency 'rest-client', '~> 1.6.0'
7
- gem.add_dependency 'multi_json', '~> 0.0.2'
5
+ gem.add_runtime_dependency 'jruby-openssl', '~> 0.7.3' if RUBY_PLATFORM == 'java'
6
+ gem.add_runtime_dependency 'multi_json', '~> 1.0.0'
7
+ gem.add_runtime_dependency 'oa-core', OmniAuth::Version::STRING
8
+ gem.add_runtime_dependency 'rest-client', '~> 1.6.0'
8
9
  gem.add_development_dependency 'json_pure', '~> 1.5'
10
+ gem.add_development_dependency 'maruku', '~> 0.6'
9
11
  gem.add_development_dependency 'rake', '~> 0.8'
10
12
  gem.add_development_dependency 'rack-test', '~> 0.5'
11
13
  gem.add_development_dependency 'rspec', '~> 2.5'
12
14
  gem.add_development_dependency 'simplecov', '~> 0.4'
13
15
  gem.add_development_dependency 'webmock', '~> 1.6'
14
16
  gem.add_development_dependency 'yard', '~> 0.6'
17
+ gem.add_development_dependency 'ZenTest', '~> 4.5'
15
18
  gem.name = 'oa-more'
16
- gem.version = Omniauth::VERSION.dup
17
- gem.summary = %q{Additional strategies for OmniAuth.}
19
+ gem.version = OmniAuth::Version::STRING
18
20
  gem.description = %q{Additional strategies for OmniAuth.}
21
+ gem.summary = gem.description
19
22
  gem.email = 'michael@intridea.com'
20
23
  gem.homepage = 'http://github.com/intridea/omniauth'
21
24
  gem.authors = ['Michael Bleigh', 'Erik Michaels-Ober']
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
2
 
3
3
  describe 'OmniAuth::Strategies::Flickr' do
4
4
  it 'should initialize with a consumer key and secret' do
@@ -1,12 +1,11 @@
1
- require 'rubygems'
1
+ require 'simplecov'
2
+ SimpleCov.start
2
3
  require 'rspec'
3
- require 'rspec/autorun'
4
4
  require 'rack/test'
5
5
  require 'webmock/rspec'
6
-
7
- include Rack::Test::Methods
8
- include WebMock::API
9
-
10
6
  require 'omniauth/more'
11
7
 
12
- WebMock.disable_net_connect!
8
+ Rspec.configure do |config|
9
+ config.include Rack::Test::Methods
10
+ config.include WebMock::API
11
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: oa-more
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.4
5
+ version: 0.2.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Michael Bleigh
@@ -11,39 +11,39 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-04-22 00:00:00 Z
14
+ date: 2011-04-29 00:00:00 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
- name: oa-core
17
+ name: multi_json
18
18
  prerelease: false
19
19
  requirement: &id001 !ruby/object:Gem::Requirement
20
20
  none: false
21
21
  requirements:
22
- - - "="
22
+ - - ~>
23
23
  - !ruby/object:Gem::Version
24
- version: 0.2.4
24
+ version: 1.0.0
25
25
  type: :runtime
26
26
  version_requirements: *id001
27
27
  - !ruby/object:Gem::Dependency
28
- name: rest-client
28
+ name: oa-core
29
29
  prerelease: false
30
30
  requirement: &id002 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
- - - ~>
33
+ - - "="
34
34
  - !ruby/object:Gem::Version
35
- version: 1.6.0
35
+ version: 0.2.5
36
36
  type: :runtime
37
37
  version_requirements: *id002
38
38
  - !ruby/object:Gem::Dependency
39
- name: multi_json
39
+ name: rest-client
40
40
  prerelease: false
41
41
  requirement: &id003 !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
44
  - - ~>
45
45
  - !ruby/object:Gem::Version
46
- version: 0.0.2
46
+ version: 1.6.0
47
47
  type: :runtime
48
48
  version_requirements: *id003
49
49
  - !ruby/object:Gem::Dependency
@@ -58,71 +58,93 @@ dependencies:
58
58
  type: :development
59
59
  version_requirements: *id004
60
60
  - !ruby/object:Gem::Dependency
61
- name: rake
61
+ name: maruku
62
62
  prerelease: false
63
63
  requirement: &id005 !ruby/object:Gem::Requirement
64
64
  none: false
65
65
  requirements:
66
66
  - - ~>
67
67
  - !ruby/object:Gem::Version
68
- version: "0.8"
68
+ version: "0.6"
69
69
  type: :development
70
70
  version_requirements: *id005
71
71
  - !ruby/object:Gem::Dependency
72
- name: rack-test
72
+ name: rake
73
73
  prerelease: false
74
74
  requirement: &id006 !ruby/object:Gem::Requirement
75
75
  none: false
76
76
  requirements:
77
77
  - - ~>
78
78
  - !ruby/object:Gem::Version
79
- version: "0.5"
79
+ version: "0.8"
80
80
  type: :development
81
81
  version_requirements: *id006
82
82
  - !ruby/object:Gem::Dependency
83
- name: rspec
83
+ name: rack-test
84
84
  prerelease: false
85
85
  requirement: &id007 !ruby/object:Gem::Requirement
86
86
  none: false
87
87
  requirements:
88
88
  - - ~>
89
89
  - !ruby/object:Gem::Version
90
- version: "2.5"
90
+ version: "0.5"
91
91
  type: :development
92
92
  version_requirements: *id007
93
93
  - !ruby/object:Gem::Dependency
94
- name: simplecov
94
+ name: rspec
95
95
  prerelease: false
96
96
  requirement: &id008 !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
99
99
  - - ~>
100
100
  - !ruby/object:Gem::Version
101
- version: "0.4"
101
+ version: "2.5"
102
102
  type: :development
103
103
  version_requirements: *id008
104
104
  - !ruby/object:Gem::Dependency
105
- name: webmock
105
+ name: simplecov
106
106
  prerelease: false
107
107
  requirement: &id009 !ruby/object:Gem::Requirement
108
108
  none: false
109
109
  requirements:
110
110
  - - ~>
111
111
  - !ruby/object:Gem::Version
112
- version: "1.6"
112
+ version: "0.4"
113
113
  type: :development
114
114
  version_requirements: *id009
115
115
  - !ruby/object:Gem::Dependency
116
- name: yard
116
+ name: webmock
117
117
  prerelease: false
118
118
  requirement: &id010 !ruby/object:Gem::Requirement
119
119
  none: false
120
120
  requirements:
121
121
  - - ~>
122
122
  - !ruby/object:Gem::Version
123
- version: "0.6"
123
+ version: "1.6"
124
124
  type: :development
125
125
  version_requirements: *id010
126
+ - !ruby/object:Gem::Dependency
127
+ name: yard
128
+ prerelease: false
129
+ requirement: &id011 !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ~>
133
+ - !ruby/object:Gem::Version
134
+ version: "0.6"
135
+ type: :development
136
+ version_requirements: *id011
137
+ - !ruby/object:Gem::Dependency
138
+ name: ZenTest
139
+ prerelease: false
140
+ requirement: &id012 !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ~>
144
+ - !ruby/object:Gem::Version
145
+ version: "4.5"
146
+ type: :development
147
+ version_requirements: *id012
126
148
  description: Additional strategies for OmniAuth.
127
149
  email: michael@intridea.com
128
150
  executables: []
@@ -135,7 +157,6 @@ files:
135
157
  - .gemtest
136
158
  - .rspec
137
159
  - .yardopts
138
- - Gemfile
139
160
  - LICENSE
140
161
  - README.rdoc
141
162
  - Rakefile
@@ -144,6 +165,8 @@ files:
144
165
  - lib/omniauth/strategies/flickr.rb
145
166
  - lib/omniauth/strategies/windows_live.rb
146
167
  - lib/omniauth/strategies/windows_live/windowslivelogin.rb
168
+ - lib/omniauth/strategies/yupoo.rb
169
+ - lib/omniauth/version.rb
147
170
  - oa-more.gemspec
148
171
  - spec/omniauth/strategies/flickr_spec.rb
149
172
  - spec/spec_helper.rb
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source 'http://rubygems.org'
2
-
3
- gemspec