Github/facebook & php

Could I please see an example Auth0-facebook PHP login?

After carefully reviewing the facebook-php oauth2 code and thePhpLeague facebook interface, both of them are specifying the default_graph_version value, so i tried to include it like so:

$auth0 = new Auth0([
‘default_graph_version’ => ‘v3.2’,

But unfortunately this did not work.

Hey there!

As I’ve said in another post you started, the PHPLeague Facebook interface you reference is not developed by Auth0 thus we are not able to provide you with any help on that however we do have our own resources on PHP and connecting it with Facebook:

ok thank you - i got a LOT farther along that time! :smile:

what was particularly confusing is that in order to include FaceBook in an app that already successfully uses Google, i had to add one line to the simple code provided to me from the app “quick-start” PHP example:

‘scope’ => ‘openid email name nickname picture’, /* add this line* /

this was very confusing, since i just assumed the very simple PHP example provided to me would work with any social media, not just Google.

suggstion: include this line in the PHP example which is displayed when the app is created.

however, this did cause one more very minor issue which i am asking about here.

Thank you I will pass that feedback to our Docs team!

hi Konrad -

As a newbie, this really was very confusing and time-consuming. the example “quick-code” generated in “Configure Auth0 PHP SDK” does not include the scope.

here are the results i am seeing:

AUTH0: with scope:

Hello !array(3) { [“sub”]=> string(30) “auth0|5d9ca5804c5a1c0e1ea2b0fa” [“email”]=> string(20) “mark@domain.com” [“email_verified”]=> bool(true) }

AUTH0: without scope:

Hello mark@domain.com!array(7) { [“sub”]=> string(30) “auth0|5d9ca5804c5a1c0e1ea2b0fa” [“nickname”]=> string(4) “mark” [“name”]=> string(20) “mark@domain.com” [“picture”]=> string(122) “https://s.gravatar.com/avatar/15e7770737e26d7094f3c77d76b2dbe0?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2Fma.png” [“updated_at”]=> string(24) “2019-10-29T15:34:01.287Z” [“email”]=> string(20) “mark@domain.com” [“email_verified”]=> bool(true) }

FACEBOOK: with scope:

Hello !array(3) { [“sub”]=> string(24) “facebook|568242963910810” [“email”]=> string(32) “mark@gmail.com” [“email_verified”]=> bool(true) }

FACEBOOK: without scope:

ERROR! This page isnt working dev-y-wc5m4m.auth0.com redirected you too many times.

GOOGLE: with scope:

Hello !array(3) { [“sub”]=> string(35) “google-oauth2|114113878629589347134” [“email”]=> string(20) “mark@domain.com” [“email_verified”]=> bool(true) }

GOOGLE: without scope:

Hello Mark Edwards!array(11) { [“sub”]=> string(35) “google-oauth2|114113878629589347134” [“given_name”]=> string(4) “Mark” [“family_name”]=> string(7) “Edwards” [“nickname”]=> string(4) “mark” [“name”]=> string(12) “Mark Edwards” [“picture”]=> string(83) “https://lh3.googleusercontent.com/a-/AAuE7mAK2vXecQCbEYKvoz5q7J8LP8YUAkswlsY36P5kYg” [“gender”]=> string(5) “other” [“locale”]=> string(2) “en” [“updated_at”]=> string(24) “2019-10-29T15:28:01.605Z” [“email”]=> string(20) “mark@domain.com” [“email_verified”]=> bool(true) }

GITHUB with scope:

Hello !array(2) { [“sub”]=> string(14) “github|2924002” [“email”]=> string(22) “mark@domain.com” }

GITHUB without scope:

ERROR! This page isnt working dev-y-wc5m4m.auth0.com redirected you too many times.

MSN with scope:

Hello !array(3) { [“sub”]=> string(28) “windowslive|a2cd40fdb7dbcb5b” [“email”]=> string(26) “makr@domain.com” [“email_verified”]=> bool(true) }

MSN without scope:

This page isnt working dev-y-wc5m4m.auth0.com redirected you too many times.

here is the code i am using (below). i am still wondering why including the scope fixes all the problems but i cannot extract name, picture, etc ??

$auth0 = new Auth0([
  'domain' => 'dev-y-wc5m4m.auth0.com',
  'client_id' => 'LXXXXXXXXXXXXX3',
  'client_secret' => '2XXXXXXXXXXXXXXXXXm',
  'redirect_uri' => 'https://DOMAIN.com/auth0/index.php',
//'scope' => 'openid email name nickname picture',  //needs to be included for facebook, github, and msn
       
  'persist_id_token' => true,
  'persist_access_token' => true,
  'persist_refresh_token' => true,
]);

error_log('index.php:  NOW trying to get userInfo.');

$userInfo = $auth0->getUser();

error_log('index.php:  $userInfo: ' . print_r($userInfo,1));

if (!$userInfo) {
error_log('logging in:');
                                                //echo '<a href="login.php">Log In</a>';
        $auth0->login();
    // We have no user info
    // See below for how to add a login link
} else {
        error_log('We have userInfo ');
        printf( "Hello %s!", htmlspecialchars( $userInfo['name'] ) );
var_dump($userInfo);
    // User is authenticated
    // See below for how to display user information
}

i know many people who would not have stuck with this and identified the issue! could you please find out for me why why the scope is not returning picture and name?? :slight_smile:

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.