Last week I had worked on my library implementing the Hawk protocol in PHP, the library itself is one independent of Drupal and can be used with any platform. Its main job is to create request on the behalf of clients and authenticate the requests on behalf of the servers. Hence, it'll be one of the most crucial parts of the module.
In my previous week's entry I had said that I'll be continuing with implementing the Oz protocol, however my mentor (skyred) suggested it would be better to make the authentication module based on Hawk first then continue with Oz as it's less crucial to the project. Hence, I repurposed this week to start working on the Drupal's module on top of my library. This would be my first Drupal module which adds to the challenge and fun, for the moment I'm only focussing on Drupal 8. The module's sandbox environment and work-in-progress code can be seen here: https://www.drupal.org/sandbox/dragooon/2499839
Before I began, I wanted to be familiar with a few concepts quite important to Drupal. Creating Drupal 8.x modules is an excellent resource to get started with creating D8 modules. Here is a short summary of the problems I tackled this week:
Composer is a dependency manager for PHP, you can specify a set of dependencies your project has and while developing and deploying composer will load them into the project. This allows the code in repository to be only of the project itself, as well as makes updating dependencies and libraries a trivial task.
While I'm familair with composer, I wanted to use it with my Drupal module. I found a few articles specifying how to manage entire Drupal based projects using composer but I couldn't find any on how to use composer within a single Drupal module. The main challenge was I couldn't specify Drupal as a dependency without having the module download whole Drupal package again. For now I have left that challenge for another day and just specified the base requirement of php-hawk library within the module's composer.json.
Dependency Injection is a design pattern where a library's dependencies are passed through a "framework" or "container" instead of the library loading them directly. This allows the dependencies to be loosely coupled and replaced on the fly with other libraries without modifying the class itself. Here's an article by Steve Rodrigue explaining dependency injection in PHP with a simple example.
Drupal implements Dependency Injection using Symfony's DependencyInjection component, for starters I've implemented a basic class layout in my hawk.services.yml after learning about DependencyInjection component and DI in general during the course of this week.
After the above two major considerations, I had to start with the module itself. For now I've only implemented hawk.install, a PHP script which hooks into hook_requirements and hook_schema. The former checks whether the module can be installed or not and the latter defines the database schema for installing the module. Currently I only see the requirement of one table storing the Hawk credential's users, although this may expand in future as I implement more features.
My week is cut short as I'll be leaving from 13th until 20th, hence the earlier than usual post. I'll be continuing once I'm back onto implementing the authentication providers and rest of the module, more on those in my next few entries.