bshaffer/oauth2-server-php — pull request #316 by bojanz (2014-01-21 23:46:19+00:00)
Title: Improve crypto token DX

Crypto tokens have bad DX. Previously I could initialize the server with my storage and I would be ready to serve requests. But if I want to support crypto tokens, I suddenly need to add a ton of boilerplate:

```diff
function oauth2_server_start($server = NULL) {
$storage = new Drupal\oauth2_server\Storage();
+ $storage_list = array(
+ 'access_token' => $storage,
+ 'authorization_code' => $storage,
+ 'client_credentials' => $storage,
+ 'client' => $storage,
+ 'refresh_token' => $storage,
+ 'user_credentials' => $storage,
+ 'jwt_bearer' => $storage,
+ );
$grant_types = oauth2_server_grant_types();
+
if ($server) {
- $oauth2_server = new OAuth2\Server($storage, $server->settings);
- // Initialize the scope util.
+ $response_types = array(
+ 'token' => new OAuth2\ResponseType\AccessToken($storage, $storage, $server->settings),
+ 'code' => new OAuth2\ResponseType\AuthorizationCode($storage, $server->settings),
+ );
+ // Wrap the storage if crypto tokens should be used.
+ if (!empty($server->settings['use_crypto_tokens'])) {
+ $storage_list['access_token'] = new OAuth2\Storage\CryptoToken($storage, $storage);
+ $response_types['token'] = new OAuth2\ResponseType\CryptoToken($storage);
+ }
+ // Initialize the server and add the scope util.
+ $oauth2_server = new OAuth2\Server($storage_list, $server->settings, array(), $response_types);

It feels better to have a "use_crypto_tokens" setting that would do the work for me.