My project for Drupal during Google Summer of Code is to create a module which provides authentication support using Hawk for Drupal 8. Hawk is a protocol similar to OAuth, either of which can be used as an altenrative to the basic cookie-based authentication already available in Drupal. One of the most major advantages of Hawk over OAuth is the ability to straight away make a request without requiring a handshake, reducing the amount of complexity required for making an API request.
The original implementation of the Hawk protocol is in Node.js with no official library for PHP, hence the first step for creating this module would be to create a library which implements the Hawk protocol in PHP.
I have two ways of doing this:
- Create a new port from scratch
- Base my work on one of the existing php ports
For (2) I had to evaluate existing libraries and determine a good option to base my work on, otherwise I'd need to revert to (1) and start from scratch. I narrowed it down to 2 libraries detailed below:
It’s a slightly more up-to-date version of alexbilbie/PHP-Hawk, the library is a very simplified implementation of Hawk protocol and doesn’t support many of the features specified in the original protocol.
- Simplified one-file implementation, easy to get started with
- Doesn’t support features beyond basic hawk authentication (such as bewit, payload validation etc)
- Doesn’t have unit tests
Due to the above cons the library was not viable to be used as a base for mine, as implementing the features and unit tests would be more work than starting from scratch and the features will be essential for D8’s module.
This is the other implementation of Hawk written in PHP.
- Implementation is a lot closer to the original node.js implementation
- Supports most of the features specified by the original implementation/protocol
- Has some unit tests
- Test coverage is not complete
- Code doesn’t have any phpDoc comments
- Misses a few minor features
Since the pros outweigh the cons in this library’s case, I will be using it as a base and improve it further instead of starting from scratch. My next update would be detailing my progress and efforts with the library, if someone would like to see my work-in-progress library they can do so at its GitHub repository.