Forced Login

There may be times when you want to allow for external authentication through social media. Community Auth won’t do this by itself, but once you’ve authenticated your user through the external service, you can force Community Auth to login that user. All you’re really doing when you do this is setting up the session and cookies that Community Auth would normally set when a user logs in.

// Email address retrieved from external authentication
$email_address = '';

if( ! empty( $email_address ) )
  $auth_model = $this->authentication->auth_model;  
  // Get normal authentication data using email address
  if( $auth_data = $this->{$auth_model}->get_auth_data( $email_address ) )
     * If redirect param exists, user redirected there.
     * This is entirely optional, and can be removed if 
     * no redirect is desired.
    // Set auth related session / cookies
    $this->authentication->maintain_state( $auth_data );
  echo 'Example requires that you set an email address.';

Be aware that when you log a user in this way, you are totally bypassing Community Auth’s regular checks.

Login Immediately After User Registration

Another good reason to force somebody to be logged in might be that they are registering for a user account on your website, and you don’t want them to have to login separately. Forced login with Community Auth makes this a very simply task.