Code Monkey home page Code Monkey logo

Comments (3)

antonkomarev avatar antonkomarev commented on August 14, 2024 2

Version 3

Token Authenticator

$http = new \GuzzleHttp\Client([
    'base_uri' => 'https://example.com',
]);

$authenticator = new \Cog\YouTrack\Authenticators\TokenAuthenticator([
    'token' => 'YOUTRACK_API_TOKEN',
]);

$client = new \Cog\YouTrack\Services\YouTrackClient($http, $authenticator);

Cookie Authenticator

$http = new \GuzzleHttp\Client([
    'base_uri' => 'https://example.com',
]);

$authenticator = new \Cog\YouTrack\Authenticators\CookieAuthenticator([
    'username' => 'YOUTRACK_USERNAME',
    'password' => 'YOUTRACK_PASSWORD',
]);

$client = new \Cog\YouTrack\Services\YouTrackClient($http, $authenticator);

Container Binding

$this->app->bind(YouTrackClientContract::class, function () {
    $config = $this->app->make('config');

    $http = new Client([
        'base_uri' => $config->get('youtrack.base_uri'),
    ]);

    $options = $config->get('youtrack.authenticators.' . $config->get('youtrack.authenticator'));
    $authenticator = new $options['driver']($options);

    return new YouTrackClient($http, $authenticator);
});

Conclusion

Pros

  • YouTrackClient not responsible for authenticator.
  • YouTrackClient constructor will rely on AuthenticatorContract.
  • All drivers has same API.

Cons

  • Each Authenticator driver must know and validate structure of its $options array. This could be solved by adding setCredentials method.

from youtrack-rest-php.

antonkomarev avatar antonkomarev commented on August 14, 2024 1

Version 2

Token Authenticator

$http = new \GuzzleHttp\Client([
    'base_uri' => 'https://example.com',
]);

$authenticator = new \Cog\YouTrack\Authenticators\TokenAuthenticator('YOUTRACK_API_TOKEN');

$client = new \Cog\YouTrack\Services\YouTrackClient($http, $authenticator);

Cookie Authenticator

$http = new \GuzzleHttp\Client([
    'base_uri' => 'https://example.com',
]);

$authenticator = new \Cog\YouTrack\Authenticators\CookieAuthenticator(
    'YOUTRACK_USERNAME',
    'YOUTRACK_PASSWORD'
);

$client = new \Cog\YouTrack\Services\YouTrackClient($http, $authenticator);

Container Binding

$this->app->bind(YouTrackClientContract::class, function () {
    $config = $this->app->make('config');

    $http = new Client([
        'base_uri' => $config->get('youtrack.base_uri'),
    ]);

    $options = $config->get('youtrack.authenticators.' . $config->get('youtrack.authenticator'));
    if ($options['driver'] == 'token') {
        $authenticator = new $options['driver']($options['token']);
    } elseif ($options['driver'] == 'cookie') {
        $authenticator = new $options['driver']($options['username'], $options['password']);
    } elseif (class_exists($options['driver']) {
        $authenticator = new $options['driver']($options);
    } else {
        $authenticator = new \Cog\YouTrack\Authenticators\NullAuthenticator();
    }

    return new YouTrackClient($http, $authenticator);
});

Conclusion

Pros

  • YouTrackClient not responsible for authenticator.
  • YouTrackClient constructor will rely on AuthenticatorContract.
  • Authenticators credentials wouldn't require array validation because of strict string type of input params.

Cons

  • Require AuthenticatorManager to remove conditionals.
  • Custom drives will has different API from official ones (cannot has fixed amount of custom driver params and will bypass credentials in array).

from youtrack-rest-php.

antonkomarev avatar antonkomarev commented on August 14, 2024

API refactoring in progress #18. Trying to decrease Authorizers responsibilities. This changes will add Authenticators and will have Breaking Changes in API provided above.

from youtrack-rest-php.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.