Comments (3)
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 onAuthenticatorContract
.- All drivers has same API.
Cons
- Each Authenticator driver must know and validate structure of its
$options
array. This could be solved by addingsetCredentials
method.
from youtrack-rest-php.
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 onAuthenticatorContract
.- 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.
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)
- Refactor authorizers HOT 4
- Refactor Client
- Request options & headers HOT 1
- OAuth support
- Move documentation to wiki HOT 1
- Write more PHPUnit tests
- Make client endpointPathPrefix configurable
- Add factories to simplify instantiation process
- Refactor exceptions
- Wrong Authenticator behavior
- Configurable API endpoint prefix HOT 1
- How to update issue (priority)?
- [Concept] Remove Authorization responsibility from YouTrackClient HOT 1
- Use PSR-18
- GET request error
- Guzzle 7 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from youtrack-rest-php.