Comments (4)
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.
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.
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.
Version 1 was implemented.
from youtrack-rest-php.
Related Issues (17)
- API client connection design HOT 3
- 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.