WordPress Social Login - Version 2.2.3

Version Description

WSL 2.2.3 fixes a critical issue found on WSL 2.2.2 that could potentially allow multiple accounts and prevent contacts import. We recommend that users upgrade to this latest version.

WSL 2.2.3 also include a number of new features, and fixes several stability issues. See below for details.

Developers Release Notes

These release notes are aimed at developers.

This release did focus on code health and flexibility and it was necessary to move some code around, and to remove few functions and hooks. We know, it sucks to break WSL API at such short notice, but it was indispensable and unavoidable as we're trying to move the project forward.

As announced on WSL Support Forum, this is by no means a drastic change to the API. In fact, we tried our best to keep the said changes to a strict minimum, and the vast majority of WSL users will not be affected.

Those breaking changes are:

  • Deprecated hooks, prior to 2.2.2, have been removed.
  • Deprecated css selectors, prior to 2.2.2, have been removed.
  • Deprecated internal functions have been removed.
  • Few internal functions have been either removed, renamed or slightly changed.
  • Few pluggable functions has slightly changed.
  • Steam's users identifiers are converted to a new format.

Please update the WSL hooks you were using accordingly to the new developer API:

http://miled.github.io/wordpress-social-login/developer-api-migrating-2.2.html http://miled.github.io/wordpress-social-login/developer-api-authentication.html http://miled.github.io/wordpress-social-login/developer-api-widget.html http://miled.github.io/wordpress-social-login/developer-api-functions.html

On this release we have reworked Steam provider to fully support their new Web API, and we decided to change Steam's users identifiers to SteamID64. When updated, WSL 2.2.3 will automatically convert all the existing steam users identifiers in wslusersprofiles to the new format.

It's worth mentioning that in upcoming releases and before we hit WSL 3.0, we're planning to rework other parts of the codebase; for instance user database functions will be re-factored using an ORM, and profile completion will be replaced by new module.

We explicitly discourage you from using, or hacking, any internal function (i.e., Not publicly documented on WSL dev API), as they are now subject to change in subsequent releases. If it wasn't possible to achieve some required functionality in a proper way through the already available and documented WSL hooks, please ask for support before resorting to hacks.

