Php prefill an email address

hello -

is there any way to prefill an email address using PHP that uses one of the social connections, such as Google, Facebook, etc?

this does not appear to be working: (found it here)

'options'=>[ 'prefill'=>['email'=>'mark@gmail.com', 'username'=>'mark@gmail.com' ]]

Hi @edwardsmarkff,

To clarify about the social connections, are you trying to prefill in the social providers login page?

For example:

Let me know,
Dan

hi dan – YES! that is exactly it!

It looks like this should be possible by passing a login_hint param to google, it requires some specific setup in the connection. The topic is covered here:

Let me know if it works!

sorry, my PHP is not working quite yet. here is what i am passing now:

$auth0 = new Auth0(     [       'domain'                => constant('Auth0_domain')
                        ,       'client_id'             => constant('Auth0_client_id')
                        ,       'client_secret'         => constant('Auth0_client_secret')
                        ,       'redirect_uri'          => constant('redirectUrl')
                        ,       'scope'                 => 'openid profile email name nickname picture'
                        ,       'login_hint'            => 'john@gmail.com'
                        ,       'options'               =>      [       'login_hint'            => 'john@gmail.com'
                                                                ]
                        ]
                );

note that i temporarily have the login_hint used twice for developments/experimentation only.

everything works fine for my PHP script, but the “login_hint” does not appear to be accepted by google, or should i say i am not seeing the value filled in for me.

do you have any suggestions?

also, is there any way to have some sort of “universal” prefill, that might also work with facebook, msn, etc?

Did you configure the upstream params in you connection? Like mentioned in the doc I linked?

here is what i tried:

 $auth0 = new Auth0(     [       'domain'                => constant('Auth0_domain')
                         ,       'client_id'             => constant('Auth0_client_id')
                         ,       'client_secret'         => constant('Auth0_client_secret')
                         ,       'redirect_uri'          => constant('redirectUrl')      .       '?one=twooo'
                         ,       'scope'                 => 'openid profile email name nickname picture'
                         ,       'upstream_params'       => [
                                    'options' => [ 'login_hint'  => 'mark@gmail.com' ]
                                                                 
                                  ]
                         ]
                 );

with no success.

is there any possibility i could pay somebody to put a PHP example together for me? and if so, i believe it would make a good addition to the website documentation.

i would rather see an actual PHP example instead of trying to interpret cURL or postman.

I think the misunderstanding here is that you need to do some config in your connection settings, not just add the login hint in the authorize request. I just tested it and it works.

Lets walk through it:

  • Go to the dashboard, navigate to APIsAuth0 Management APIAPI Explorer and copy the token
  • Go to the management API explorer and click the Set API Token button in the top left of the window. Paste the token you got from the dashboard here.
  • Next, scroll down to Get All Connections and click the Try button
    Screen Shot 2020-04-24 at 10.41.20 AM
  • You should get a successful response with a ton of JSON, if not, let me know and we can debug.
  • Parse through the JSON and find the connection with the name google-oauth2
  • In a notepad/temporary doc, copy the entire options array and the id. It should look like this:
id:con_123456asdfg

"options": {
      "email": true,
      "gmail": false,
      "orkut": false,
      "scope": [
        "email",
        "profile"
      ],
      "sites": false,
      "tasks": false,
      "blogger": false,
      "profile": true,
      "youtube": false,
      "calendar": false,
      "contacts": false,
      "analytics": false,
      "client_id": "",
      "moderator": false,
      "coordinate": false,
      "picasa_web": false,
      "google_plus": false,
      "google_books": false,
      "google_drive": false,
      "spreadsheets": false,
      "client_secret": "",
      "document_list": false,
      "latitude_best": false,
      "latitude_city": false,
      "url_shortener": false,
      "webmaster_tools": false,
      "chrome_web_store": false,
      "allowed_audiences": "",
      "adsense_management": false,
      "google_drive_files": false,
      "coordinate_readonly": false,
      "google_cloud_storage": false,
      "content_api_for_shopping": false,
      "google_affiliate_network": false
    }
  • In your temporary doc add this to the options array.
