Download the PHP package almefy/client without Composer
On this page you can find all versions of the php package almefy/client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download almefy/client
More information about almefy/client
Files in almefy/client
Package client
Short Description PHP Wrapper for the Almefy API
License Apache-2.0
Homepage https://almefy.com
Informations about the package client
Almefy PHP Client
A simple dependency-free PHP wrapper for the Almefy API.
Quick Guide
Below is a quick guide how to integrate Almefy in your PHP project to test it easily. We are already preparing a comprehensive documentation covering all possible use cases and parameters. So stay tuned.
Please notice: this document is work in progress.
Prerequisites
To successfully initialize the PHP client, you'll need an API key and API secret from Almefy.
Installation
Almefy PHP Client is available on Packagist as the almefy/client
package. Run composer require almefy/client
from the root of your project in terminal, and you are done. If you
cannot use composer
for any reasons you can download the latest version
from GitHub. The minimum PHP version currently supported is 8.0.
Client Initialization
Once you have the package installed, you will need to instantiate a Client object. This example assumes that you store the secrets in some environment variables:
Identity Enrollment
Before a user account can be used with the Almefy app, it needs to be enrolled and the device provisioned. The easiest way to enroll an account with Almefy is to send the user an email with an enrollment QR Code inside. A good starting point could be a "Connect with Almefy" button somewhere inside the protected area, which triggers the following process in the backend:
The returned $enrollmentToken
object provides a public base64ImageData
property with the base64 encoded image data
that can be used in any HTML email.
If enabled, you can also use the Almefy API to send a generic enrollment email without the effort to build a custom email-client compatible template:
Notice: Check out the API Enrollment Reference for all available options.
This process creates or uses an existing identity and sends out an enrollment email with a QR Code inside, that needs to be scanned with the Almefy app to provision it. Once done, the enrollment is completed, and the user is ready to authenticate using the Almefy app.
Frontend
Add the following few lines to your HTML frontend to show the Almefy image used for authentication.
Authentication
The authentication controller configured in the data-alemfy-auth-url
will receive the X-Almefy-Authorization
header
from the Almefy API. The first thing needs to be done inside the controller is extracting the token from the header and
decode it (it is also verified).
Notice: The JWT is provided using the X-Almefy-Authorization
header for compatibility reasons (e.g. Apache webserver
not forwarding it to the PHP process), but also using the standard Authorization: Bearer ...
header.
Next you should check if the user trying to authenticate is in your own identity management system and allowed to authenticate. This is your own business logic, thus just as an example:
The last and important step is to verify and confirm the authentication attempt on the Almefy system:
Notice: For security reasons any network or server error will always return false.
At this stage you can authenticate the user by setting up session etc. and redirect him to the protected area.
License
The Almefy PHP SDK is licensed under the Apache License, version 2.0.
All versions of client with dependencies
ext-json Version *
ext-curl Version *
ext-mbstring Version *