Giter Site home page Giter Site logo

Comments (4)

antonkomarev avatar antonkomarev commented on May 18, 2024

Version 1

Token Authorization

use Cog\YouTrack\Rest;

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

$authorizer = new Rest\Authorizer\TokenAuthorizer('YOUTRACK_API_TOKEN');

$client = new Rest\Client\YouTrackClient($http, $authorizer);

Cookie Authorization

use Cog\YouTrack\Rest;

$http = new \GuzzleHttp\Client([
    'base_uri' => $apiBaseUri,
]);

$authenticator = new Rest\Authenticator\CookieAuthenticator(
    'YOUTRACK_USERNAME', 'YOUTRACK_PASSWORD'
);

$authorizer = new Rest\Authorizer\CookieAuthorizer($authenticator);

$client = new Rest\Client\YouTrackClient($http, $authorizer);

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.authorizers.' . $config->get('youtrack.authorizer'));
    if ($options['driver'] == 'token') {
        $authorizer = new $options['driver']($options['token']);
    } elseif ($options['driver'] == 'cookie') {
        $authenticator = new \Cog\YouTrack\Rest\Authenticator\CookieAuthenticator(
            $options['username'],
            $options['password']
        );
        $authorizer = new $options['driver']($authenticator);
    } elseif (class_exists($options['driver']) {
        $authorizer = new $options['driver']($options);
    } else {
        $authorizer = new \Cog\YouTrack\Rest\Authorizer\NullAuthorizer();
    }

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

from youtrack-rest-php.

antonkomarev avatar antonkomarev commented on May 18, 2024

Version 2

Token Authorization

use Cog\YouTrack\Rest;

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

$authorizer = new Rest\Authorizer\TokenAuthorizer([
    'token' => 'YOUTRACK_API_TOKEN',
]);

$client = new Rest\Client\YouTrackClient($http, $authorizer);

Cookie Authorization

use Cog\YouTrack\Rest;

$http = new \GuzzleHttp\Client([
    'base_uri' => $apiBaseUri,
]);

$authenticator = new Rest\Authenticator\CookieAuthenticator([
    'username' => 'YOUTRACK_USERNAME',
    'password' => 'YOUTRACK_PASSWORD',
]);

$authorizer = new Rest\Authorizer\CookieAuthorizer($authenticator);

$client = new Rest\Client\YouTrackClient($http, $authorizer);

Container Binding

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

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

    $authorizerName = $config->get('youtrack.authorizer');

    $options = $config->get('youtrack.authorizers.' . $authorizerName);
    if ($authorizerName == 'cookie') {
        $authenticator = new \Cog\YouTrack\Rest\Authenticator\CookieAuthenticator($options);
        $authorizer = new $options['driver']($authenticator);
    } else {
        $authorizer = new $options['driver']($options);
    }

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

from youtrack-rest-php.

antonkomarev avatar antonkomarev commented on May 18, 2024

Because now we can't instantiate authorizer without conditional checks there is not much benefit from passing options as array. But we definitely require factory for building Authorizers and have an ability to define own factories within application.

from youtrack-rest-php.

antonkomarev avatar antonkomarev commented on May 18, 2024

Version 1 was implemented.

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.