-<?php\r\r
-\r\r
- $hybridauth_config = /* dirname(__FILE__) . */ '../hybridauth/config.php';\r\r
- require_once( "../hybridauth/Hybrid/Auth.php" );\r\r
-\r\r
- try{\r\r
- \r\r
- // create an instance for Hybridauth with the configuration file path as parameter\r\r
- $hybridauth = new Hybrid_Auth( $hybridauth_config );\r\r
-\r\r
- // try to authenticate the selected $provider\r\r
- $adapter = $hybridauth->authenticate( $username );\r\r
-\r\r
- // grab the user profile\r\r
- $user_profile = $adapter->getUserProfile();\r\r
- \r\r
- // a) Does user with "xxx" = identifier exist?\r\r
- // -> Yes, then login as user \r\r
-\r\r
- // b) Does email of user exist?\r\r
- // -> No, then create new user\r\r
-\r\r
- // c) Does email of user exist?\r\r
- // -> Yes, ask for regular login. Preset email = login\r\r
- \r\r
- $provider_uid = $user_profile->identifier;\r\r
- $email = $user_profile->email;\r\r
- $first_name = $user_profile->firstName;\r\r
- $last_name = $user_profile->lastName;\r\r
- $display_name = $user_profile->displayName;\r\r
- $website_url = $user_profile->webSiteURL;\r\r
- $profile_url = $user_profile->profileURL;\r\r
- $password = rand( ) ; # for the password we generate something random\r\r
- \r\r
- echo $provider_uid."<br>";\r\r
- echo $email;\r\r
- }\r\r
- catch( Exception $e ){\r\r
- // Display the recived error\r\r
- switch( $e->getCode() ){ \r\r
- case 0 : $error = "Unspecified error."; break;\r\r
- case 1 : $error = "Hybriauth configuration error."; break;\r\r
- case 2 : $error = "Provider not properly configured."; break;\r\r
- case 3 : $error = "Unknown or disabled provider."; break;\r\r
- case 4 : $error = "Missing provider application credentials."; break;\r\r
- case 5 : $error = "Authentification failed. The user has canceled the authentication or the provider refused the connection."; break;\r\r
- case 6 : $error = "User profile request failed. Most likely the user is not connected to the provider and he should to authenticate again."; \r\r
- $adapter->logout(); \r\r
- break;\r\r
- case 7 : $error = "User not connected to the provider."; \r\r
- $adapter->logout(); \r\r
- break;\r\r
- } \r\r
- } \r\r
+<?php
+\r
+
+\r
+ $hybridauth_config = /* dirname(__FILE__) . */ '../hybridauth/config.php';
+\r
+ require_once( "../hybridauth/Hybrid/Auth.php" );
+\r
+
+\r
+ try{
+\r
+
+\r
+ // create an instance for Hybridauth with the configuration file path as parameter
+\r
+ $hybridauth = new Hybrid_Auth( $hybridauth_config );
+\r
+
+\r
+ // try to authenticate the selected $provider
+\r
+ $adapter = $hybridauth->authenticate( $username );
+\r
+
+\r
+ // grab the user profile
+\r
+ $user_profile = $adapter->getUserProfile();
+\r
+
+\r
+ // a) Does user with "xxx" = identifier exist?
+\r
+ // -> Yes, then login as user
+\r
+
+\r
+ // b) Does email of user exist?
+\r
+ // -> No, then create new user
+\r
+
+\r
+ // c) Does email of user exist?
+\r
+ // -> Yes, ask for regular login. Preset email = login
+\r
+
+\r
+ $provider_uid = $user_profile->identifier;
+\r
+ $email = $user_profile->email;
+\r
+ $first_name = $user_profile->firstName;
+\r
+ $last_name = $user_profile->lastName;
+\r
+ $display_name = $user_profile->displayName;
+\r
+ $website_url = $user_profile->webSiteURL;
+\r
+ $profile_url = $user_profile->profileURL;
+\r
+ $password = rand( ) ; # for the password we generate something random
+\r
+
+\r
+ echo $provider_uid."<br>";
+\r
+ echo $email;
+\r
+ }
+\r
+ catch( Exception $e ){
+\r
+ // Display the recived error
+\r
+ switch( $e->getCode() ){
+\r
+ case 0 : $error = "Unspecified error."; break;
+\r
+ case 1 : $error = "Hybriauth configuration error."; break;
+\r
+ case 2 : $error = "Provider not properly configured."; break;
+\r
+ case 3 : $error = "Unknown or disabled provider."; break;
+\r
+ case 4 : $error = "Missing provider application credentials."; break;
+\r
+ case 5 : $error = "Authentification failed. The user has canceled the authentication or the provider refused the connection."; break;
+\r
+ case 6 : $error = "User profile request failed. Most likely the user is not connected to the provider and he should to authenticate again.";
+\r
+ $adapter->logout();
+\r
+ break;
+\r
+ case 7 : $error = "User not connected to the provider.";
+\r
+ $adapter->logout();
+\r
+ break;
+\r
+ }
+\r
+ }
+\r
?>
\ No newline at end of file