Auth Server API
, (*1)
Auth Server API is a PHP HTTP client for Auth Server that makes it easy to send HTTP requests and
trivial to integrate with web services., (*2)
- Manages things like persistent connections, simplifies sending streaming POST requests with fields ,and abstracts away the underlying HTTP transport layer.
- Set the cookie on your server by the token issued by the Auth Server
- Easy login and logout function
- Auth Server API makes it so that you no longer need to fool around with cURL options,
stream contexts, or sockets for connecting with Auth Server.
Usage
$auth = new Auth\ApiClient(array(
'KEY' => AUTH_KEY, // YOUR AUTH KEY
'SECRET' => AUTH_SECRET, // YOUR AUTH SECRET
'LOGIN_URI' => '/login.php', // YOUR APP LOGIN URL
));
For Check Login Status
- If the user is logged in, it returns the user information array.
- If it is not logged in, it redirects to the auth server login page
$token = isset($_SESSION[āauth_server_tokenā])?$_SESSION[āauth_server_tokenā]:NULL ; // If you save token in session than you can receive it like this .
if($user = $auth -> isloggedIn($token)){
echo āwelcomeā.$user[āfirst_nameā].āā.$user[ālast_nameā];
}
For Login
$response = $auth -> dologin();
$token = $auth -> getToken();
$_SESSION[āauth_server_tokenā] = $token;
header(ālocation:ā , $auth ->getcallbackUri()); // After Saving token redirect to the callback_url()
session_write_close();
.
For Logout
unset($_SESSION['auth_server_token']);
$auth->doLogout();
Installing via Composer
The recommended way to install Auth Server API is through
Composer., (*3)
# Install Composer
curl -sS https://getcomposer.org/installer | php
Next, run the Composer command to install the latest stable version of Auth Server API:, (*4)
composer require spandansingh/auth-server-api:dev-master
After installing, you need to require Composer's autoloader:, (*5)
require 'vendor/autoload.php';
Sample app
Check out Auth Server Demo App for a quick sample app., (*6)
Consultation
- Spandan Singh
- Looking for PHP web development solutions or consultation? Drop me a mail.