diff --git a/oauth.install b/oauth.install
index 7f642ef..c99f76d 100644
--- a/oauth.install
+++ b/oauth.install
@@ -1,4 +1,5 @@
 <?php
+
 /**
  * @file
  * Installation and schema related functions for the OAuth module.
@@ -53,7 +54,7 @@ function oauth_schema() {
         'length'      => 40,
         'not null'    => TRUE,
       ),
-      // Key is a reserved word in MySQL so lets avoid that
+      // Key is a reserved word in MySQL so let's avoid that.
       'consumer_key' => array(
         'description' => 'Consumer key.',
         'type'        => 'text',
@@ -68,7 +69,7 @@ function oauth_schema() {
     'primary key' => array('cid'),
     'indexes' => array(
       'key_hash' => array('key_hash'),
-       'uid' => array('uid'),
+      'uid' => array('uid'),
     ),
     'foreign keys' => array(
       'users' => array(
diff --git a/oauth.services.yml b/oauth.services.yml
index 53edd36..d8b6729 100644
--- a/oauth.services.yml
+++ b/oauth.services.yml
@@ -1,5 +1,10 @@
 services:
   authentication.oauth:
-    class: Drupal\oauth\Authentication\Provider\OAuthDrupalProvider
+    class: 'Drupal\oauth\Authentication\Provider\OAuthDrupalProvider'
+    arguments: ['@database', '@logger.channel.oauth']
     tags:
-      - { name: authentication_provider, priority: 100 }
+      - { name: 'authentication_provider', priority: 100 }
+
+  logger.channel.oauth:
+    parent: 'logger.channel_base'
+    arguments: ['oauth']
diff --git a/src/Authentication/Provider/OAuthDrupalProvider.php b/src/Authentication/Provider/OAuthDrupalProvider.php
index 9be22ef..1f4adca 100644
--- a/src/Authentication/Provider/OAuthDrupalProvider.php
+++ b/src/Authentication/Provider/OAuthDrupalProvider.php
@@ -7,11 +7,12 @@
 
 namespace Drupal\oauth\Authentication\Provider;
 
+
 use Drupal\Core\Authentication\AuthenticationProviderInterface;
-use Symfony\Component\HttpFoundation\RedirectResponse;
-use Symfony\Component\HttpFoundation\Response;
+use Drupal\Core\Database\Connection;
+use Drupal\user\Entity\User;
+use Psr\Log\LoggerInterface;
 use Symfony\Component\HttpFoundation\Request;
-use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
 use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
 use \OauthProvider;
 use \OauthException;
@@ -22,6 +23,20 @@ use \OauthException;
 class OAuthDrupalProvider implements AuthenticationProviderInterface {
 
   /**
+   * The database service.
+   *
+   * @var \Drupal\Core\Database\Connection
+   */
+  protected $connection;
+
+  /**
+   * The logger service for OAuth.
+   *
+   * @var \Psr\Log\LoggerInterface
+   */
+  protected $logger;
+
+  /**
    * An authenticated user object.
    *
    * @var \Drupal\user\UserBCDecorator
@@ -29,6 +44,17 @@ class OAuthDrupalProvider implements AuthenticationProviderInterface {
   protected $user;
 
   /**
+   * Constructor.
+   *
+   * @param \Psr\Log\LoggerInterface $logger
+   *   The logger service for OAuth.
+   */
+  public function __construct(Connection $connection, LoggerInterface $logger) {
+    $this->connection = $connection;
+    $this->logger = $logger;
+  }
+
+  /**
    * {@inheritdoc}
    */
   public function applies(Request $request) {
@@ -43,17 +69,18 @@ class OAuthDrupalProvider implements AuthenticationProviderInterface {
     try {
       // Initialize and configure the OauthProvider too handle the request.
       $this->provider = new OAuthProvider();
-      $this->provider->consumerHandler(array($this,'lookupConsumer'));
-      $this->provider->timestampNonceHandler(array($this,'timestampNonceChecker'));
-      $this->provider->tokenHandler(array($this,'tokenHandler'));
+      $this->provider->consumerHandler(array($this, 'lookupConsumer'));
+      $this->provider->timestampNonceHandler(array($this, 'timestampNonceChecker'));
+      $this->provider->tokenHandler(array($this, 'tokenHandler'));
       $this->provider->is2LeggedEndpoint(TRUE);
 
       // Now check the request validity.
       $this->provider->checkOAuthRequest();
-    } catch (OAuthException $e) {
+    }
+    catch (OAuthException $e) {
       // The OAuth extension throws an alert when there is something wrong
       // with the request (ie. the consumer key is invalid).
-      watchdog('oauth', $e->getMessage(), array(), WATCHDOG_WARNING);
+      $this->logger->warning($e->getMessage());
       return NULL;
     }
 
@@ -82,19 +109,27 @@ class OAuthDrupalProvider implements AuthenticationProviderInterface {
    * For the moment it handles two legged authentication for a pair of
    * dummy key and secret, 'a' and 'b' respectively.
    *
-   * @param \OAuthProvider
+   * @param \OAuthProvider $provider
    *   An instance of OauthProvider with the authorization request headers.
-   * @return
-   *   constant OAUTH_OK if the authentication was successfull.
-   *   OAUTH_CONSUMER_KEY_UNKNOWN if not.
+   *
+   * @return int
+   *   - OAUTH_OK if the authentication was successful.
+   *   - OAUTH_CONSUMER_KEY_UNKNOWN if not.
+   *
    * @see http://www.php.net/manual/en/class.oauthprovider.php
    */
-  public function lookupConsumer($provider) {
-    $row = db_query('select * from {oauth_consumer} where consumer_key = :consumer_key',
-                    array(':consumer_key' => $provider->consumer_key))->fetchObject();
+  public function lookupConsumer(OAuthProvider $provider) {
+    $sql = <<<SQL
+SELECT *
+FROM {oauth_consumer}
+WHERE consumer_key = :consumer_key
+SQL;
+
+    $query_arguments = [':consumer_key' => $provider->consumer_key];
+    $row = $this->connection->query($sql, $query_arguments)->fetchObject();
     if (!empty($row)) {
       $provider->consumer_secret = $row->consumer_secret;
-      $this->user = user_load($row->uid);
+      $this->user = User::load($row->uid);
       return OAUTH_OK;
     }
     else {
@@ -119,4 +154,5 @@ class OAuthDrupalProvider implements AuthenticationProviderInterface {
   public function timestampNonceChecker($provider) {
     return OAUTH_OK;
   }
+
 }
diff --git a/src/Controller/OAuthController.php b/src/Controller/OAuthController.php
index ab3efe6..11a039b 100644
--- a/src/Controller/OAuthController.php
+++ b/src/Controller/OAuthController.php
@@ -7,10 +7,12 @@
 
 namespace Drupal\oauth\Controller;
 
+use Drupal\Core\Database\Connection;
+use Drupal\Core\Url;
+use Drupal\Core\Utility\LinkGeneratorInterface;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
 use Drupal\user\UserInterface;
-use Drupal\oauth\Form\OAuthDeleteConsumerForm;
 
 /**
  * Controller routines for book routes.
@@ -18,16 +20,43 @@ use Drupal\oauth\Form\OAuthDeleteConsumerForm;
 class OAuthController implements ContainerInjectionInterface {
 
   /**
+   * The database service.
+   *
+   * @var \Drupal\Core\Database\Connection
+   */
+  protected $connection;
+
+  /**
+   * The URL generator service.
+   *
+   * @var \Drupal\Core\Utility\LinkGeneratorInterface
+   */
+  protected $linkGenerator;
+
+  /**
    * Constructs a BookController object.
+   *
+   * @param \Drupal\Core\Database\Connection $connection
+   *   The database service.
+   * @param \Drupal\Core\Utility\LinkGeneratorInterface $link_generator
+   *   The link generator service.
    */
-  public function __construct() {
+  public function __construct(Connection $connection, LinkGeneratorInterface $link_generator) {
+    $this->connection = $connection;
+    $this->linkGenerator = $link_generator;
   }
 
   /**
    * {@inheritdoc}
    */
   public static function create(ContainerInterface $container) {
-    return new static();
+    /** @var \Drupal\Core\Database\Connection $connection */
+    $connection = $container->get('database');
+
+    /** @var \Drupal\Core\Utility\LinkGeneratorInterface $link_generator */
+    $link_generator = $container->get('url_generator');
+
+    return new static($connection, $link_generator);
   }
 
   /**
@@ -40,15 +69,19 @@ class OAuthController implements ContainerInjectionInterface {
    *   A HTML-formatted string with the list of OAuth consumers.
    */
   public function consumers(UserInterface $user) {
-    $request = \Drupal::request();
     $list = array();
 
-    $list['heading']['#markup'] = l(t('Add consumer'), 'oauth/consumer/add');
+    $list['heading']['#markup'] = $this->linkGenerator->generate(t('Add consumer'), Url::fromRoute('oauth.user_consumer_add'));
 
     // Get the list of consumers.
-    $result = db_query('select *
-                        from {oauth_consumer}
-                        where uid = :uid', array(':uid' => $user->id()));
+    $sql = <<<SQL
+SELECT *
+FROM {oauth_consumer}
+WHERE uid = :uid'
+SQL;
+
+    $query_args = [':uid' => $user->id()];
+    $result = $this->connection->query($sql, $query_args);
 
     // Define table headers.
     $list['table'] = array(
@@ -79,7 +112,7 @@ class OAuthController implements ContainerInjectionInterface {
               '#links' => array(
                 'delete' => array(
                   'title' => t('Delete'),
-                  'href' => 'oauth/consumer/delete/' . $row->cid,
+                  'url' => Url::fromRoute('oauth.user_consumer_delete', ['cid' => $row->cid]),
                 ),
               ),
             ),
