API Example User Authentication

From InClickAdServer

User Authentication

This API Service Request will authenticate the username and password pair for login.

In the factory User Interface (UI), the corresponding action is when someone logs into their account. On success, this service request will provide the User ID (Account Number), the User Name, the users first and last name, and the account type.

The Code Example

Breaking Down the Code

This require references the local inClick Ad Server deployment configuration files allowing your code to utilize the pre-packaged API Objects as well as the bundled PHPOlait services.

This will include the files that contain the API Objects and Classes needed for this API Service Request.

The $base_url is the URL to your inClick Ad Server deployment, the ad server root URL. For local host API usage, the constant of INCLICK_WEB_URL is defined in the globals.php file referenced earlier. Remote deployments, deployments where the ad server and API Request Location are not on the same server, would change this to the fully qualified URL to the ad server root directory.

The $service_key is one of the the api_service_keys values you created for your ad server. (more information)

This is where we create an instance of the classes needed to perform a User Authentication request.

This line processes the API Service Request using the User Name ($username) and Password ($password) provided.

These two lines set the status objects:

Object Description Response Content
$validation_result->getValidated()Indicates if the the username and password pass or failnull=failed
$user_account->getUserID()The account number of the authenticated userinteger
$user_account->getUsername()The registered user name of the userText
$user_account->getFirstname()The registered first name of the userText
$user_account->getLastname()The registered last name of the userText
$user_account->getUserTypeCode()The account type of the authenticated useradv
$validation_result->getMessage()Available on failures only, a verbose reason for the failed loginText
$validation_result->getCode()The reason code for the failureauthentication_failed

This section of code is provided to give you a visual confirmation of what occurred, or to let you know what error occurred.