Indatus/trucker

Extending Auth Driver

jralph opened this issue · 1 comments

I am looking at using trucker for a project I am working on but need to be able to use it with OAuth2. I have looked at the contributing.md about creating a new driver but I am unsure on where to start.

I noticed that it says the new driver must be in the namespace \Trucker\Requests\Auth. Does this mean that I would be adding my new driver into the trucker package when downloaded, creating a composer autoload rule for it to be able to find it, or some other way?

Thanks!

@jralph that is correct. Trucker has some expectations on the namespace and class naming conventions. This allows you to create your class, then simply modify the config to use it by driver name. You don't have to modify other classes / factories etc to allow for your new drivers use.

You'd want your new OAuth2 class to be in the Trucker\Requests\Auth namespace and have a class name suffix of Authenticator, additionally it would need to implement the Trucker\Requests\Auth\AuthenticationInterface interface.

For example:

<?php namespace Trucker\Requests\Auth;

class Oauth2Authenticator implements AuthenticationInterface 
{
// ...
}

If you had any specific configuration items that were required for your driver you could add them in the config/auth.php file under an oauth2 key and reference them in your driver via Config::get('auth.oauth2.some_config_item');

Once your driver was all ready to use in your application you would have setup the Trucker config files. In the auth.php file you'd set the driver option to oauth2 or whatever you ended up calling it.