Smart-IT-Kirkham / OpusVL-FB11

Business and Social Application Framework
http://flexibase.io
Other
1 stars 2 forks source link

Put auth in the Hive #38

Open Altreus opened 5 years ago

Altreus commented 5 years ago

Note: I don't like the names of these services. I want login to be auth, but I can't think of a better name for auth.

This is gonna be a fun one. I had a good talk with Nick and we figured out a potentially decent way of getting auth into the Hive.

The way we do it is we separate auth into two services: auth itself, and login.

This is somewhat inspired by the way Catalyst::Plugin::Authentication already does it, which is to provide an interface set_authenticated, which simply tells the auth plugin that the user is authenticated.

Auth service handles session-type storage

The auth service would provide a very simple interface:

How the service stores this information is largely irrelevant. The only necessary interface is that the "log in" function returns a token, and the other functions accept it (or something like that).

Login service performs authentication

The login service provides the other half of the behaviour. This would be the first instance of a truly swappable Hive service. This would provide all the behaviour necessary to authenticate user information against arbitrary input data.

Here's how it would, very broadly, work:

my $h = OpusVL::FB11::Hive;
$h->service('auth')->set_logged_in(
  $h->service('login')->authenticate( $auth_info )
);

Clearly missing from this code is the source of $auth_info, and this is the bit we have to fill in. The idea here is that this would be provided by various interfaces into the same system.

Login service can signal what data it needs

The way we collect $auth_info would be another module (or set of modules) that support the login Brain. The login Brain is literally only concerned with getting the data to the source of auth data, and then signalling to the auth service that somebody is logged in.

This is basically a view on the login service. In HTML mode, we would direct the user through one or more forms, while on the CLI we can direct them through one or more prompts.

The idea would be that the login service could be quizzed for its behaviour. I don't propose that we make a generic view that can handle all login services (although, with an OpenAPI format of hashrefs we could certainly try), but rather that each login style ships with multiple views.

An obvious example is to take the current auth system and turn it into a Hive auth system:

Around this:

Around that:

fb11-auth

Altreus commented 5 years ago

I've added the "breaking change" label even though it might not actually be a breaking change. We could in theory update everything at once (i.e. the Catalyst auth process) so the migration is seamless.