"upstream_params": {"login_hint": {"alias": "login_hint"}},
  • Put curly brackets around the whole options object:
  • It should look something like this:
{"options": {
      "upstream_params": {"login_hint": {"alias": "login_hint"}},
      "email": true,
      "gmail": false,
      "orkut": false,
      "scope": [
        "email",
        "profile"
      ],
      "sites": false,
      "tasks": false,
      "blogger": false,
      "profile": true,
      "youtube": false,
      "calendar": false,
      "contacts": false,
      "analytics": false,
      "client_id": "",
      "moderator": false,
      "coordinate": false,
      "picasa_web": false,
      "google_plus": false,
      "google_books": false,
      "google_drive": false,
      "spreadsheets": false,
      "client_secret": "",
      "document_list": false,
      "latitude_best": false,
      "latitude_city": false,
      "url_shortener": false,
      "webmaster_tools": false,
      "chrome_web_store": false,
      "allowed_audiences": "",
      "adsense_management": false,
      "google_drive_files": false,
      "coordinate_readonly": false,
      "google_cloud_storage": false,
      "content_api_for_shopping": false,
      "google_affiliate_network": false
    }}
  • Click out of the overlay with the JSON, and go to Update a Connection :
    Screen Shot 2020-04-24 at 10.49.33 AM
  • Input your ID and the options object your just edited.You must add the whole options object, as it overrides your options when you do this. Like this:
  • You should get a successful response with the new options object for your connection. If you get an error or something let me know and we can work through it.

Hope this helps!
Dan

hey dan -

this link seemed to indicate there may be a better way to pre-populate the google login other than using login_hint:

Our best practice recommendations from Auth0 have been changed to discontinue using login_hint as a way to pass this data, and instead recommend doing a namespaced parameter.
e.g.  `mycompany_showsignup=1`  or  `mycompany_initialscreen=signup`
This will help avoid any conflicts with the appropriate use of those parameters.

but that being said, i have run out of time (and patience) to get this working so i have hired somebody to finish this for me (yes Dan, i am cheating…!)

i was able to implement your “upstream_params” but was still unable to see any meaningful results.

assuming my contractor gets this working, i will be posting all the steps he went through, with a special asterisk notation to the steps i probably carelessly glossed over.:grin:

thanks.

1 Like

Thanks for posting that guidance!

For anyone implementing this, it seems that Carlos is directing us to avoid login_hint as the alias param as it can cause a conflict with an existing UL param called login_hint.

Well we appreciate your patience up to this point, sorry this wasn’t easier. This was a new one for me and certainly took some inside knowledge to figure out. Hopefully your contractor can get it working. Feel free to send them my way if they need any help.

Thanks again!

assuming we can get this working, maybe auth0 should consider having a special “recipe” section? i should think other PHP people might be interested in this.

i successfull prefill the email address to pass the parameter to auth0 php … but it prefill with meaningfull email address … see this stackoverflow Use login_hint to pre-fill email box for Google oAuth2 - Stack Overflow

1 Like

@ashu4code,

Could you expand on your question?

I can write up an FAQ for this, but that is kind of the purpose of these threads. We hope that future users with this question will find this thread and solution.

How i use login_hint for facebook. facebook doesn’t support login_hint
Facebook supports display (‘page’, ‘popup’, or ‘touch’), auth_type, auth_nonce.
Google supports access_type, approval_prompt, prompt, login_hint, user_id, hd.
Twitter supports force_login, screen_name.
Linkedin supports fields

I don’t see a login_hint type param from facebook:

It may not be possible.

here is the working example below. once again, this is pretty simple, but auth0 really should have a PHP cookbook recipe section for stuff like this.

<?php

// written by ashu4code

require 'vendor/autoload.php';
use Auth0\SDK\Auth0;

define('defaultEmail'           ,       'mark@gmail.com'  );

define('redirectUrl'         ,       ( $_SERVER['HTTPS'] ? 'https' : 'http' )
                                        .       '://'
                                        .       $_SERVER['HTTP_HOST']
                                        .       $_SERVER['SCRIPT_NAME']
                                );

$auth0 = new Auth0([
  'domain' => 'dev-2XXXXX8.auth0.com',
  'client_id' => 'kZvgXXXXXXTC',
  'client_secret' => '4pXXXXXW0',
  'redirect_uri' => constant('redirectUrl'),
  'scope' => 'openid profile email',
]);


$userInfo = null;
try {
        $userInfo = $auth0->getUser();
} catch (Exception $e) {
        $auth0->logout();
        error_log( 'Line: ' . __LINE__ . ' -- Caught Auth0 exception: ' .  $e->getMessage() . ' -- exiting program.' . "\n" );
        header('Location: ?logout=1' ) ;
        exit;
}

if (!$userInfo) {
    // We have no user info
    // pass login_hint in additonalParams array
             
        $additionalParams= array('login_hint' => constant('defaultEmail')       );
        $auth0->login(null, null, $additionalParams);
        exit;
} else {
        $userInfo = $auth0->getUser();
        printf( 'Hello %s!', htmlspecialchars( $userInfo['name'] ));;
        phpinfo();
    // User is authenticated
    // See below for how to display user information
}
1 Like

Thanks for sharing @edwardsmarkff !

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