Upon reaching WSL 3.0 as a major milestone, our priorities will flip to maintenance and stability (i.e, repair code health, enhance code coverage) rather than developing new features. This massive rewrite aims to make WSL more modular easily extended through plugins and add-ons (e.g., http://miled.github.io/wsl-users-converter/).

List of changes

  • WSL is now compatible with PHP 5.2 again.
  • WSL is now compatible with WordPress 3.0+ again.
  • WSL now display social apis errors when authentication fails.
  • WSL now support authentications through Dribbble.com.
  • Steam provider has been entirely reworked and now fully support the new Web API.
  • Steam users IDs is now converted to SteamID64 rather than http://steamcommunity.com/openid/id/{USER_STEAMID64}.
  • LinkedIn provider has been enhanced. WSL can now get the full LinkedIn's members avatars and headline (fix).
  • Changed facebook api endpoints to graph api v2.0
  • WSL can now import users contacts from vkontakte.
  • Profile completion form has received a visual update.
  • WSL now provide an easier access to social networks apis.
  • WSL now trigger WordPress do_login action hooks whenever a user connect.
  • Authentication display now fall back to In Page when WSL is used on a mobile device.
  • WSL admin interfaces have been reworked and can be now extended with hooks.
  • Bouncer Membership level can be now set to any user role.
  • WSL Diagnostics has been reworked and can check the minimum system requirements and for few common issues.
  • Added "Repair WSL tables" under Tools tab.
  • Added "Debug mode" under Tools tab (namely whatchdog).
  • Added "Authentication Playground" under Tools tab (namely auth-paly).
  • Added "Uninstall" under Tools tab.
  • Added new hooks in the authentication widget and auth process.
  • Made WSL more RTL friendly.
  • Added 403 pages under wsl folders (silence is.. highly overrated).
  • PHP file wsl.auth.widget.php renamed to wsl.auth.widgets.php
  • Function wsl_render_login_form() renamed to wsl_render_auth_widget()
  • wsl_user_custom_avatar and wsl_bp_user_custom_avatar are now pluggable and can be redefined.
  • wsl_render_notice_page and wsl_render_error_page has slightly changed.
  • Fix a critical issue found on WSL 2.2.2 with wslusersprofiles.
  • Fix an issue where redirect_to get overwritten in some cases.
  • Fix an issue with redirect_to where the callback url was encoded twice.
  • Fix several stability issues.
  • Added testunit to the project (early version).
  • Deprecated hooks, prior to 2.2.2, have been removed.
  • Deprecated internal functions have been removed.
  • Deprecated css selectors, in wsl widget, have been removed.
  • Updated the API documentation for WSL authentication process
  • Updated the API documentation for WSL widget generator
  • Updated the API documentation for pluggable WSL functions
  • Added a list of code snippets to WSL documentation
  • Added documentation for social apis access (through php code)
  • Added documentation for basic troubleshooting (common issues)
  • Added documentation for advanced troubleshooting (internal tools)
Download this release

Release Info

Developer miled
Plugin Icon 128x128 WordPress Social Login
Version 2.2.3
Comparing to
See all releases

Code changes from version 2.2.2 to 2.2.3

Files changed (157) hide show
  1. LICENSE +22 -0
  2. assets/css/admin.css +1 -0
  3. assets/css/style.css +1 -13
  4. assets/img/16x16/dribbble.png +0 -0
  5. assets/img/16x16/latch.png +0 -0
  6. assets/img/16x16/vkontakte.png +0 -0
  7. assets/img/32x32/icondock/dribbble.png +0 -0
  8. assets/img/32x32/icondock/latch.png +0 -0
  9. assets/img/32x32/icondock/vkontakte.png +0 -0
  10. assets/img/32x32/wpzoom/dribbble.png +0 -0
  11. assets/img/32x32/wpzoom/latch.png +0 -0
  12. assets/img/32x32/wpzoom/vkontakte.png +0 -0
  13. assets/img/components.png +0 -0
  14. assets/img/debug.png +0 -0
  15. assets/img/dismiss.png +0 -0
  16. assets/img/help.png +0 -0
  17. assets/img/info.png +0 -0
  18. assets/img/magic.png +0 -0
  19. assets/img/question.png +0 -0
  20. assets/img/tools.png +0 -0
  21. assets/index.html +31 -0
  22. assets/js/script.js +0 -64
  23. assets/js/widget.js +74 -0
  24. hybridauth/Hybrid/Auth.php +380 -401
  25. hybridauth/Hybrid/Endpoint.php +10 -26
  26. hybridauth/Hybrid/Error.php +87 -89
  27. hybridauth/Hybrid/Logger.php +0 -92
  28. hybridauth/Hybrid/Provider_Adapter.php +313 -322
  29. hybridauth/Hybrid/Provider_Model.php +245 -263
  30. hybridauth/Hybrid/Provider_Model_OAuth1.php +180 -171
  31. hybridauth/Hybrid/Provider_Model_OAuth2.php +184 -184
  32. hybridauth/Hybrid/Provider_Model_OpenID.php +181 -179
  33. hybridauth/Hybrid/Providers/AOL.php +16 -16
  34. hybridauth/Hybrid/Providers/Dribbble.php +51 -0
  35. hybridauth/Hybrid/Providers/Facebook.php +381 -433
  36. hybridauth/Hybrid/Providers/Foursquare.php +56 -56
  37. hybridauth/Hybrid/Providers/GitHub.php +72 -72
  38. hybridauth/Hybrid/Providers/Goodreads.php +115 -115
  39. hybridauth/Hybrid/Providers/Google.php +242 -283
  40. hybridauth/Hybrid/Providers/Identica.php +0 -165
  41. hybridauth/Hybrid/Providers/LastFM.php +111 -111
  42. hybridauth/Hybrid/Providers/Latch.php +30 -30
  43. hybridauth/Hybrid/Providers/LinkedIn.php +269 -259
  44. hybridauth/Hybrid/Providers/Live.php +108 -106
  45. hybridauth/Hybrid/Providers/Mailru.php +63 -63
  46. hybridauth/Hybrid/Providers/Mixi.php +6 -6
  47. hybridauth/Hybrid/Providers/Odnoklassniki.php +176 -181
  48. hybridauth/Hybrid/Providers/OpenID.php +15 -15
  49. hybridauth/Hybrid/Providers/Paypal.php +0 -146
  50. hybridauth/Hybrid/Providers/PixelPin.php +49 -49
  51. hybridauth/Hybrid/Providers/Reddit.php +7 -11
  52. hybridauth/Hybrid/Providers/Stackoverflow.php +4 -4
  53. hybridauth/Hybrid/Providers/Steam.php +122 -55
  54. hybridauth/Hybrid/Providers/Tumblr.php +79 -79
  55. hybridauth/Hybrid/Providers/TwitchTV.php +73 -73
  56. hybridauth/Hybrid/Providers/Twitter.php +275 -270
  57. hybridauth/Hybrid/Providers/Vkontakte.php +3 -3
  58. hybridauth/Hybrid/Providers/WordPress.php +85 -82
  59. hybridauth/Hybrid/Providers/Yahoo.php +32 -31
  60. hybridauth/Hybrid/Providers/Yandex.php +61 -61
  61. hybridauth/Hybrid/Providers/px500.php +18 -22
  62. hybridauth/Hybrid/Storage.php +137 -140
  63. hybridauth/Hybrid/StorageInterface.php +0 -28
  64. hybridauth/Hybrid/User.php +40 -40
  65. hybridauth/Hybrid/User_Activity.php +54 -54
  66. hybridauth/Hybrid/User_Contact.php +58 -58
  67. hybridauth/Hybrid/User_Profile.php +150 -150
  68. hybridauth/Hybrid/index.html +9 -9
  69. hybridauth/Hybrid/resources/config.php.tpl +0 -72
  70. hybridauth/Hybrid/resources/index.html +9 -9
  71. hybridauth/Hybrid/resources/openid_policy.html +9 -9
  72. hybridauth/Hybrid/resources/openid_realm.html +31 -13
  73. hybridauth/Hybrid/resources/openid_xrds.xml +11 -11
  74. hybridauth/Hybrid/thirdparty/Facebook/base_facebook.php +40 -12
  75. hybridauth/Hybrid/thirdparty/LastFM/LastFM.php +379 -381
  76. hybridauth/Hybrid/thirdparty/LinkedIn/LinkedIn.php +2661 -2648
  77. hybridauth/Hybrid/thirdparty/OAuth/OAuth.php +901 -901
  78. hybridauth/Hybrid/thirdparty/OAuth/OAuth1Client.php +262 -253
  79. hybridauth/Hybrid/thirdparty/OAuth/OAuth2Client.php +229 -256
  80. hybridauth/Hybrid/thirdparty/OpenID/LightOpenID.php +997 -984
  81. hybridauth/Hybrid/thirdparty/Paypal/PaypalOAuth2Client.php +135 -142
  82. hybridauth/Hybrid/thirdparty/index.html +9 -9
  83. hybridauth/endpoints/WSL_Endpoint.php +161 -0
  84. hybridauth/endpoints/dribbble.php +11 -0
  85. hybridauth/endpoints/live.php +11 -0
  86. hybridauth/endpoints/readme.md +1 -0
  87. hybridauth/index.php +37 -7
  88. hybridauth/readme.md +2 -48
  89. includes/admin/components/auth-paly/index.php +382 -0
  90. includes/admin/components/bouncer/index.php +54 -54
  91. includes/admin/components/bouncer/wsl.components.bouncer.setup.php +466 -291
  92. includes/admin/components/bouncer/wsl.components.bouncer.sidebar.php +69 -70
  93. includes/admin/components/buddypress/index.php +60 -60
  94. includes/admin/components/buddypress/wsl.components.buddypress.notfound.php +59 -59
  95. includes/admin/components/buddypress/wsl.components.buddypress.setup.php +277 -256
  96. includes/admin/components/buddypress/wsl.components.buddypress.sidebar.php +58 -50
  97. includes/admin/components/components/index.php +36 -36
  98. includes/admin/components/components/wsl.components.help.gallery.php +83 -71
  99. includes/admin/components/components/wsl.components.help.setup.php +131 -119
  100. includes/admin/components/contacts/index.php +63 -240
  101. includes/admin/components/contacts/wsl.components.contacts.list.php +153 -0
  102. includes/admin/components/contacts/wsl.components.contacts.settings.setup.php +179 -0
  103. includes/admin/components/contacts/wsl.components.contacts.settings.sidebar.php +68 -0
  104. includes/admin/components/diagnostics/index.php +0 -92
  105. includes/admin/components/help/index.php +50 -155
  106. includes/admin/components/help/wsl.components.help.reference.php +99 -0
  107. includes/admin/components/help/wsl.components.help.sidebar.php +56 -0
  108. includes/admin/components/login-widget/index.php +54 -54
  109. includes/admin/components/login-widget/wsl.components.loginwidget.setup.php +303 -224
  110. includes/admin/components/login-widget/wsl.components.loginwidget.sidebar.php +130 -88
  111. includes/admin/components/networks/index.php +60 -65
  112. includes/admin/components/networks/wsl.components.networks.addmore.php +0 -68
  113. includes/admin/components/networks/wsl.components.networks.basicinsights.php +0 -136
  114. includes/admin/components/networks/wsl.components.networks.setup.php +339 -319
  115. includes/admin/components/networks/wsl.components.networks.sidebar.php +251 -0
  116. includes/admin/components/networks/wsl.components.networks.whyhello.php +0 -51
  117. includes/admin/components/tools/index.php +76 -0
  118. includes/admin/components/tools/wsl.components.tools.actions.job.php +927 -0
  119. includes/admin/components/tools/wsl.components.tools.actions.php +234 -0
  120. includes/admin/components/tools/wsl.components.tools.sidebar.php +57 -0
  121. includes/admin/components/users/index.php +41 -41
  122. includes/admin/components/users/wsl.components.users.list.php +247 -202
  123. includes/admin/components/users/{wsl.components.users.profile.php → wsl.components.users.profiles.php} +171 -146
  124. includes/admin/components/watchdog/index.php +243 -214
  125. includes/admin/wsl.admin.ui.php +502 -630
  126. includes/index.html +31 -0
  127. includes/services/wsl.authentication.php +1171 -915
  128. includes/services/wsl.mail.notification.php +51 -45
  129. includes/services/wsl.user.avatar.php +166 -144
  130. includes/services/wsl.user.data.php +443 -381
  131. includes/services/wsl.utilities.php +437 -385
  132. includes/services/wsl.watchdog.php +251 -0
  133. includes/settings/wsl.compatibilities.php +243 -150
  134. includes/settings/wsl.database.php +167 -104
  135. includes/settings/wsl.initialization.php +298 -256
  136. includes/settings/wsl.providers.php +279 -272
  137. includes/widgets/wsl.auth.widget.php +0 -310
  138. includes/widgets/wsl.auth.widgets.php +552 -0
  139. includes/widgets/wsl.complete.registration.php +368 -159
  140. includes/widgets/wsl.error.pages.php +304 -285
  141. includes/widgets/wsl.loading.screens.php +205 -200
  142. includes/widgets/wsl.users.gateway.php +635 -0
  143. index.html +31 -0
  144. languages/default.po +2754 -0
  145. languages/index.html +31 -0
  146. languages/readme.md +5 -0
  147. languages/readme.txt +0 -6
  148. languages/wordpress-social-login-ar.mo +0 -0
  149. languages/wordpress-social-login-fr_FR.mo +0 -0
  150. languages/wordpress-social-login-pt_BR.mo +0 -0
  151. readme.txt +88 -7
  152. utilities/diagnostics.php +0 -190
  153. utilities/index.php +0 -4
  154. utilities/siteinfo.php +0 -132
  155. utilities/uninstall.php +0 -93
  156. utilities/watchdog.php +0 -206
  157. wp-social-login.php +145 -71
LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (C) 2011-2014 Mohamed Mrassi and contributors.
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.
assets/css/admin.css ADDED
@@ -0,0 +1 @@
1
+ /*! WordPress Social Login | (c) 2011-2014 Mohamed Mrassi and contributors. | opensource.org/licenses/MIT */.wsl-container{margin:25px 40px 0 20px}.wsl-container .inside{font-size:13px;line-height:1.4em}.wsl-container h1{color:#333;text-shadow:1px 1px 1px #FFF;font-size:2.8em;font-weight:200;line-height:1.2em;margin:.2em 200px .6em .2em}.wsl-container h2 .nav-tab{color:#21759B}.wsl-container h2 .nav-tab-active{color:#464646;text-shadow:1px 1px 1px #FFF}.wsl-container hr{border-color:#EEE;border-style:none none solid;border-width:0 0 1px;margin:2px 0 15px}.wsl-container h3,.wsl-container h3 label{cursor:default}.wsl-container p{line-height:1.8em}.wsl-container .wslpre{font-size:14m;border:1px solid #E6DB55;border-radius:3px;padding:5px;width:650px}.wsl-container ul{list-style:disc}.thumbnails:after,.thumbnails:before{display:table;line-height:0;content:""}.thumbnail{display:block;padding:4px;line-height:20px;border:1px solid #ddd;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;-webkit-box-shadow:0 1px 3px rgba(0,0,0,.055);-moz-box-shadow:0 1px 3px rgba(0,0,0,.055);box-shadow:0 1px 3px rgba(0,0,0,.055);-webkit-transition:all .2s ease-in-out;-moz-transition:all .2s ease-in-out;-o-transition:all .2s ease-in-out;transition:all .2s ease-in-out}a.thumbnail:hover{border-color:#08c;-webkit-box-shadow:0 1px 4px rgba(0,105,214,.25);-moz-box-shadow:0 1px 4px rgba(0,105,214,.25);box-shadow:0 1px 4px rgba(0,105,214,.25)}.thumbnail>img{display:block;max-width:100%;margin-right:auto;margin-left:auto}.thumbnail .caption{padding:9px;color:#555}.wsl-container .span4{width:220px}.wsl_connect_with_provider{text-decoration:none;cursor:not-allowed}#wsl-w-panel{background:linear-gradient(to top,#F5F5F5,#FAFAFA) #F5F5F5;border-color:#DFDFDF;border-radius:3px;border-style:solid;border-width:1px;font-size:13px;line-height:2.1em;margin:20px 0;overflow:auto;padding:5px;position:relative}#wsl-w-panel-dismiss:before{content:" ";height:100%;left:-12px;position:absolute;width:10px;margin:-2px 0}#wsl-w-panel-dismiss:hover:before{background-position:100% 17%}#wsl-w-panel-dismiss{font-size:13px;line-height:1;padding:8px 3px;position:absolute;right:10px;text-decoration:none;top:0}#wsl-w-panel-updates-tr{display:none}.wp-editor-textarea{width:98%;padding:1%;font-family:"Trebuchet MS",Arial,verdana,sans-serif}.wp-editor-textarea textarea{height:100px}.wp-editor-textarea input{width:auto!important}#wsl_div_warn{padding:10px;border:1px solid #ddd;background-color:#fff;width:55%;margin:30px auto 0}.wsl-container .button-danger{background-color:#da4f49;background-image:linear-gradient(to bottom,#ce3f38,#bd362f);border-color:#bd362f;border-radius:3px;border-style:solid;border-width:1px;box-sizing:border-box;color:#fff;cursor:pointer;display:inline-block;float:none;font-size:13px;height:30px;margin:0;padding:5px;text-decoration:none;text-shadow:0 1px 0 rgba(0,0,0,.1);white-space:nowrap}.wsl-container .button-danger:focus,.wsl-container .button-danger:hover{background:#d3534c;border-color:#ce3f38;-webkit-box-shadow:inset 0 1px 0 rgba(206,63,56,.6);box-shadow:inset 0 1px 0 rgba(206,63,56,.6);color:#fff}.wsl_component_div{width:30%;min-height:140px;padding:10px;border:1px solid #ddd;background-color:#fff;float:left;margin-bottom:20px;margin-right:20px;position:relative}.wsl_component_div h3{border-bottom:1px solid #ddd;padding-bottom:5px;margin-bottom:0}.wsl_component_about_div{height:2px;overflow:hidden;min-height:93px}
assets/css/style.css CHANGED
@@ -1,13 +1 @@
1
- /*
2
- ! Notes:
3
- ! Since WSL 2.2.1, all elements IDs generated by the widget are replaced by css classes :
4
- ! #wp-social-login-connect-with replaced with .wp-social-login-connect-with
5
- ! #wp-social-login-connect-options replaced with .wp-social-login-provider-list
6
-
7
- ! Class .wsl_connect_with_provider will be replaced with .wp-social-login-provider .wp-social-login-provider-{provider}
8
-
9
- ! Those depreciated selectors are kept for backward compatibility and will be removed.
10
- */
11
- .wp-social-login-provider-list { padding: 10px; }
12
- .wp-social-login-provider-list a {text-decoration: none; }
13
- .wp-social-login-provider-list img{ border: 0 none; }
1
+ /*! Do not edit this file. Please integrate your custom style either on your theme templates or through Widget > Custom CSS */.wp-social-login-provider-list{padding:10px}.wp-social-login-provider-list a{text-decoration:none}.wp-social-login-provider-list img{border:0}
assets/img/16x16/dribbble.png ADDED
Binary file
assets/img/16x16/latch.png DELETED
Binary file
assets/img/16x16/vkontakte.png CHANGED
Binary file
assets/img/32x32/icondock/dribbble.png ADDED
Binary file
assets/img/32x32/icondock/latch.png DELETED
Binary file
assets/img/32x32/icondock/vkontakte.png CHANGED
Binary file
assets/img/32x32/wpzoom/dribbble.png ADDED
Binary file
assets/img/32x32/wpzoom/latch.png DELETED
Binary file
assets/img/32x32/wpzoom/vkontakte.png CHANGED
Binary file
assets/img/components.png ADDED
Binary file
assets/img/debug.png ADDED
Binary file
assets/img/dismiss.png ADDED
Binary file
assets/img/help.png ADDED
Binary file
assets/img/info.png ADDED
Binary file
assets/img/magic.png ADDED
Binary file
assets/img/question.png ADDED
Binary file
assets/img/tools.png ADDED
Binary file
assets/index.html ADDED
@@ -0,0 +1,31 @@
1
+ <html>
2
+ <head>
3
+ <meta name="robots" content="noindex, nofollow">
4
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
5
+ <title>WordPress Social Login</title>
6
+ <style type="text/css">
7
+ * {
8
+ margin: 0;
9
+ padding: 0;
10
+ }
11
+ body {
12
+ background: #333;
13
+ }
14
+ h1 {
15
+ color: white;
16
+ font: 45px 'Open Sans';
17
+ padding: 30px;
18
+ }
19
+ p {
20
+ color: white;
21
+ font: 15px 'Open Sans';
22
+ padding: 0 30px;
23
+ }
24
+ </style>
25
+ </head>
26
+ <body>
27
+ <h1>WordPress Social Login</h1>
28
+
29
+ <p>403.</p>
30
+ </body>
31
+ </html>
assets/js/script.js DELETED
@@ -1,64 +0,0 @@
1
- /*!
2
- * WordPress Social Login
3
- *
4
- * http://hybridauth.sourceforge.net/wsl/index.html | http://github.com/hybridauth/WordPress-Social-Login
5
- * (c) 2011-2014 Mohamed Mrassi and contributors | http://wordpress.org/extend/plugins/wordpress-social-login/
6
- */
7
-
8
- /**
9
- * Manage authentications via a popup
10
- *
11
- * Based on http://wordpress.org/extend/plugins/social-connect/
12
- */
13
-
14
- (function($){
15
- $(function(){
16
- //
17
- $(document).on("click", "a.wsl_connect_with_provider", function(){
18
- popupurl = $("#wsl_popup_base_url").val();
19
- provider = $(this).attr("data-provider");
20
-
21
- window.open( popupurl + "provider=" + provider, "hybridauth_social_sing_on", "location=1,status=0,scrollbars=0,width=1000,height=600" );
22
- });
23
- });
24
- })(jQuery);
25
-
26
- /**
27
- *
28
- */
29
- window.wsl_wordpress_social_login = function(config){
30
- jQuery('#loginform').unbind('submit.simplemodal-login');
31
-
32
- var form_id = '#loginform';
33
-
34
- if( ! jQuery('#loginform').length ){
35
- // if register form exists, just use that
36
- if( jQuery('#registerform').length ){
37
- form_id = '#registerform';
38
- }
39
-
40
- // create the login form
41
- else {
42
- var login_uri = jQuery("#wsl_login_form_uri").val();
43
-
44
- jQuery('body').append( "<form id='loginform' method='post' action='" + login_uri + "'></form>" );
45
- jQuery('#loginform').append( "<input type='hidden' id='redirect_to' name='redirect_to' value='" + window.location.href + "'>" );
46
- }
47
- }
48
-
49
- jQuery.each(config, function(key, value){
50
- jQuery("#" + key).remove();
51
-
52
- jQuery(form_id).append( "<input type='hidden' id='" + key + "' name='" + key + "' value='" + value + "'>" );
53
- });
54
-
55
- if( jQuery("#simplemodal-login-form").length ){
56
- var current_url = window.location.href;
57
-
58
- jQuery("#redirect_to").remove();
59
-
60
- jQuery(form_id).append( "<input type='hidden' id='redirect_to' name='redirect_to' value='" + current_url + "'>" );
61
- }
62
-
63
- jQuery(form_id).submit();
64
- }
assets/js/widget.js ADDED
@@ -0,0 +1,74 @@
1
+ /*!
2
+ * WordPress Social Login
3
+ *
4
+ * http://miled.github.io/wordpress-social-login/ | https://github.com/miled/wordpress-social-login
5
+ * (c) 2011-2014 Mohamed Mrassi and contributors | http://wordpress.org/plugins/wordpress-social-login/
6
+ */
7
+
8
+ /**
9
+ * Manage authentications via a popup
10
+ *
11
+ * Based on http://wordpress.org/extend/plugins/social-connect/
12
+ */
13
+
14
+ /**
15
+ * bind on click event to idps icons
16
+ */
17
+ (function($){
18
+ $(function(){
19
+ $(document).on( 'click', 'a.wp-social-login-provider', function(){
20
+ popupurl = $( '#wsl_popup_base_url' ).val();
21
+
22
+ provider = $(this).attr("data-provider");
23
+
24
+ var width = 1000;
25
+ var height = 600;
26
+ var top = ( screen.height / 2 ) - ( height / 2 ) - 50;
27
+ var left = ( screen.width / 2 ) - ( width / 2 );
28
+
29
+ window.open( popupurl + 'provider=' + provider, 'hybridauth_social_sing_on', 'location=1,status=0,scrollbars=0,height=' + height + ',width=' + width + ',top=' + top + ',left=' + left);
30
+ });
31
+ });
32
+ })(jQuery);
33
+
34
+ /**
35
+ * generate login wp form
36
+ */
37
+ window.wsl_wordpress_social_login = function( config ){
38
+ jQuery( '#loginform' ).unbind( 'submit.simplemodal-login' );
39
+
40
+ var form_id = '#loginform';
41
+
42
+ if( ! jQuery( '#loginform' ).length )
43
+ {
44
+ if( jQuery( '#registerform' ).length )
45
+ {
46
+ form_id = '#registerform';
47
+ }
48
+
49
+ else {
50
+ var login_uri = jQuery( '#wsl_login_form_uri' ).val();
51
+
52
+ jQuery('body').append( '<form id="loginform" method="post" action="' + login_uri + '"></form>' );
53
+
54
+ jQuery('#loginform').append( '<input type="hidden" id="redirect_to" name="redirect_to" value="' + window.location.href + '">' );
55
+ }
56
+ }
57
+
58
+ jQuery.each( config, function( key, value ){
59
+ jQuery( '#' + key ).remove();
60
+
61
+ jQuery( form_id ).append( '<input type="hidden" id="' + key + '" name="' + key + '" value="' + value + '">' );
62
+ });
63
+
64
+ if( jQuery( '#simplemodal-login-form' ).length )
65
+ {
66
+ var current_url = window.location.href;
67
+
68
+ jQuery( '#redirect_to' ).remove();
69
+
70
+ jQuery( form_id ).append( '<input type="hidden" id="redirect_to" name="redirect_to" value="' + current_url + '">' );
71
+ }
72
+
73
+ jQuery( form_id ).submit();
74
+ }
hybridauth/Hybrid/Auth.php CHANGED
@@ -1,401 +1,380 @@
1
- <?php
2
- /**
3
- * HybridAuth
4
- * http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth
5
- * (c) 2009-2014, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html
6
- */
7
-
8
- /**
9
- * Hybrid_Auth class
10
- *
11
- * Hybrid_Auth class provide a simple way to authenticate users via OpenID and OAuth.
12
- *
13
- * Generally, Hybrid_Auth is the only class you should instanciate and use throughout your application.
14
- */
15
- class Hybrid_Auth
16
- {
17
- public static $version = "2.3.0-dev";
18
-
19
- public static $config = array();
20
-
21
- public static $store = NULL;
22
-
23
- public static $error = NULL;
24
-
25
- public static $logger = NULL;
26
-
27
- // --------------------------------------------------------------------
28
-
29
- /**
30
- * Try to start a new session of none then initialize Hybrid_Auth
31
- *
32
- * Hybrid_Auth constructor will require either a valid config array or
33
- * a path for a configuration file as parameter. To know more please
34
- * refer to the Configuration section:
35
- * http://hybridauth.sourceforge.net/userguide/Configuration.html
36
- */
37
- function __construct( $config )
38
- {
39
- Hybrid_Auth::initialize( $config );
40
- }
41
-
42
- // --------------------------------------------------------------------
43
-
44
- /**
45
- * Try to initialize Hybrid_Auth with given $config hash or file
46
- */
47
- public static function initialize( $config )
48
- {
49
- if( ! is_array( $config ) && ! file_exists( $config ) ){
50
- throw new Exception( "Hybriauth config does not exist on the given path.", 1 );
51
- }
52
-
53
- if( ! is_array( $config ) ){
54
- $config = include $config;
55
- }
56
-
57
- // build some need'd paths
58
- $config["path_base"] = realpath( dirname( __FILE__ ) ) . "/";
59
- $config["path_libraries"] = $config["path_base"] . "thirdparty/";
60
- $config["path_resources"] = $config["path_base"] . "resources/";
61
- $config["path_providers"] = $config["path_base"] . "Providers/";
62
-
63
- // reset debug mode
64
- if( ! isset( $config["debug_mode"] ) ){
65
- $config["debug_mode"] = false;
66
- $config["debug_file"] = null;
67
- }
68
-
69
- # load hybridauth required files, a autoload is on the way...
70
- require_once $config["path_base"] . "Error.php";
71
- require_once $config["path_base"] . "Exception.php";
72
- require_once $config["path_base"] . "Logger.php";
73
-
74
- require_once $config["path_base"] . "Provider_Adapter.php";
75
-
76
- require_once $config["path_base"] . "Provider_Model.php";
77
- require_once $config["path_base"] . "Provider_Model_OpenID.php";
78
- require_once $config["path_base"] . "Provider_Model_OAuth1.php";
79
- require_once $config["path_base"] . "Provider_Model_OAuth2.php";
80
-
81
- require_once $config["path_base"] . "User.php";
82
- require_once $config["path_base"] . "User_Profile.php";
83
- require_once $config["path_base"] . "User_Contact.php";
84
- require_once $config["path_base"] . "User_Activity.php";
85
-
86
- if ( ! class_exists("Hybrid_Storage", false) ){
87
- require_once $config["path_base"] . "Storage.php";
88
- }
89
-
90
- // hash given config
91
- Hybrid_Auth::$config = $config;
92
-
93
- // instance of log mng
94
- Hybrid_Auth::$logger = new Hybrid_Logger();
95
-
96
- // instance of errors mng
97
- Hybrid_Auth::$error = new Hybrid_Error();
98
-
99
- // start session storage mng
100
- Hybrid_Auth::$store = new Hybrid_Storage();
101
-
102
- Hybrid_Logger::info( "Enter Hybrid_Auth::initialize()");
103
- Hybrid_Logger::info( "Hybrid_Auth::initialize(). PHP version: " . PHP_VERSION );
104
- Hybrid_Logger::info( "Hybrid_Auth::initialize(). Hybrid_Auth version: " . Hybrid_Auth::$version );
105
- Hybrid_Logger::info( "Hybrid_Auth::initialize(). Hybrid_Auth called from: " . Hybrid_Auth::getCurrentUrl() );
106
-
107
- // PHP Curl extension [http://www.php.net/manual/en/intro.curl.php]
108
- if ( ! function_exists('curl_init') ) {
109
- Hybrid_Logger::error('Hybridauth Library needs the CURL PHP extension.');
110
- throw new Exception('Hybridauth Library needs the CURL PHP extension.');
111
- }
112
-
113
- // PHP JSON extension [http://php.net/manual/en/book.json.php]
114
- if ( ! function_exists('json_decode') ) {
115
- Hybrid_Logger::error('Hybridauth Library needs the JSON PHP extension.');
116
- throw new Exception('Hybridauth Library needs the JSON PHP extension.');
117
- }
118
-
119
- // session.name
120
- if( session_name() != "PHPSESSID" ){
121
- Hybrid_Logger::info('PHP session.name diff from default PHPSESSID. http://php.net/manual/en/session.configuration.php#ini.session.name.');
122
- }
123
-
124
- // safe_mode is on
125
- if( ini_get('safe_mode') ){
126
- Hybrid_Logger::info('PHP safe_mode is on. http://php.net/safe-mode.');
127
- }
128
-
129
- // open basedir is on
130
- if( ini_get('open_basedir') ){
131
- Hybrid_Logger::info('PHP open_basedir is on. http://php.net/open-basedir.');
132
- }
133
-
134
- Hybrid_Logger::debug( "Hybrid_Auth initialize. dump used config: ", serialize( $config ) );
135
- Hybrid_Logger::debug( "Hybrid_Auth initialize. dump current session: ", Hybrid_Auth::storage()->getSessionData() );
136
- Hybrid_Logger::info( "Hybrid_Auth initialize: check if any error is stored on the endpoint..." );
137
-
138
- if( Hybrid_Error::hasError() ){
139
- $m = Hybrid_Error::getErrorMessage();
140
- $c = Hybrid_Error::getErrorCode();
141
- $p = Hybrid_Error::getErrorPrevious();
142
-
143
- Hybrid_Logger::error( "Hybrid_Auth initialize: A stored Error found, Throw an new Exception and delete it from the store: Error#$c, '$m'" );
144
-
145
- Hybrid_Error::clearError();
146
-
147
- // try to provide the previous if any
148
- // Exception::getPrevious (PHP 5 >= 5.3.0) http://php.net/manual/en/exception.getprevious.php
149
- if ( version_compare( PHP_VERSION, '5.3.0', '>=' ) && ($p instanceof Exception) ) {
150
- throw new Exception( $m, $c, $p );
151
- }
152
- else{
153
- throw new Exception( $m, $c );
154
- }
155
- }
156
-
157
- Hybrid_Logger::info( "Hybrid_Auth initialize: no error found. initialization succeed." );
158
-
159
- // Endof initialize
160
- }
161
-
162
- // --------------------------------------------------------------------
163
-
164
- /**
165
- * Hybrid storage system accessor
166
- *
167
- * Users sessions are stored using HybridAuth storage system ( HybridAuth 2.0 handle PHP Session only) and can be accessed directly by
168
- * Hybrid_Auth::storage()->get($key) to retrieves the data for the given key, or calling
169
- * Hybrid_Auth::storage()->set($key, $value) to store the key => $value set.
170
- */
171
- public static function storage()
172
- {
173
- return Hybrid_Auth::$store;
174
- }
175
-
176
- // --------------------------------------------------------------------
177
-
178
- /**
179
- * Get hybridauth session data.
180
- */
181
- function getSessionData()
182
- {
183
- return Hybrid_Auth::storage()->getSessionData();
184
- }
185
-
186
- // --------------------------------------------------------------------
187
-
188
- /**
189
- * restore hybridauth session data.
190
- */
191
- function restoreSessionData( $sessiondata = NULL )
192
- {
193
- Hybrid_Auth::storage()->restoreSessionData( $sessiondata );
194
- }
195
-
196
- // --------------------------------------------------------------------
197
-
198
- /**
199
- * Try to authenticate the user with a given provider.
200
- *
201
- * If the user is already connected we just return and instance of provider adapter,
202
- * ELSE, try to authenticate and authorize the user with the provider.
203
- *
204
- * $params is generally an array with required info in order for this provider and HybridAuth to work,
205
- * like :
206
- * hauth_return_to: URL to call back after authentication is done
207
- * openid_identifier: The OpenID identity provider identifier
208
- * google_service: can be "Users" for Google user accounts service or "Apps" for Google hosted Apps
209
- */
210
- public static function authenticate( $providerId, $params = NULL )
211
- {
212
- Hybrid_Logger::info( "Enter Hybrid_Auth::authenticate( $providerId )" );
213
-
214
- // if user not connected to $providerId then try setup a new adapter and start the login process for this provider
215
- if( ! Hybrid_Auth::storage()->get( "hauth_session.$providerId.is_logged_in" ) ){
216
- Hybrid_Logger::info( "Hybrid_Auth::authenticate( $providerId ), User not connected to the provider. Try to authenticate.." );
217
-
218
- $provider_adapter = Hybrid_Auth::setup( $providerId, $params );
219
-
220
- $provider_adapter->login();
221
- }
222
-
223
- // else, then return the adapter instance for the given provider
224
- else{
225
- Hybrid_Logger::info( "Hybrid_Auth::authenticate( $providerId ), User is already connected to this provider. Return the adapter instance." );
226
-
227
- return Hybrid_Auth::getAdapter( $providerId );
228
- }
229
- }
230
-
231
- // --------------------------------------------------------------------
232
-
233
- /**
234
- * Return the adapter instance for an authenticated provider
235
- */
236
- public static function getAdapter( $providerId = NULL )
237
- {
238
- Hybrid_Logger::info( "Enter Hybrid_Auth::getAdapter( $providerId )" );
239
-
240
- return Hybrid_Auth::setup( $providerId );
241
- }
242
-
243
- // --------------------------------------------------------------------
244
-
245
- /**
246
- * Setup an adapter for a given provider
247
- */
248
- public static function setup( $providerId, $params = NULL )
249
- {
250
- Hybrid_Logger::debug( "Enter Hybrid_Auth::setup( $providerId )", $params );
251
-
252
- if( ! $params ){
253
- $params = Hybrid_Auth::storage()->get( "hauth_session.$providerId.id_provider_params" );
254
-
255
- Hybrid_Logger::debug( "Hybrid_Auth::setup( $providerId ), no params given. Trying to get the stored for this provider.", $params );
256
- }
257
-
258
- if( ! $params ){
259
- $params = ARRAY();
260
-
261
- Hybrid_Logger::info( "Hybrid_Auth::setup( $providerId ), no stored params found for this provider. Initialize a new one for new session" );
262
- }
263
-
264
- if( is_array($params) && ! isset( $params["hauth_return_to"] ) ){
265
- $params["hauth_return_to"] = Hybrid_Auth::getCurrentUrl();
266
-
267
- Hybrid_Logger::debug( "Hybrid_Auth::setup( $providerId ). HybridAuth Callback URL set to: ", $params["hauth_return_to"] );
268
- }
269
-
270
- # instantiate a new IDProvider Adapter
271
- $provider = new Hybrid_Provider_Adapter();
272
-
273
- $provider->factory( $providerId, $params );
274
-
275
- return $provider;
276
- }
277
-
278
- // --------------------------------------------------------------------
279
-
280
- /**
281
- * Check if the current user is connected to a given provider
282
- */
283
- public static function isConnectedWith( $providerId )
284
- {
285
- return (bool) Hybrid_Auth::storage()->get( "hauth_session.{$providerId}.is_logged_in" );
286
- }
287
-
288
- // --------------------------------------------------------------------
289
-
290
- /**
291
- * Return array listing all authenticated providers
292
- */
293
- public static function getConnectedProviders()
294
- {
295
- $idps = array();
296
-
297
- foreach( Hybrid_Auth::$config["providers"] as $idpid => $params ){
298
- if( Hybrid_Auth::isConnectedWith( $idpid ) ){
299
- $idps[] = $idpid;
300
- }
301
- }
302
-
303
- return $idps;
304
- }
305
-
306
- // --------------------------------------------------------------------
307
-
308
- /**
309
- * Return array listing all enabled providers as well as a flag if you are connected.
310
- */
311
- public static function getProviders()
312
- {
313
- $idps = array();
314
-
315
- foreach( Hybrid_Auth::$config["providers"] as $idpid => $params ){
316
- if($params['enabled']) {
317
- $idps[$idpid] = array( 'connected' => false );
318
-
319
- if( Hybrid_Auth::isConnectedWith( $idpid ) ){
320
- $idps[$idpid]['connected'] = true;
321
- }
322
- }
323
- }
324
-
325
- return $idps;
326
- }
327
-
328
- // --------------------------------------------------------------------
329
-
330
- /**
331
- * A generic function to logout all connected provider at once
332
- */
333
- public static function logoutAllProviders()
334
- {
335
- $idps = Hybrid_Auth::getConnectedProviders();
336
-
337
- foreach( $idps as $idp ){
338
- $adapter = Hybrid_Auth::getAdapter( $idp );
339
-
340
- $adapter->logout();
341
- }
342
- }
343
-
344
- // --------------------------------------------------------------------
345
-
346
- /**
347
- * Utility function, redirect to a given URL with php header or using javascript location.href
348
- */
349
- public static function redirect( $url, $mode = "PHP" )
350
- {
351
- Hybrid_Logger::info( "Enter Hybrid_Auth::redirect( $url, $mode )" );
352
-
353
- if( $mode == "PHP" ){
354
- header( "Location: $url" ) ;
355
- }
356
- elseif( $mode == "JS" ){
357
- echo '<html>';
358
- echo '<head>';
359
- echo '<script type="text/javascript">';
360
- echo 'function redirect(){ window.top.location.href="' . $url . '"; }';
361
- echo '</script>';
362
- echo '</head>';
363
- echo '<body onload="redirect()">';
364
- echo 'Redirecting, please wait...';
365
- echo '</body>';
366
- echo '</html>';
367
- }
368
-
369
- die();
370
- }
371
-
372
- // --------------------------------------------------------------------
373
-
374
- /**
375
- * Utility function, return the current url. TRUE to get $_SERVER['REQUEST_URI'], FALSE for $_SERVER['PHP_SELF']
376
- */
377
- public static function getCurrentUrl( $request_uri = true )
378
- {
379
- if(
380
- isset( $_SERVER['HTTPS'] ) && ( $_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1 )
381
- || isset( $_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'
382
- ){
383
- $protocol = 'https://';
384
- }
385
- else {
386
- $protocol = 'http://';
387
- }
388
-
389
- $url = $protocol . $_SERVER['HTTP_HOST'];
390
-
391
- if( $request_uri ){
392
- $url .= $_SERVER['REQUEST_URI'];
393
- }
394
- else{
395
- $url .= $_SERVER['PHP_SELF'];
396
- }
397
-
398
- // return current url
399
- return $url;
400
- }
401
- }
1
+ <?php
2
+ /**
3
+ * HybridAuth
4
+ * http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth
5
+ * (c) 2009-2014, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html
6
+ */
7
+
8
+ /**
9
+ * Hybrid_Auth class
10
+ *
11
+ * Hybrid_Auth class provide a simple way to authenticate users via OpenID and OAuth.
12
+ *
13
+ * Generally, Hybrid_Auth is the only class you should instantiate and use throughout your application.
14
+ */
15
+ class Hybrid_Auth
16
+ {
17
+ public static $version = "2.4.1-wsl-fork";
18
+
19
+ public static $config = array();
20
+
21
+ public static $store = NULL;
22
+
23
+ public static $error = NULL;
24
+
25
+ // --------------------------------------------------------------------
26
+
27
+ /**
28
+ * Try to start a new session of none then initialize Hybrid_Auth
29
+ *
30
+ * Hybrid_Auth constructor will require either a valid config array or
31
+ * a path for a configuration file as parameter. To know more please
32
+ * refer to the Configuration section:
33
+ * http://hybridauth.sourceforge.net/userguide/Configuration.html
34
+ */
35
+ function __construct( $config )
36
+ {
37
+ Hybrid_Auth::initialize( $config );
38
+ }
39
+
40
+ // --------------------------------------------------------------------
41
+
42
+ /**
43
+ * Try to initialize Hybrid_Auth with given $config hash or file
44
+ */
45
+ public static function initialize( $config )
46
+ {
47
+ if( ! is_array( $config ) && ! file_exists( $config ) ){
48
+ throw new Exception( "Hybriauth config does not exist on the given path.", 1 );
49
+ }
50
+
51
+ if( ! is_array( $config ) ){
52
+ $config = include $config;
53
+ }
54
+
55
+ // build some need'd paths
56
+ $path_base = realpath( dirname( __FILE__ ) ) . "/";
57
+
58
+ # load hybridauth required files
59
+ require_once $path_base . "Error.php";
60
+ require_once $path_base . "Exception.php";
61
+
62
+ require_once $path_base . "Provider_Adapter.php";
63
+
64
+ require_once $path_base . "Provider_Model.php";
65
+ require_once $path_base . "Provider_Model_OpenID.php";
66
+ require_once $path_base . "Provider_Model_OAuth1.php";
67
+ require_once $path_base . "Provider_Model_OAuth2.php";
68
+
69
+ require_once $path_base . "User.php";
70
+ require_once $path_base . "User_Profile.php";
71
+ require_once $path_base . "User_Contact.php";
72
+ require_once $path_base . "User_Activity.php";
73
+
74
+ require_once $path_base . "Storage.php";
75
+
76
+ // hash given config
77
+ Hybrid_Auth::$config = $config;
78
+
79
+ // instance of errors mng
80
+ Hybrid_Auth::$error = new Hybrid_Error();
81
+
82
+ // start session storage mng
83
+ Hybrid_Auth::$store = new Hybrid_Storage();
84
+
85
+ if( Hybrid_Error::hasError() ){
86
+ $m = Hybrid_Error::getErrorMessage();
87
+ $c = Hybrid_Error::getErrorCode();
88
+
89
+ Hybrid_Error::clearError();
90
+
91
+ throw new Exception( $m, $c );
92
+ }
93
+
94
+ // Endof initialize
95
+ }
96
+
97
+ // --------------------------------------------------------------------
98
+
99
+ /**
100
+ * Hybrid storage system accessors
101
+ *
102
+ * Users sessions are stored using HybridAuth storage system ( HybridAuth 2.0 handle PHP Session only) and can be accessed directly by
103
+ * Hybrid_Auth::storage()->get($key) to retrieves the data for the given key, or calling
104
+ * Hybrid_Auth::storage()->set($key, $value) to store the key => $value set.
105
+ */
106
+ public static function storage()
107
+ {
108
+ return Hybrid_Auth::$store;
109
+ }
110
+
111
+ // --------------------------------------------------------------------
112
+
113
+ /**
114
+ * Get hybridauth session data.
115
+ */
116
+ function getSessionData()
117
+ {
118
+ return Hybrid_Auth::storage()->getSessionData();
119
+ }
120
+
121
+ // --------------------------------------------------------------------
122
+
123
+ /**
124
+ * restore hybridauth session data.
125
+ */
126
+ function restoreSessionData( $sessiondata = NULL )
127
+ {
128
+ Hybrid_Auth::storage()->restoreSessionData( $sessiondata );
129
+ }
130
+
131
+ // --------------------------------------------------------------------
132
+
133
+ /**
134
+ * Try to authenticate the user with a given provider.
135
+ *
136
+ * If the user is already connected we just return and instance of provider adapter,
137
+ * ELSE, try to authenticate and authorize the user with the provider.
138
+ *
139
+ * $params is generally an array with required info in order for this provider and HybridAuth to work,
140
+ * like :
141
+ * hauth_return_to: URL to call back after authentication is done
142
+ * openid_identifier: The OpenID identity provider identifier
143
+ * google_service: can be "Users" for Google user accounts service or "Apps" for Google hosted Apps
144
+ */
145
+ public static function authenticate( $providerId, $params = NULL )
146
+ {
147
+ // if user not connected to $providerId then try setup a new adapter and start the login process for this provider
148
+ if( ! Hybrid_Auth::storage()->get( "hauth_session.$providerId.is_logged_in" ) ){
149
+ $provider_adapter = Hybrid_Auth::setup( $providerId, $params );
150
+
151
+ $provider_adapter->login();
152
+ }
153
+
154
+ // else, then return the adapter instance for the given provider
155
+ else{
156
+ return Hybrid_Auth::getAdapter( $providerId );
157
+ }
158
+ }
159
+
160
+ // --------------------------------------------------------------------
161
+
162
+ /**
163
+ * Return the adapter instance for an authenticated provider
164
+ */
165
+ public static function getAdapter( $providerId = NULL )
166
+ {
167
+ if( ! Hybrid_Auth::$store ) {
168
+ require_once realpath( dirname( __FILE__ ) ) . "/Storage.php";
169
+
170
+ Hybrid_Auth::$store = new Hybrid_Storage();
171
+ }
172
+
173
+ if( ! Hybrid_Auth::$config ) {
174
+ Hybrid_Auth::initialize( Hybrid_Auth::storage()->config( "CONFIG" ) );
175
+ }
176
+
177
+ return Hybrid_Auth::setup( $providerId );
178
+ }
179
+
180
+ // --------------------------------------------------------------------
181
+
182
+ /**
183
+ * Return the latest api error
184
+ */
185
+ public static function getLatestApiError()
186
+ {
187
+ return Hybrid_Error::getErrorMessage();
188
+ }
189
+
190
+ // --------------------------------------------------------------------
191
+
192
+ /**
193
+ * Setup an adapter for a given provider
194
+ */
195
+ public static function setup( $providerId, $params = NULL )
196
+ {
197
+ if( ! $params ){
198
+ $params = Hybrid_Auth::storage()->get( "hauth_session.$providerId.id_provider_params" );
199
+ }
200
+
201
+ if( ! $params ){
202
+ $params = ARRAY();
203
+ }
204
+
205
+ if( is_array($params) && ! isset( $params["hauth_return_to"] ) ){
206
+ $params["hauth_return_to"] = Hybrid_Auth::getCurrentUrl();
207
+ }
208
+
209
+ # instantiate a new IDProvider Adapter
210
+ $provider = new Hybrid_Provider_Adapter();
211
+
212
+ $provider->factory( $providerId, $params );
213
+
214
+ return $provider;
215
+ }
216
+
217
+ // --------------------------------------------------------------------
218
+
219
+ /**
220
+ * Check if the current user is connected to a given provider
221
+ */
222
+ public static function isConnectedWith( $providerId )
223
+ {
224
+ return (bool) Hybrid_Auth::storage()->get( "hauth_session.{$providerId}.is_logged_in" );
225
+ }
226
+
227
+ // --------------------------------------------------------------------
228
+
229
+ /**
230
+ * Return array listing all authenticated providers
231
+ */
232
+ public static function getConnectedProviders()
233
+ {
234
+ $idps = array();
235
+
236
+ foreach( Hybrid_Auth::$config["providers"] as $idpid => $params ){
237
+ if( Hybrid_Auth::isConnectedWith( $idpid ) ){
238
+ $idps[] = $idpid;
239
+ }
240
+ }
241
+
242
+ return $idps;
243
+ }
244
+
245
+ // --------------------------------------------------------------------
246
+
247
+ /**
248
+ * Return array listing all enabled providers as well as a flag if you are connected.
249
+ */
250
+ public static function getProviders()
251
+ {
252
+ $idps = array();
253
+
254
+ foreach( Hybrid_Auth::$config["providers"] as $idpid => $params ){
255
+ if($params['enabled']) {
256
+ $idps[$idpid] = array( 'connected' => false );
257
+
258
+ if( Hybrid_Auth::isConnectedWith( $idpid ) ){
259
+ $idps[$idpid]['connected'] = true;
260
+ }
261
+ }
262
+ }
263
+
264
+ return $idps;
265
+ }
266
+
267
+ // --------------------------------------------------------------------
268
+
269
+ /**
270
+ * A generic function to logout all connected provider at once
271
+ */
272
+ public static function logoutAllProviders()
273
+ {
274
+ $idps = Hybrid_Auth::getConnectedProviders();
275
+
276
+ foreach( $idps as $idp ){
277
+ $adapter = Hybrid_Auth::getAdapter( $idp );
278
+
279
+ $adapter->logout();
280
+ }
281
+ }
282
+
283
+ // --------------------------------------------------------------------
284
+
285
+ /**
286
+ * Utility function, redirect to a given URL with php header or using javascript location.href
287
+ */
288
+ public static function redirect( $url, $mode = "PHP" )
289
+ {
290
+ if( $mode == "PHP" ){
291
+ header( "Location: $url" ) ;
292
+ }
293
+ elseif( $mode == "JS" ){
294
+ echo '<html>';
295
+ echo '<head>';
296
+ echo '<script type="text/javascript">';
297
+ echo 'function redirect(){ window.top.location.href="' . $url . '"; }';
298
+ echo '</script>';
299
+ echo '</head>';
300
+ echo '<body onload="redirect()">';
301
+ echo 'Redirecting, please wait...';
302
+ echo '</body>';
303
+ echo '</html>';
304
+ }
305
+
306
+ die();
307
+ }
308
+
309
+ // --------------------------------------------------------------------
310
+
311
+ /**
312
+ * Utility function, return the current url. TRUE to get $_SERVER['REQUEST_URI'], FALSE for $_SERVER['PHP_SELF']
313
+ */
314
+ public static function getCurrentUrl( $request_uri = true )
315
+ {
316
+ $wsl_is_https_on = false;
317
+
318
+ if( ! empty ( $_SERVER ['SERVER_PORT'] ) )
319
+ {
320
+ if(trim ( $_SERVER ['SERVER_PORT'] ) == '443')
321
+ {
322
+ $wsl_is_https_on = true;
323
+ }
324
+ }
325
+
326
+ if ( ! empty ( $_SERVER ['HTTP_X_FORWARDED_PROTO'] ) )
327
+ {
328
+ if(strtolower (trim ($_SERVER ['HTTP_X_FORWARDED_PROTO'])) == 'https')
329
+ {
330
+ $wsl_is_https_on = true;
331
+ }
332
+ }
333
+
334
+ if( ! empty ( $_SERVER ['HTTPS'] ) )
335
+ {
336
+ if ( strtolower( trim($_SERVER ['HTTPS'] ) ) == 'on' OR trim ($_SERVER ['HTTPS']) == '1')
337
+ {
338
+ $wsl_is_https_on = true;
339
+ }
340
+ }
341
+
342
+ //Extract parts
343
+ $request_uri = (isset ($_SERVER ['REQUEST_URI']) ? $_SERVER ['REQUEST_URI'] : $_SERVER ['PHP_SELF']);
344
+ $request_protocol = ( $wsl_is_https_on ? 'https' : 'http');
345
+ $request_host = (isset ($_SERVER ['HTTP_X_FORWARDED_HOST']) ? $_SERVER ['HTTP_X_FORWARDED_HOST'] : (isset ($_SERVER ['HTTP_HOST']) ? $_SERVER ['HTTP_HOST'] : $_SERVER ['SERVER_NAME']));
346
+
347
+ //Port of this request
348
+ $request_port = '';
349
+
350
+ //We are using a proxy
351
+ if( isset( $_SERVER ['HTTP_X_FORWARDED_PORT'] ) )
352
+ {
353
+ // SERVER_PORT is usually wrong on proxies, don't use it!
354
+ $request_port = intval($_SERVER ['HTTP_X_FORWARDED_PORT']);
355
+ }
356
+ //Does not seem like a proxy
357
+ elseif( isset( $_SERVER ['SERVER_PORT'] ) )
358
+ {
359
+ $request_port = intval($_SERVER ['SERVER_PORT']);
360
+ }
361
+
362
+ //Remove standard ports
363
+ $request_port = (!in_array($request_port, array (80, 443)) ? $request_port : '');
364
+
365
+ //Build url
366
+ $current_url = $request_protocol . '://' . $request_host . ( ! empty ($request_port) ? (':'.$request_port) : '');
367
+
368
+ if( $request_uri )
369
+ {
370
+ $current_url .= $request_uri;
371
+ }
372
+ else
373
+ {
374
+ $current_url .= $_SERVER ['PHP_SELF'];
375
+ }
376
+
377
+ //Done
378
+ return $current_url;
379
+ }
380
+ }
hybridauth/Hybrid/Endpoint.php CHANGED
@@ -10,7 +10,8 @@
10
*
11
* Hybrid_Endpoint class provides a simple way to handle the OpenID and OAuth endpoint.
12
*/
13
- class Hybrid_Endpoint {
14
public static $request = NULL;
15
public static $initDone = FALSE;
16
@@ -117,8 +118,6 @@ class Hybrid_Endpoint {
117
118
# check if page accessed directly
119
if( ! Hybrid_Auth::storage()->get( "hauth_session.$provider_id.hauth_endpoint" ) ) {
120
- Hybrid_Logger::error( "Endpoint: hauth_endpoint parameter is not defined on hauth_start, halt login process!" );
121
-
122
throw new Hybrid_Exception( "You cannot access this page directly." );
123
}
124
@@ -127,19 +126,14 @@ class Hybrid_Endpoint {
127
128
# if REQUESTed hauth_idprovider is wrong, session not created, etc.
129
if( ! $hauth ) {
130
- Hybrid_Logger::error( "Endpoint: Invalid parameter on hauth_start!" );
131
-
132
throw new Hybrid_Exception( "Invalid parameter! Please return to the login page and try again." );
133
}
134
135
try {
136
- Hybrid_Logger::info( "Endpoint: call adapter [{$provider_id}] loginBegin()" );
137
-
138
$hauth->adapter->loginBegin();
139
}
140
catch ( Exception $e ) {
141
- Hybrid_Logger::error( "Exception:" . $e->getMessage(), $e );
142
- Hybrid_Error::setError( $e->getMessage(), $e->getCode(), $e->getTraceAsString(), $e->getPrevious() );
143
144
$hauth->returnToCallbackUrl();
145
}
@@ -156,30 +150,28 @@ class Hybrid_Endpoint {
156
157
$provider_id = trim( strip_tags( Hybrid_Endpoint::$request["hauth_done"] ) );
158
159
$hauth = Hybrid_Auth::setup( $provider_id );
160
161
if( ! $hauth ) {
162
- Hybrid_Logger::error( "Endpoint: Invalid parameter on hauth_done!" );
163
-
164
$hauth->adapter->setUserUnconnected();
165
166
throw new Hybrid_Exception( "Invalid parameter! Please return to the login page and try again." );
167
}
168
169
try {
170
- Hybrid_Logger::info( "Endpoint: call adapter [{$provider_id}] loginFinish() " );
171
-
172
$hauth->adapter->loginFinish();
173
}
174
catch( Exception $e ){
175
- Hybrid_Logger::error( "Exception:" . $e->getMessage(), $e );
176
- Hybrid_Error::setError( $e->getMessage(), $e->getCode(), $e->getTraceAsString(), $e->getPrevious());
177
178
$hauth->adapter->setUserUnconnected();
179
}
180
181
- Hybrid_Logger::info( "Endpoint: job done. retrun to callback url." );
182
-
183
$hauth->returnToCallbackUrl();
184
die();
185
}
@@ -191,24 +183,16 @@ class Hybrid_Endpoint {
191
192
# Init Hybrid_Auth
193
try {
194
- if(!class_exists("Hybrid_Storage")){
195
- require_once realpath( dirname( __FILE__ ) ) . "/Storage.php";
196
- }
197
-
198
$storage = new Hybrid_Storage();
199
200
// Check if Hybrid_Auth session already exist
201
- if ( ! $storage->config( "CONFIG" ) ) {
202
- Hybrid_Logger::error( "Endpoint: Config storage not found when trying to init Hyrid_Auth. " );
203
-
204
throw new Hybrid_Exception( "You cannot access this page directly." );
205
}
206
207
Hybrid_Auth::initialize( $storage->config( "CONFIG" ) );
208
}
209
catch ( Exception $e ){
210
- Hybrid_Logger::error( "Endpoint: Error while trying to init Hybrid_Auth: " . $e->getMessage());
211
-
212
throw new Hybrid_Exception( "Oophs. Error!" );
213
}
214
}
10
*
11
* Hybrid_Endpoint class provides a simple way to handle the OpenID and OAuth endpoint.
12
*/
13
+ class Hybrid_Endpoint
14
+ {
15
public static $request = NULL;
16
public static $initDone = FALSE;
17
118
119
# check if page accessed directly
120
if( ! Hybrid_Auth::storage()->get( "hauth_session.$provider_id.hauth_endpoint" ) ) {
121
throw new Hybrid_Exception( "You cannot access this page directly." );
122
}
123
126
127
# if REQUESTed hauth_idprovider is wrong, session not created, etc.
128
if( ! $hauth ) {
129
throw new Hybrid_Exception( "Invalid parameter! Please return to the login page and try again." );
130
}
131
132
try {
133
$hauth->adapter->loginBegin();
134
}
135
catch ( Exception $e ) {
136
+ Hybrid_Error::setError( $e->getMessage(), $e->getCode() );
137
138
$hauth->returnToCallbackUrl();
139
}
150
151
$provider_id = trim( strip_tags( Hybrid_Endpoint::$request["hauth_done"] ) );
152
153
+ # check if page accessed directly
154
+ if( ! Hybrid_Auth::storage()->get( "hauth_session.$provider_id.hauth_endpoint" ) ) {
155
+ throw new Hybrid_Exception( "You cannot access this page directly." );
156
+ }
157
+
158
$hauth = Hybrid_Auth::setup( $provider_id );
159
160
if( ! $hauth ) {
161
$hauth->adapter->setUserUnconnected();
162
163
throw new Hybrid_Exception( "Invalid parameter! Please return to the login page and try again." );
164
}
165
166
try {
167
$hauth->adapter->loginFinish();
168
}
169
catch( Exception $e ){
170
+ Hybrid_Error::setError( $e->getMessage(), $e->getCode() );
171
172
$hauth->adapter->setUserUnconnected();
173
}
174
175
$hauth->returnToCallbackUrl();
176
die();
177
}
183
184
# Init Hybrid_Auth
185
try {
186
$storage = new Hybrid_Storage();
187
188
// Check if Hybrid_Auth session already exist
189
+ if ( ! $storage->config( "CONFIG" ) ){
190
throw new Hybrid_Exception( "You cannot access this page directly." );
191
}
192
193
Hybrid_Auth::initialize( $storage->config( "CONFIG" ) );
194
}
195
catch ( Exception $e ){
196
throw new Hybrid_Exception( "Oophs. Error!" );
197
}
198
}
hybridauth/Hybrid/Error.php CHANGED
@@ -1,89 +1,87 @@
1
- <?php
2
- /**
3
- * HybridAuth
4
- * http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth
5
- * (c) 2009-2014, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html
6
- */
7
-
8
- /**
9
- * Errors manager
10
- *
11
- * HybridAuth errors are stored in Hybrid::storage() and not displayed directly to the end user
12
- */
13
- class Hybrid_Error
14
- {
15
- /**
16
- * Store error in session
17
- *
18
- * @param String $message
19
- * @param Number $code
20
- * @param String $trace
21
- * @param String $previous
22
- */
23
- public static function setError( $message, $code = NULL, $trace = NULL, $previous = NULL )
24
- {
25
- Hybrid_Logger::info( "Enter Hybrid_Error::setError( $message )" );
26
-
27
- Hybrid_Auth::storage()->set( "hauth_session.error.status" , 1 );
28
- Hybrid_Auth::storage()->set( "hauth_session.error.message" , $message );
29
- Hybrid_Auth::storage()->set( "hauth_session.error.code" , $code );
30
- Hybrid_Auth::storage()->set( "hauth_session.error.trace" , $trace );
31
- Hybrid_Auth::storage()->set( "hauth_session.error.previous", $previous );
32
- }
33
-
34
- /**
35
- * Clear the last error
36
- */
37
- public static function clearError()
38
- {
39
- Hybrid_Logger::info( "Enter Hybrid_Error::clearError()" );
40
-
41
- Hybrid_Auth::storage()->delete( "hauth_session.error.status" );
42
- Hybrid_Auth::storage()->delete( "hauth_session.error.message" );
43
- Hybrid_Auth::storage()->delete( "hauth_session.error.code" );
44
- Hybrid_Auth::storage()->delete( "hauth_session.error.trace" );
45
- Hybrid_Auth::storage()->delete( "hauth_session.error.previous" );
46
- }
47
-
48
- /**
49
- * Checks to see if there is a an error.
50
- *
51
- * @return boolean True if there is an error.
52
- */
53
- public static function hasError()
54
- {
55
- return (bool) Hybrid_Auth::storage()->get( "hauth_session.error.status" );
56
- }
57
-
58
- /**
59
- * return error message
60
- */
61
- public static function getErrorMessage()
62
- {
63
- return Hybrid_Auth::storage()->get( "hauth_session.error.message" );
64
- }
65
-
66
- /**
67
- * return error code
68
- */
69
- public static function getErrorCode()
70
- {
71
- return Hybrid_Auth::storage()->get( "hauth_session.error.code" );
72
- }
73
-
74
- /**
75
- * return string detailed error backtrace as string.
76
- */
77
- public static function getErrorTrace()
78
- {
79
- return Hybrid_Auth::storage()->get( "hauth_session.error.trace" );
80
- }
81
-
82
- /**
83
- * @return string detailed error backtrace as string.
84
- */
85
- public static function getErrorPrevious()
86
- {
87
- return Hybrid_Auth::storage()->get( "hauth_session.error.previous" );
88
- }
89
- }
1
+ <?php
2
+ /**
3
+ * HybridAuth
4
+ * http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth
5
+ * (c) 2009-2014, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html
6
+ */
7
+
8
+ /**
9
+ * Errors manager
10
+ *
11
+ * HybridAuth errors are stored in Hybrid::storage() and not displayed directly to the end user
12
+ */
13
+ class Hybrid_Error
14
+ {
15
+ /**
16
+ * Store error in session
17
+ *
18
+ * @param String $message
19
+ * @param Number $code
20
+ */
21
+ public static function setError( $message, $code = NULL )
22
+ {
23
+ Hybrid_Auth::storage()->set( "hauth_session.error.status" , 1 );
24
+ Hybrid_Auth::storage()->set( "hauth_session.error.message" , $message );
25
+ Hybrid_Auth::storage()->set( "hauth_session.error.code" , $code );
26
+ }
27
+
28
+ /**
29
+ * Clear the last error
30
+ */
31
+ public static function clearError()
32
+ {
33
+ Hybrid_Auth::storage()->delete( "hauth_session.error.status" );
34
+ Hybrid_Auth::storage()->delete( "hauth_session.error.message" );
35
+ Hybrid_Auth::storage()->delete( "hauth_session.error.code" );
36
+ }
37
+
38
+ /**
39
+ * Checks to see if there is a an error.
40
+ *
41
+ * @return boolean True if there is an error.
42
+ */
43
+ public static function hasError()
44
+ {
45
+ return (bool) Hybrid_Auth::storage()->get( "hauth_session.error.status" );
46
+ }
47
+
48
+ /**
49
+ * return error message
50
+ */
51
+ public static function getErrorMessage()
52
+ {
53
+ return Hybrid_Auth::storage()->get( "hauth_session.error.message" );
54
+ }
55
+
56
+ /**
57
+ * return error code
58
+ */
59
+ public static function getErrorCode()
60
+ {
61
+ return Hybrid_Auth::storage()->get( "hauth_session.error.code" );
62
+ }
63
+
64
+ /**
65
+ * set api error
66
+ */
67
+ public static function setApiError( $error )
68
+ {
69
+ return Hybrid_Auth::storage()->set( "hauth_session.error.apierror", $error );
70
+ }
71
+
72
+ /**
73
+ * set api error
74
+ */
75
+ public static function deleteApiError()
76
+ {
77
+ return Hybrid_Auth::storage()->delete( "hauth_session.error.apierror" );
78
+ }
79
+
80
+ /**
81
+ * return api error
82
+ */
83
+ public static function getApiError()
84
+ {
85
+ return Hybrid_Auth::storage() ? Hybrid_Auth::storage()->get( "hauth_session.error.apierror" ) : '';
86
+ }
87
+ }
hybridauth/Hybrid/Logger.php DELETED
@@ -1,92 +0,0 @@
1
- <?php
2
- /**
3
- * HybridAuth
4
- * http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth
5
- * (c) 2009-2014, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html
6
- */
7
-
8
- /**
9
- * Debugging and Logging manager
10
- */
11
- class Hybrid_Logger
12
- {
13
- /**
14
- * Constructor
15
- */
16
- function __construct()
17
- {
18
- // Hybrid_Auth::$config["debug_mode"] = true;
19
- // Hybrid_Auth::$config["debug_file"] = 'C:/xampp/htdocs/hybridauth/hawp4/wp-content/plugins/wordpress-social-login/log/log.log';
20
-
21
- // if debug mode is set to true, then check for the writable log file
22
- if ( Hybrid_Auth::$config["debug_mode"] ){
23
- if ( ! isset(Hybrid_Auth::$config["debug_file"]) ) {
24
- throw new Exception( "'debug_mode' is set to 'true' but no log file path 'debug_file' is set.", 1 );
25
- }
26
- elseif ( ! file_exists( Hybrid_Auth::$config["debug_file"] ) && ! is_writable( Hybrid_Auth::$config["debug_file"]) ){
27
- if ( ! touch( Hybrid_Auth::$config["debug_file"] ) ){
28
- throw new Exception( "'debug_mode' is set to 'true', but the file " . Hybrid_Auth::$config['debug_file'] . " in 'debug_file' can not be created.", 1 );
29
- }
30
- }
31
- elseif ( ! is_writable( Hybrid_Auth::$config["debug_file"] ) ){
32
- throw new Exception( "'debug_mode' is set to 'true', but the given log file path 'debug_file' is not a writable file.", 1 );
33
- }
34
- }
35
- }
36
-
37
- /**
38
- * Debug
39
- * @param String $message
40
- * @param Object $object
41
- */
42
- public static function debug( $message, $object = NULL )
43
- {
44
- if( Hybrid_Auth::$config["debug_mode"] ){
45
- $datetime = new DateTime();
46
- $datetime = $datetime->format(DATE_ATOM);
47
-
48
- file_put_contents(
49
- Hybrid_Auth::$config["debug_file"],
50
- "DEBUG -- " . $_SERVER['REMOTE_ADDR'] . " -- " . $datetime . " -- " . $message . " -- " . print_r($object, true) . "\n",
51
- FILE_APPEND
52
- );
53
- }
54
- }
55
-
56
- /**
57
- * Info
58
- * @param String $message
59
- */
60
- public static function info( $message )
61
- {
62
- if( in_array(Hybrid_Auth::$config["debug_mode"], array(true, 'info'), true) ){
63
- $datetime = new DateTime();
64
- $datetime = $datetime->format(DATE_ATOM);
65
-
66
- file_put_contents(
67
- Hybrid_Auth::$config["debug_file"],
68
- "INFO -- " . $_SERVER['REMOTE_ADDR'] . " -- " . $datetime . " -- " . $message . "\n",
69
- FILE_APPEND
70
- );
71
- }
72
- }
73
-
74
- /**
75
- * Error
76
- * @param String $message Error message
77
- * @param Object $object
78
- */
79
- public static function error($message, $object = NULL)
80
- {
81
- if(isset(Hybrid_Auth::$config["debug_mode"]) && in_array(Hybrid_Auth::$config["debug_mode"], array(true, 'info', 'error'), true) ){
82
- $datetime = new DateTime();
83
- $datetime = $datetime->format(DATE_ATOM);
84
-
85
- file_put_contents(
86
- Hybrid_Auth::$config["debug_file"],
87
- "ERROR -- " . $_SERVER['REMOTE_ADDR'] . " -- " . $datetime . " -- " . $message . " -- " . print_r($object, true) . "\n",
88
- FILE_APPEND
89
- );
90
- }
91
- }
92
- }
hybridauth/Hybrid/Provider_Adapter.php CHANGED
@@ -1,322 +1,313 @@
1
- <?php
2
- /**
3
- * HybridAuth
4
- * http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth
5
- * (c) 2009-2014, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html
6
- */
7
-
8
- /**
9
- * Hybrid_Provider_Adapter is the basic class which Hybrid_Auth will use
10
- * to connect users to a given provider.
11
- *
12
- * Basically Hybrid_Provider_Adapter will create a bridge from your php
13
- * application to the provider api.
14
- *
15
- * Hybrid_Auth will automatically load Hybrid_Provider_Adapter and create
16
- * an instance of it for each authenticated provider.
17
- */
18
- class Hybrid_Provider_Adapter
19
- {
20
- /**
21
- * Provider ID (or unique name)
22
- * @var Numeric/String
23
- */
24
- public $id = NULL ;
25
-
26
- /**
27
- * Provider adapter specific config
28
- * @var Array
29
- */
30
- public $config = NULL ;
31
-
32
- /**
33
- * Provider adapter extra parameters
34
- * @var array
35
- */
36
- public $params = array() ;
37
-
38
- /**
39
- * Provider adapter wrapper path
40
- * @var String
41
- */
42
- public $wrapper = NULL ;
43
-
44
- /**
45
- * Provider adapter instance
46
- * @var object
47
- */
48
- public $adapter = NULL ;
49
-
50
- // --------------------------------------------------------------------
51
-
52
- /**
53
- * create a new adapter switch IDp name or ID
54
- *
55
- * @param string $id The id or name of the IDp
56
- * @param array $params (optional) required parameters by the adapter
57
- */
58
- function factory( $id, $params = array() )
59
- {
60
- Hybrid_Logger::info( "Enter Hybrid_Provider_Adapter::factory( $id )" );
61
-
62
- # init the adapter config and params
63
- $this->id = $id;
64
- $this->params = $params;
65
- $this->id = $this->getProviderCiId( $this->id );
66
- $this->config = $this->getConfigById( $this->id );
67
-
68
- # check the IDp id
69
- if( ! $this->id ){
70
- throw new Exception( "No provider ID specified.", 2 );
71
- }
72
-
73
- # check the IDp config
74
- if( ! $this->config ){
75
- throw new Exception( "Unknown Provider ID, check your configuration file.", 3 );
76
- }
77
-
78
- # check the IDp adapter is enabled
79
- if( ! $this->config["enabled"] ){
80
- throw new Exception( "The provider '{$this->id}' is not enabled.", 3 );
81
- }
82
-
83
- # include the adapter wrapper
84
- if( isset( $this->config["wrapper"] ) && is_array( $this->config["wrapper"] ) ){
85
- if (isset( $this->config["wrapper"]["path"] )) {
86
- require_once $this->config["wrapper"]["path"];
87
- }
88
-
89
- if( ! class_exists( $this->config["wrapper"]["class"] ) ){
90
- throw new Exception( "Unable to load the adapter class.", 3 );
91
- }
92
-
93
- $this->wrapper = $this->config["wrapper"]["class"];
94
- }
95
- else{
96
- require_once Hybrid_Auth::$config["path_providers"] . $this->id . ".php" ;
97
-
98
- $this->wrapper = "Hybrid_Providers_" . $this->id;
99
- }
100
-
101
- # create the adapter instance, and pass the current params and config
102
- $this->adapter = new $this->wrapper( $this->id, $this->config, $this->params );
103
-
104
- return $this;
105
- }
106
-
107
- // --------------------------------------------------------------------
108
-
109
- /**
110
- * Hybrid_Provider_Adapter::login(), prepare the user session and the authentication request
111
- * for index.php
112
- */
113
- function login()
114
- {
115
- Hybrid_Logger::info( "Enter Hybrid_Provider_Adapter::login( {$this->id} ) " );
116
-
117
- if( ! $this->adapter ){
118
- throw new Exception( "Hybrid_Provider_Adapter::login() should not directly used." );
119
- }
120
-
121
- // clear all unneeded params
122
- foreach( Hybrid_Auth::$config["providers"] as $idpid => $params ){
123
- Hybrid_Auth::storage()->delete( "hauth_session.{$idpid}.hauth_return_to" );
124
- Hybrid_Auth::storage()->delete( "hauth_session.{$idpid}.hauth_endpoint" );
125
- Hybrid_Auth::storage()->delete( "hauth_session.{$idpid}.id_provider_params" );
126
- }
127
-
128
- // make a fresh start
129
- $this->logout();
130
-
131
- # get hybridauth base url
132
- if (empty(Hybrid_Auth::$config["base_url"])) {
133
- // the base url wasn't provide, so we must use the current
134
- // url (which makes sense actually)
135
- $url = empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off' ? 'http' : 'https';
136
- $url .= '://' . $_SERVER['HTTP_HOST'];
137
- $url .= $_SERVER['REQUEST_URI'];
138
- $HYBRID_AUTH_URL_BASE = $url;
139
- } else {
140
- $HYBRID_AUTH_URL_BASE = Hybrid_Auth::$config["base_url"];
141
- }
142
-
143
- // make sure params is array
144
- if( !is_array( $this->params ) ){
145
- $this->params = array();
146
- }
147
-
148
- # we make use of session_id() as storage hash to identify the current user
149
- # using session_regenerate_id() will be a problem, but ..
150
- $this->params["hauth_token"] = session_id();
151
-
152
- # set request timestamp
153
- $this->params["hauth_time"] = time();
154
-
155
- # for default HybridAuth endpoint url hauth_login_start_url
156
- # auth.start required the IDp ID
157
- # auth.time optional login request timestamp
158
- $this->params["login_start"] = $HYBRID_AUTH_URL_BASE . ( strpos( $HYBRID_AUTH_URL_BASE, '?' ) ? '&' : '?' ) . "hauth.start={$this->id}&hauth.time={$this->params["hauth_time"]}";
159
-
160
- # for default HybridAuth endpoint url hauth_login_done_url
161
- # auth.done required the IDp ID
162
- $this->params["login_done"] = $HYBRID_AUTH_URL_BASE . ( strpos( $HYBRID_AUTH_URL_BASE, '?' ) ? '&' : '?' ) . "hauth.done={$this->id}";
163
-
164
- if( isset( $this->params["hauth_return_to"] ) ){
165
- Hybrid_Auth::storage()->set( "hauth_session.{$this->id}.hauth_return_to", $this->params["hauth_return_to"] );
166
- }
167
- if( isset( $this->params["login_done"] ) ){
168
- Hybrid_Auth::storage()->set( "hauth_session.{$this->id}.hauth_endpoint" , $this->params["login_done"] );
169
- }
170
- Hybrid_Auth::storage()->set( "hauth_session.{$this->id}.id_provider_params" , $this->params );
171
-
172
- // store config to be used by the end point
173
- Hybrid_Auth::storage()->config( "CONFIG", Hybrid_Auth::$config );
174
-
175
- // move on
176
- Hybrid_Logger::debug( "Hybrid_Provider_Adapter::login( {$this->id} ), redirect the user to login_start URL." );
177
-
178
- Hybrid_Auth::redirect( $this->params["login_start"] );
179
- }
180
-
181
- // --------------------------------------------------------------------
182
-
183
- /**
184
- * let hybridauth forget all about the user for the current provider
185
- */
186
- function logout()
187
- {
188
- $this->adapter->logout();
189
- }
190
-
191
- // --------------------------------------------------------------------
192
-
193
- /**
194
- * return true if the user is connected to the current provider
195
- */
196
- public function isUserConnected()
197
- {
198
- return $this->adapter->isUserConnected();
199
- }
200
-
201
- // --------------------------------------------------------------------
202
-
203
- /**
204
- * handle :
205
- * getUserProfile()
206
- * getUserContacts()
207
- * getUserActivity()
208
- * setUserStatus()
209
- */
210
- public function __call( $name, $arguments )
211
- {
212
- Hybrid_Logger::info( "Enter Hybrid_Provider_Adapter::$name(), Provider: {$this->id}" );
213
-
214
- if ( ! $this->isUserConnected() ){
215
- throw new Exception( "User not connected to the provider {$this->id}.", 7 );
216
- }
217
-
218
- if ( ! method_exists( $this->adapter, $name ) ){
219
- throw new Exception( "Call to undefined function Hybrid_Providers_{$this->id}::$name()." );
220
- }
221
-
222
- $counter = count( $arguments );
223
- if( $counter == 1 ){
224
- return $this->adapter->$name( $arguments[0] );
225
- }
226
- elseif( $counter == 2 ){
227
- return $this->adapter->$name( $arguments[0], $arguments[1] );
228
- }
229
- else{
230
- return $this->adapter->$name();
231
- }
232
- }
233
-
234
- // --------------------------------------------------------------------
235
-
236
- /**
237
- * If the user is connected, then return the access_token and access_token_secret
238
- * if the provider api use oauth
239
- */
240
- public function getAccessToken()
241
- {
242
- if( ! $this->adapter->isUserConnected() ){
243
- Hybrid_Logger::error( "User not connected to the provider." );
244
-
245
- throw new Exception( "User not connected to the provider.", 7 );
246
- }
247
-
248
- return
249
- ARRAY(
250
- "access_token" => $this->adapter->token( "access_token" ) , // OAuth access token
251
- "access_token_secret" => $this->adapter->token( "access_token_secret" ), // OAuth access token secret
252
- "refresh_token" => $this->adapter->token( "refresh_token" ) , // OAuth refresh token
253
- "expires_in" => $this->adapter->token( "expires_in" ) , // OPTIONAL. The duration in seconds of the access token lifetime
254
- "expires_at" => $this->adapter->token( "expires_at" ) , // OPTIONAL. Timestamp when the access_token expire. if not provided by the social api, then it should be calculated: expires_at = now + expires_in
255
- );
256
- }
257
-
258
- // --------------------------------------------------------------------
259
-
260
- /**
261
- * Naive getter of the current connected IDp API client
262
- */
263
- function api()
264
- {
265
- if( ! $this->adapter->isUserConnected() ){
266
- Hybrid_Logger::error( "User not connected to the provider." );
267
-
268
- throw new Exception( "User not connected to the provider.", 7 );
269
- }
270
-
271
- return $this->adapter->api;
272
- }
273
-
274
- // --------------------------------------------------------------------
275
-
276
- /**
277
- * redirect the user to hauth_return_to (the callback url)
278
- */
279
- function returnToCallbackUrl()
280
- {
281
- // get the stored callback url
282
- $callback_url = Hybrid_Auth::storage()->get( "hauth_session.{$this->id}.hauth_return_to" );
283
-
284
- // remove some unneeded stored data
285
- Hybrid_Auth::storage()->delete( "hauth_session.{$this->id}.hauth_return_to" );
286
- Hybrid_Auth::storage()->delete( "hauth_session.{$this->id}.hauth_endpoint" );
287
- Hybrid_Auth::storage()->delete( "hauth_session.{$this->id}.id_provider_params" );
288
-
289
- // back to home
290
- Hybrid_Auth::redirect( $callback_url );
291
- }
292
-
293
- // --------------------------------------------------------------------
294
-
295
- /**
296
- * return the provider config by id
297
- */
298
- function getConfigById( $id )
299
- {
300
- if( isset( Hybrid_Auth::$config["providers"][$id] ) ){
301
- return Hybrid_Auth::$config["providers"][$id];
302
- }
303
-
304
- return NULL;
305
- }
306
-
307
- // --------------------------------------------------------------------
308
-
309
- /**
310
- * return the provider config by id; insensitive
311
- */
312
- function getProviderCiId( $id )
313
- {
314
- foreach( Hybrid_Auth::$config["providers"] as $idpid => $params ){
315
- if( strtolower( $idpid ) == strtolower( $id ) ){
316
- return $idpid;
317
- }
318
- }
319
-
320
- return NULL;
321
- }
322
- }
1
+ <?php
2
+ /**
3
+ * HybridAuth
4
+ * http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth
5
+ * (c) 2009-2014, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html
6
+ */
7
+
8
+ /**
9
+ * Hybrid_Provider_Adapter is the basic class which Hybrid_Auth will use
10
+ * to connect users to a given provider.
11
+ *
12
+ * Basically Hybrid_Provider_Adapter will create a bridge from your php
13
+ * application to the provider api.
14
+ *
15
+ * Hybrid_Auth will automatically load Hybrid_Provider_Adapter and create
16
+ * an instance of it for each authenticated provider.
17
+ */
18
+ class Hybrid_Provider_Adapter
19
+ {
20
+ /**
21
+ * Provider ID (or unique name)
22
+ * @var Numeric/String
23
+ */
24
+ public $id = NULL ;
25
+
26
+ /**
27
+ * Provider adapter specific config
28
+ * @var Array
29
+ */
30
+ public $config = NULL ;
31
+
32
+ /**
33
+ * Provider adapter extra parameters
34
+ * @var array
35
+ */
36
+ public $params = array() ;
37
+
38
+ /**
39
+ * Provider adapter wrapper path
40
+ * @var String
41
+ */
42
+ public $wrapper = NULL ;
43
+
44
+ /**
45
+ * Provider adapter instance
46
+ * @var object
47
+ */
48
+ public $adapter = NULL ;
49
+
50
+ // --------------------------------------------------------------------
51
+
52
+ /**
53
+ * create a new adapter switch IDp name or ID
54
+ *
55
+ * @param string $id The id or name of the IDp
56
+ * @param array $params (optional) required parameters by the adapter
57
+ */
58
+ function factory( $id, $params = array() )
59
+ {
60
+ # init the adapter config and params
61
+ $this->id = $id;
62
+ $this->params = $params;
63
+ $this->id = $this->getProviderCiId( $this->id );
64
+ $this->config = $this->getConfigById( $this->id );
65
+
66
+ # check the IDp id
67
+ if( ! $this->id ){
68
+ throw new Exception( "No provider ID specified.", 2 );
69
+ }
70
+
71
+ # check the IDp config
72
+ if( ! $this->config ){
73
+ throw new Exception( "Unknown Provider ID, check your configuration file.", 3 );
74
+ }
75
+
76
+ # check the IDp adapter is enabled
77
+ if( ! $this->config["enabled"] ){
78
+ throw new Exception( "The provider '{$this->id}' is not enabled.", 3 );
79
+ }
80
+
81
+ # include the adapter wrapper
82
+ if( isset( $this->config["wrapper"] ) && is_array( $this->config["wrapper"] ) ){
83
+ if (isset( $this->config["wrapper"]["path"] )) {
84
+ require_once $this->config["wrapper"]["path"];
85
+ }
86
+
87
+ if( ! class_exists( $this->config["wrapper"]["class"] ) ){
88
+ throw new Exception( "Unable to load the adapter class.", 3 );
89
+ }
90
+
91
+ $this->wrapper = $this->config["wrapper"]["class"];
92
+ }
93
+ else{
94
+ $path_providers = realpath( dirname( __FILE__ ) ) . "/Providers/";
95
+
96
+ require_once $path_providers . $this->id . ".php" ;
97
+
98
+ $this->wrapper = "Hybrid_Providers_" . $this->id;
99
+ }
100
+
101
+ # create the adapter instance, and pass the current params and config
102
+ $this->adapter = new $this->wrapper( $this->id, $this->config, $this->params );
103
+
104
+ return $this;
105
+ }
106
+
107
+ // --------------------------------------------------------------------
108
+
109
+ /**
110
+ * Hybrid_Provider_Adapter::login(), prepare the user session and the authentication request
111
+ * for index.php
112
+ */
113
+ function login()
114
+ {
115
+ if( ! $this->adapter ){
116
+ throw new Exception( "Hybrid_Provider_Adapter::login() should not directly used." );
117
+ }
118
+
119
+ // clear all unneeded params
120
+ foreach( Hybrid_Auth::$config["providers"] as $idpid => $params ){
121
+ Hybrid_Auth::storage()->delete( "hauth_session.{$idpid}.hauth_return_to" );
122
+ Hybrid_Auth::storage()->delete( "hauth_session.{$idpid}.hauth_endpoint" );
123
+ Hybrid_Auth::storage()->delete( "hauth_session.{$idpid}.id_provider_params" );
124
+ }
125
+
126
+ // make a fresh start
127
+ $this->logout();
128
+
129
+ # get hybridauth base url
130
+ if (empty(Hybrid_Auth::$config["base_url"])) {
131
+ $HYBRID_AUTH_URL_BASE = Hybrid_Auth::getCurrentUrl( true ) ;
132
+ } else {
133
+ $HYBRID_AUTH_URL_BASE = Hybrid_Auth::$config["base_url"];
134
+ }
135
+
136
+ // make sure params is array
137
+ if( !is_array( $this->params ) ){
138
+ $this->params = array();
139
+ }
140
+
141
+ # we make use of session_id() as storage hash to identify the current user
142
+ # using session_regenerate_id() will be a problem, but ..
143
+ $this->params["hauth_token"] = session_id();
144
+
145
+ # set request timestamp
146
+ $this->params["hauth_time"] = time();
147
+
148
+ # for default HybridAuth endpoint url hauth_login_start_url
149
+ # auth.start required the IDp ID
150
+ # auth.time optional login request timestamp
151
+ $this->params["login_start"] = $HYBRID_AUTH_URL_BASE . ( strpos( $HYBRID_AUTH_URL_BASE, '?' ) ? '&' : '?' ) . "hauth.start={$this->id}&hauth.time={$this->params["hauth_time"]}";
152
+
153
+ # for default HybridAuth endpoint url hauth_login_done_url
154
+ # auth.done required the IDp ID
155
+ $this->params["login_done"] = $HYBRID_AUTH_URL_BASE . ( strpos( $HYBRID_AUTH_URL_BASE, '?' ) ? '&' : '?' ) . "hauth.done={$this->id}";
156
+
157
+ if( isset( $this->config["endpoint"] ) ){
158
+ $this->params["login_start"] = $this->config["endpoint"] . ( strpos( $HYBRID_AUTH_URL_BASE, '?' ) ? '&' : '?' ) . "hauth.start={$this->id}&hauth.time={$this->params["hauth_time"]}";
159
+ $this->params["login_done"] = $this->config["endpoint"];
160
+ }
161
+
162
+ if( isset( $this->params["hauth_return_to"] ) ){
163
+ Hybrid_Auth::storage()->set( "hauth_session.{$this->id}.hauth_return_to", $this->params["hauth_return_to"] );
164
+ }
165
+
166
+ if( isset( $this->params["login_done"] ) ){
167
+ Hybrid_Auth::storage()->set( "hauth_session.{$this->id}.hauth_endpoint" , $this->params["login_done"] );
168
+ }
169
+
170
+ Hybrid_Auth::storage()->set( "hauth_session.{$this->id}.id_provider_params" , $this->params );
171
+
172
+ // store config to be used by the end point
173
+ Hybrid_Auth::storage()->config( "CONFIG", Hybrid_Auth::$config );
174
+
175
+ Hybrid_Auth::redirect( $this->params["login_start"] );
176
+ }
177
+
178
+ // --------------------------------------------------------------------
179
+
180
+ /**
181
+ * let hybridauth forget all about the user for the current provider
182
+ */
183
+ function logout()
184
+ {
185
+ $this->adapter->logout();
186
+ }
187
+
188
+ // --------------------------------------------------------------------
189
+
190
+ /**
191
+ * return true if the user is connected to the current provider
192
+ */
193
+ public function isUserConnected()
194
+ {
195
+ return $this->adapter->isUserConnected();
196
+ }
197
+
198
+ // --------------------------------------------------------------------
199
+
200
+ /**
201
+ * handle :
202
+ * getUserProfile()
203
+ * getUserContacts()
204
+ * getUserActivity()
205
+ * setUserStatus()
206
+ */
207
+ public function __call( $name, $arguments )
208
+ {
209
+ if ( ! $this->isUserConnected() ){
210
+ throw new Exception( "User not connected to the provider {$this->id}.", 7 );
211
+ }
212
+
213
+ if ( ! method_exists( $this->adapter, $name ) ){
214
+ throw new Exception( "Call to undefined function Hybrid_Providers_{$this->id}::$name()." );
215
+ }
216
+
217
+ $counter = count( $arguments );
218
+ if( $counter == 1 ){
219
+ return $this->adapter->$name( $arguments[0] );
220
+ }
221
+ elseif( $counter == 2 ){
222
+ return $this->adapter->$name( $arguments[0], $arguments[1] );
223
+ }
224
+ else{
225
+ return $this->adapter->$name();
226
+ }
227
+ }
228
+
229
+ // --------------------------------------------------------------------
230
+
231
+ /**
232
+ * If the user is connected, then return the access_token and access_token_secret
233
+ * if the provider api use oauth
234
+ */
235
+ public function getAccessToken()
236
+ {
237
+ if( ! $this->adapter->isUserConnected() ){
238
+ throw new Exception( "User not connected to the provider.", 7 );
239
+ }
240
+
241
+ return
242
+ ARRAY(
243
+ "access_token" => $this->adapter->token( "access_token" ) , // OAuth access token
244
+ "access_token_secret" => $this->adapter->token( "access_token_secret" ), // OAuth access token secret
245
+ "refresh_token" => $this->adapter->token( "refresh_token" ) , // OAuth refresh token
246
+ "expires_in" => $this->adapter->token( "expires_in" ) , // OPTIONAL. The duration in seconds of the access token lifetime
247
+ "expires_at" => $this->adapter->token( "expires_at" ) , // OPTIONAL. Timestamp when the access_token expire. if not provided by the social api, then it should be calculated: expires_at = now + expires_in
248
+ );
249
+ }
250
+
251
+ // --------------------------------------------------------------------
252
+
253
+ /**
254
+ * Naive getter of the current connected IDp API client
255
+ */
256
+ function api()
257
+ {
258
+ if( ! $this->adapter->isUserConnected() ){
259
+ throw new Exception( "User not connected to the provider.", 7 );
260
+ }
261
+
262
+ return $this->adapter->api;
263
+ }
264
+
265
+ // --------------------------------------------------------------------
266
+
267
+ /**
268
+ * redirect the user to hauth_return_to (the callback url)
269
+ */
270
+ function returnToCallbackUrl()
271
+ {
272
+ // get the stored callback url
273
+ $callback_url = Hybrid_Auth::storage()->get( "hauth_session.{$this->id}.hauth_return_to" );
274
+
275
+ // remove some unneeded stored data
276
+ Hybrid_Auth::storage()->delete( "hauth_session.{$this->id}.hauth_return_to" );
277
+ Hybrid_Auth::storage()->delete( "hauth_session.{$this->id}.hauth_endpoint" );
278
+ Hybrid_Auth::storage()->delete( "hauth_session.{$this->id}.id_provider_params" );
279
+
280
+ // back to home
281
+ Hybrid_Auth::redirect( $callback_url );
282
+ }
283
+
284
+ // --------------------------------------------------------------------
285
+
286
+ /**
287
+ * return the provider config by id
288
+ */
289
+ function getConfigById( $id )
290
+ {
291
+ if( isset( Hybrid_Auth::$config["providers"][$id] ) ){
292
+ return Hybrid_Auth::$config["providers"][$id];
293
+ }
294
+
295
+ return NULL;
296
+ }
297
+
298
+ // --------------------------------------------------------------------
299
+
300
+ /**
301
+ * return the provider config by id; insensitive
302
+ */
303
+ function getProviderCiId( $id )
304
+ {
305
+ foreach( Hybrid_Auth::$config["providers"] as $idpid => $params ){
306
+ if( strtolower( $idpid ) == strtolower( $id ) ){
307
+ return $idpid;
308
+ }
309
+ }
310
+
311
+ return NULL;
312
+ }
313
+ }
hybridauth/Hybrid/Provider_Model.php CHANGED
@@ -1,263 +1,245 @@
1
- <?php
2
- /**
3
- * HybridAuth
4
- * http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth
5
- * (c) 2009-2014, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html
6
- */
7
-
8
- /**
9
- * Hybrid_Provider_Model provide a common interface for supported IDps on HybridAuth.
10
- *
11
- * Basically, each provider adapter has to define at least 4 methods:
12
- * Hybrid_Providers_{provider_name}::initialize()
13
- * Hybrid_Providers_{provider_name}::loginBegin()
14
- * Hybrid_Providers_{provider_name}::loginFinish()
15
- * Hybrid_Providers_{provider_name}::getUserProfile()
16
- *
17
- * HybridAuth also come with three others models
18
- * Class Hybrid_Provider_Model_OpenID for providers that uses the OpenID 1 and 2 protocol.
19
- * Class Hybrid_Provider_Model_OAuth1 for providers that uses the OAuth 1 protocol.
20
- * Class Hybrid_Provider_Model_OAuth2 for providers that uses the OAuth 2 protocol.
21
- */
22
- abstract class Hybrid_Provider_Model
23
- {
24
- /**
25
- * IDp ID (or unique name)
26
- * @var Numeric/String
27
- */
28
- public $providerId = NULL;
29
-
30
- /**
31
- * specific provider adapter config
32
- * @var array
33
- */
34
- public $config = NULL;
35
-
36
- /**
37
- * provider extra parameters
38
- * @var array
39
- */
40
- public $params = NULL;
41
-
42
- /**
43
- * Endpoint URL for that provider
44
- * @var String
45
- */
46
- public $endpoint = NULL;
47
-
48
- /**
49
- * Hybrid_User obj, represents the current loggedin user
50
- * @var object
51
- */
52
- public $user = NULL;
53
-
54
- /**
55
- * the provider api client (optional)
56
- * @var String
57
- */
58
- public $api = NULL;
59
-
60
- /**
61
- * Common providers adapter constructor
62
- * @param Numeric/String $providerId
63
- * @param Array $config
64
- * @param Array $params
65
- */
66
- function __construct( $providerId, $config, $params = NULL )
67
- {
68
- # init the IDp adapter parameters, get them from the cache if possible
69
- if( ! $params ){
70
- $this->params = Hybrid_Auth::storage()->get( "hauth_session.$providerId.id_provider_params" );
71
- }
72
- else{
73
- $this->params = $params;
74
- }
75
-
76
- // idp id
77
- $this->providerId = $providerId;
78
-
79
- // set HybridAuth endpoint for this provider
80
- $this->endpoint = Hybrid_Auth::storage()->get( "hauth_session.$providerId.hauth_endpoint" );
81
-
82
- // idp config
83
- $this->config = $config;
84
-
85
- // new user instance
86
- $this->user = new Hybrid_User();
87
- $this->user->providerId = $providerId;
88
-
89
- // initialize the current provider adapter
90
- $this->initialize();
91
-
92
- Hybrid_Logger::debug( "Hybrid_Provider_Model::__construct( $providerId ) initialized. dump current adapter instance: ", serialize( $this ) );
93
- }
94
-
95
- // --------------------------------------------------------------------
96
-
97
- /**
98
- * IDp wrappers initializer
99
- *
100
- * The main job of wrappers initializer is to performs (depend on the IDp api client it self):
101
- * - include some libs needed by this provider,
102
- * - check IDp key and secret,
103
- * - set some needed parameters (stored in $this->params) by this IDp api client
104
- * - create and setup an instance of the IDp api client on $this->api
105
- */
106
- abstract protected function initialize();
107
-
108
- // --------------------------------------------------------------------
109
-
110
- /**
111
- * begin login
112
- */
113
- abstract protected function loginBegin();
114
-
115
- // --------------------------------------------------------------------
116
-
117
- /**
118
- * finish login
119
- */
120
- abstract protected function loginFinish();
121
-
122
- // --------------------------------------------------------------------
123
-
124
- /**
125
- * generic logout, just erase current provider adapter stored data to let Hybrid_Auth all forget about it
126
- */
127
- function logout()
128
- {
129
- Hybrid_Logger::info( "Enter [{$this->providerId}]::logout()" );
130
-
131
- $this->clearTokens();
132
-
133
- return TRUE;
134
- }
135
-
136
- // --------------------------------------------------------------------
137
-
138
- /**
139
- * grab the user profile from the IDp api client
140
- */
141
- function getUserProfile()
142
- {
143
- Hybrid_Logger::error( "HybridAuth do not provide users contacts list for {$this->providerId} yet." );
144
-
145
- throw new Exception( "Provider does not support this feature.", 8 );
146
- }
147
-
148
- // --------------------------------------------------------------------
149
-
150
- /**
151
- * load the current logged in user contacts list from the IDp api client
152
- */
153
- function getUserContacts()
154
- {
155
- Hybrid_Logger::error( "HybridAuth do not provide users contacts list for {$this->providerId} yet." );
156
-
157
- throw new Exception( "Provider does not support this feature.", 8 );
158
- }
159
-
160
- // --------------------------------------------------------------------
161
-
162
- /**
163
- * return the user activity stream
164
- */
165
- function getUserActivity( $stream )
166
- {
167
- Hybrid_Logger::error( "HybridAuth do not provide user's activity stream for {$this->providerId} yet." );
168
-
169
- throw new Exception( "Provider does not support this feature.", 8 );
170
- }
171
-
172
- // --------------------------------------------------------------------
173
-
174
- /**
175
- * set user status
176
- */
177
- function setUserStatus( $status )
178
- {
179
- Hybrid_Logger::error( "HybridAuth do not provide user's activity stream for {$this->providerId} yet." );
180
-
181
- throw new Exception( "Provider does not support this feature.", 8 );
182
- }
183
-
184
-
185
- /**
186
- * return the user status
187
- */
188
- function getUserStatus( $statusid )
189
- {
190
- Hybrid_Logger::error( "HybridAuth do not provide user's status for {$this->providerId} yet." );
191
-
192
- throw new Exception( "Provider does not support this feature.", 8 );
193
- }
194
-
195
- // --------------------------------------------------------------------
196
-
197
- /**
198
- * return true if the user is connected to the current provider
199
- */
200
- public function isUserConnected()
201
- {
202
- return (bool) Hybrid_Auth::storage()->get( "hauth_session.{$this->providerId}.is_logged_in" );
203
- }
204
-
205
- // --------------------------------------------------------------------
206
-
207
- /**
208
- * set user to connected
209
- */
210
- public function setUserConnected()
211
- {
212
- Hybrid_Logger::info( "Enter [{$this->providerId}]::setUserConnected()" );
213
-
214
- Hybrid_Auth::storage()->set( "hauth_session.{$this->providerId}.is_logged_in", 1 );
215
- }
216
-
217
- // --------------------------------------------------------------------
218
-
219
- /**
220
- * set user to unconnected
221
- */
222
- public function setUserUnconnected()
223
- {
224
- Hybrid_Logger::info( "Enter [{$this->providerId}]::setUserUnconnected()" );
225
-
226
- Hybrid_Auth::storage()->set( "hauth_session.{$this->providerId}.is_logged_in", 0 );
227
- }
228
-
229
- // --------------------------------------------------------------------
230
-
231
- /**
232
- * get or set a token
233
- */
234
- public function token( $token, $value = NULL )
235
- {
236
- if( $value === NULL ){
237
- return Hybrid_Auth::storage()->get( "hauth_session.{$this->providerId}.token.$token" );
238
- }
239
- else{
240
- Hybrid_Auth::storage()->set( "hauth_session.{$this->providerId}.token.$token", $value );
241
- }
242
- }
243
-
244
- // --------------------------------------------------------------------
245
-
246
- /**
247
- * delete a stored token
248
- */
249
- public function deleteToken( $token )
250
- {
251
- Hybrid_Auth::storage()->delete( "hauth_session.{$this->providerId}.token.$token" );
252
- }
253
-
254
- // --------------------------------------------------------------------
255
-
256
- /**
257
- * clear all existent tokens for this provider
258
- */
259
- public function clearTokens()
260
- {
261
- Hybrid_Auth::storage()->deleteMatch( "hauth_session.{$this->providerId}." );
262
- }
263
- }
1
+ <?php
2
+ /**
3
+ * HybridAuth
4
+ * http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth
5
+ * (c) 2009-2014, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html
6
+ */
7
+
8
+ /**
9
+ * Hybrid_Provider_Model provide a common interface for supported IDps on HybridAuth.
10
+ *
11
+ * Basically, each provider adapter has to define at least 4 methods:
12
+ * Hybrid_Providers_{provider_name}::initialize()
13
+ * Hybrid_Providers_{provider_name}::loginBegin()
14
+ * Hybrid_Providers_{provider_name}::loginFinish()
15
+ * Hybrid_Providers_{provider_name}::getUserProfile()
16
+ *
17
+ * HybridAuth also come with three others models
18
+ * Class Hybrid_Provider_Model_OpenID for providers that uses the OpenID 1 and 2 protocol.
19
+ * Class Hybrid_Provider_Model_OAuth1 for providers that uses the OAuth 1 protocol.
20
+ * Class Hybrid_Provider_Model_OAuth2 for providers that uses the OAuth 2 protocol.
21
+ */
22
+ abstract class Hybrid_Provider_Model
23
+ {
24
+ /**
25
+ * IDp ID (or unique name)
26
+ * @var Numeric/String
27
+ */
28
+ public $providerId = NULL;
29
+
30
+ /**
31
+ * specific provider adapter config
32
+ * @var array
33
+ */
34
+ public $config = NULL;
35
+
36
+ /**
37
+ * provider extra parameters
38
+ * @var array
39
+ */
40
+ public $params = NULL;
41
+
42
+ /**
43
+ * Endpoint URL for that provider
44
+ * @var String
45
+ */
46
+ public $endpoint = NULL;
47
+
48
+ /**
49
+ * Hybrid_User obj, represents the current loggedin user
50
+ * @var object
51
+ */
52
+ public $user = NULL;
53
+
54
+ /**
55
+ * the provider api client (optional)
56
+ * @var object
57
+ */
58
+ public $api = NULL;
59
+
60
+ /**
61
+ * Common providers adapter constructor
62
+ * @param Numeric/String $providerId
63
+ * @param Array $config
64
+ * @param Array $params
65
+ */
66
+ function __construct( $providerId, $config, $params = NULL )
67
+ {
68
+ # init the IDp adapter parameters, get them from the cache if possible
69
+ if( ! $params ){
70
+ $this->params = Hybrid_Auth::storage()->get( "hauth_session.$providerId.id_provider_params" );
71
+ }
72
+ else{
73
+ $this->params = $params;
74
+ }
75
+
76
+ // idp id
77
+ $this->providerId = $providerId;
78
+
79
+ // set HybridAuth endpoint for this provider
80
+ $this->endpoint = Hybrid_Auth::storage()->get( "hauth_session.$providerId.hauth_endpoint" );
81
+
82
+ // idp config
83
+ $this->config = $config;
84
+
85
+ // new user instance
86
+ $this->user = new Hybrid_User();
87
+ $this->user->providerId = $providerId;
88
+
89
+ // initialize the current provider adapter
90
+ $this->initialize();
91
+ }
92
+
93
+ // --------------------------------------------------------------------
94
+
95
+ /**
96
+ * IDp wrappers initializer
97
+ *
98
+ * The main job of wrappers initializer is to performs (depend on the IDp api client it self):
99
+ * - include some libs needed by this provider,
100
+ * - check IDp key and secret,
101
+ * - set some needed parameters (stored in $this->params) by this IDp api client
102
+ * - create and setup an instance of the IDp api client on $this->api
103
+ */
104
+ abstract protected function initialize();
105
+
106
+ // --------------------------------------------------------------------
107
+
108
+ /**
109
+ * begin login
110
+ */
111
+ abstract protected function loginBegin();
112
+
113
+ // --------------------------------------------------------------------
114
+
115
+ /**
116
+ * finish login
117
+ */
118
+ abstract protected function loginFinish();
119
+
120
+ // --------------------------------------------------------------------
121
+
122
+ /**
123
+ * generic logout, just erase current provider adapter stored data to let Hybrid_Auth all forget about it
124
+ */
125
+ function logout()
126
+ {
127
+ $this->clearTokens();
128
+
129
+ return TRUE;
130