PHP code example of appkita / phpauth

1. Go to this page and download the library: Download appkita/phpauth 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/ */

    

appkita / phpauth example snippets


    use Appkita\PHPAuth;
    $config = [
        'session' => [
            'session_key'=>'isLogin'
        ]
    ];
    $auth = new Authentication($config);
    $cek = $auth->auth(METHOD::SESSION, function($auth) {
        return ($auth ? true : false);
    });
    

  $configApi = [
      'google' = [
      'clientID' => 'your client id',
      'clientSecret' => 'secret client',
      'redirectUri' => 'redirect url',
    ];
     'facebook' = [
      'clientID' => 'your client id',
      'clientSecret' => 'secret client',
      'redirectUri' => 'redirect url',
    ];
  ]

  //identifikasi Facebook Library
  $FB = new \Appkita\PHPAuth\Type\Facebooklogin($configApi);
  //identifikas google library
  $GOOGLE = new \Appkita\PHPAuth\Type\GoogleLogin($this->configApi);

  //get FB login url
  function loginFB() {
      header('location:'. $FB->urlLogin());
  }

  //get Google Login url
  function loginGoogle() {
      header('location:'. $GOOGLE->urlLogin());
  }

  //url callback fb login to verify token
  function verify_fb() {
      return $FB->decode(function($user, $args, $error) {
            die(json_encode($user));
        });
  }
  //url callback fb Google to verify token
  function verify_fb() {
      return $FB->decode(function($user, $args, $error) {
            die(json_encode($user));
        }, []);
  }
  

  $config = [
    'key_header'=>'X-API-KEY', //Delete if you not use API KEY
    //jwt Configuration
    'key'=>'key_JWT',
    'data'=>'username',
    'timeout'=>3600,
    'iss'=>'mydomain.com',
    'aud'=>'mydomain.com',
    'basic_auth'=>[
        'username_key'=>'email',
        'password_key'=>'password'
    ];
  ];
  $auth = new Appkita\PHPAuth\Authentication($config);
  //or
  use Appkita\PHPAuth;
  $auth = new Authentication($config);
  //or configuration default
  $auth = new Authentication();

    $cek = $auth->auth(METHOD, callback);

return ['username'=>username, 'password'=>password];

    $mykey = 'testingkey';
    $cek = $auth->auth(METHOD::KEY, function($key) {
        if ($key === $mykey) {
            return true;
        } else {
            return false;
        }
    });

    $myusername = 'testingkey';
    $mypassword = 'password';
    $cek = $auth->auth(METHOD::BASIC, function($username, $password) {
        if ($username == $myusername && $mypassword == $password) {
            return true;
        } else {
            return false;
        }
    });

    $myusername = 'testingkey';
    $mypassword = 'password';
    $cek = $auth->auth(METHOD::DIGEST, function($username, $password) {
        if ($username == $myusername) {
            return ['username'=>$myusername, 'password'=>$mypassword];
        } else {
            return false;
        }
    });

    $myusername = 'testingkey';
    $cek = $auth->auth(METHOD::TOKEN, function($username) {
        if ($username == $myusername) {
            return true
        } else {
            return false;
        }
    });
sh
cd PHP_AUTHENTICATION
composer install