PHP code example of betterbrief / silverstripe-opauth

1. Go to this page and download the library: Download betterbrief/silverstripe-opauth library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

betterbrief / silverstripe-opauth example snippets


//Register and configure strategies
Config::inst()->update('OpauthAuthenticator', 'opauth_settings', array(
  'Strategy' => array(
    'Facebook' => array(
      'app_id' => '',
      'app_secret' => '',
      'scope' => 'email',
    ),
    'Google' => array(
      'client_id' => '',
      'client_secret' => ''
    ),
    'Twitter' => array(
      'key' => '',
      'secret' => ''
    ),
  ),
));

//Identity to member mapping settings per strategy
Config::inst()->update('OpauthIdentity', 'member_mapper', array(
  'Facebook' => array(
    'FirstName' => 'info.first_name',
    'Surname' => 'info.last_name',
    'Locale' => 'raw.locale',
    'Email' => 'info.email',
  ),
  'Twitter' => array(
    'FirstName' => array('OpauthResponseHelper', 'get_first_name'),
    'Surname' => array('OpauthResponseHelper', 'get_last_name'),
    'Locale' => array('OpauthResponseHelper', 'get_twitter_locale'),
  ),
  'Google' => array(
    'FirstName' => 'info.first_name',
    'Surname' => 'info.last_name',
    'Email' => 'info.email',
    'Locale' => array('OpauthResponseHelper', 'get_google_locale'),
  ),
));