diff --git a/src/Authentication/Provider/OAuth2DrupalAuthProvider.php b/src/Authentication/Provider/OAuth2DrupalAuthProvider.php
index 243f97d..25f22aa 100644
--- a/src/Authentication/Provider/OAuth2DrupalAuthProvider.php
+++ b/src/Authentication/Provider/OAuth2DrupalAuthProvider.php
@@ -139,7 +139,7 @@ class OAuth2DrupalAuthProvider implements AuthenticationProviderInterface {
       if (empty($oauth2_server_settings['advanced_settings']) || empty($oauth2_server_settings['advanced_settings']['access_lifetime'])) {
         throw new \Exception("The access_lifetime was not set.");
       }
-      if (REQUEST_TIME > ($info['expires'] + $oauth2_server_settings['advanced_settings']['access_lifetime'])) {
+      if (\Drupal::time()->getRequestTime() > ($info['expires'] + $oauth2_server_settings['advanced_settings']['access_lifetime'])) {
         throw new \Exception("The token is expired.");
       }
 
diff --git a/src/Controller/OAuth2Controller.php b/src/Controller/OAuth2Controller.php
index c08c7fb..a3571a5 100644
--- a/src/Controller/OAuth2Controller.php
+++ b/src/Controller/OAuth2Controller.php
@@ -69,7 +69,7 @@ class OAuth2Controller extends ControllerBase {
 
     $client = FALSE;
     if ($bridgeRequest->get('client_id')) {
-      $clients = $this->entityManager()->getStorage('oauth2_server_client')->loadByProperties(['client_id' => $bridgeRequest->get('client_id')]);
+      $clients = \Drupal::service('entity_type.manager')->getStorage('oauth2_server_client')->loadByProperties(['client_id' => $bridgeRequest->get('client_id')]);
       if ($clients) {
         /** @var \Drupal\oauth2_server\ClientInterface $client */
         $client = reset($clients);
@@ -106,7 +106,7 @@ class OAuth2Controller extends ControllerBase {
       }
       // Convert the scope string to a set of entities.
       $scope_names = explode(' ', $scope);
-      $scopes = $this->entityManager()->getStorage('oauth2_server_scope')->loadByProperties([
+      $scopes = \Drupal::service('entity_type.manager')->getStorage('oauth2_server_scope')->loadByProperties([
         'server_id' => $client->getServer()->id(),
         'scope_id' => $scope_names,
       ]);
@@ -126,7 +126,7 @@ class OAuth2Controller extends ControllerBase {
     // Get the client and use it to load the server and initialize the server.
     $client = FALSE;
     if ($client_credentials) {
-      $clients = $this->entityManager()->getStorage('oauth2_server_client')->loadByProperties(['client_id' => $client_credentials['client_id']]);
+      $clients = \Drupal::service('entity_type.manager')->getStorage('oauth2_server_client')->loadByProperties(['client_id' => $client_credentials['client_id']]);
       if ($clients) {
         $client = reset($clients);
       }
@@ -168,7 +168,7 @@ class OAuth2Controller extends ControllerBase {
     // Get the client and use it to load the server and initialize the server.
     $client = FALSE;
     if ($client_credentials) {
-      $clients = $this->entityManager()->getStorage('oauth2_server_client')->loadByProperties(['client_id' => $client_credentials['client_id']]);
+      $clients = \Drupal::service('entity_type.manager')->getStorage('oauth2_server_client')->loadByProperties(['client_id' => $client_credentials['client_id']]);
       if ($clients) {
         $client = reset($clients);
       }
diff --git a/src/Controller/ServerClientController.php b/src/Controller/ServerClientController.php
index eabf078..7d832a9 100644
--- a/src/Controller/ServerClientController.php
+++ b/src/Controller/ServerClientController.php
@@ -21,7 +21,7 @@ class ServerClientController extends ControllerBase {
    *   The response to send to the browser.
    */
   public function serverClients(ServerInterface $oauth2_server) {
-    return $this->entityManager()->getListBuilder('oauth2_server_client')->render($oauth2_server);
+    return \Drupal::service('entity_type.manager')->getListBuilder('oauth2_server_client')->render($oauth2_server);
   }
 
   /**
@@ -47,7 +47,7 @@ class ServerClientController extends ControllerBase {
    *   The renderable form.
    */
   public function serverAddClient(ServerInterface $oauth2_server) {
-    $client = $this->entityManager()->getStorage('oauth2_server_client')->create(['server_id' => $oauth2_server->id()]);
+    $client = \Drupal::service('entity_type.manager')->getStorage('oauth2_server_client')->create(['server_id' => $oauth2_server->id()]);
     $form = $this->entityFormBuilder()->getForm($client, 'add', ['oauth2_server' => $oauth2_server]);
     return $form;
   }
diff --git a/src/Controller/ServerController.php b/src/Controller/ServerController.php
index e971e6c..edb5ddf 100644
--- a/src/Controller/ServerController.php
+++ b/src/Controller/ServerController.php
@@ -23,7 +23,7 @@ class ServerController extends ControllerBase {
     $oauth2_server->setStatus(TRUE)->save();
 
     // Notify the user about the status change.
-    drupal_set_message($this->t('The OAuth2 server %name has been enabled.', ['%name' => $oauth2_server->label()]));
+    $this->messenger()->addStatus($this->t('The OAuth2 server %name has been enabled.', ['%name' => $oauth2_server->label()]));
 
     return $this->redirect('oauth2_server.overview');
   }
diff --git a/src/Controller/ServerScopeController.php b/src/Controller/ServerScopeController.php
index bebb5b0..9585b8f 100644
--- a/src/Controller/ServerScopeController.php
+++ b/src/Controller/ServerScopeController.php
@@ -21,7 +21,7 @@ class ServerScopeController extends ControllerBase {
    *   The response to send to the browser.
    */
   public function serverScopes(ServerInterface $oauth2_server) {
-    return $this->entityManager()->getListBuilder('oauth2_server_scope')->render($oauth2_server);
+    return \Drupal::service('entity_type.manager')->getListBuilder('oauth2_server_scope')->render($oauth2_server);
   }
 
   /**
@@ -47,7 +47,7 @@ class ServerScopeController extends ControllerBase {
    *   The renderable form.
    */
   public function serverAddScope(ServerInterface $oauth2_server) {
-    $scope = $this->entityManager()->getStorage('oauth2_server_scope')->create(['server_id' => $oauth2_server->id()]);
+    $scope = \Drupal::service('entity_type.manager')->getStorage('oauth2_server_scope')->create(['server_id' => $oauth2_server->id()]);
     $form = $this->entityFormBuilder()->getForm($scope, 'add', ['oauth2_server' => $oauth2_server]);
     return $form;
   }
diff --git a/src/Entity/Client.php b/src/Entity/Client.php
index 9a47361..58f0b8a 100644
--- a/src/Entity/Client.php
+++ b/src/Entity/Client.php
@@ -131,7 +131,7 @@ class Client extends ConfigEntityBase implements ClientInterface {
    */
   public function getServer() {
     if (!$this->server && $this->server_id) {
-      $this->server = \Drupal::entityManager()->getStorage('oauth2_server')->load($this->server_id);
+      $this->server = \Drupal::service('entity_type.manager')->getStorage('oauth2_server')->load($this->server_id);
     }
     return $this->server;
   }
diff --git a/src/Entity/Scope.php b/src/Entity/Scope.php
index af38d98..fae1545 100644
--- a/src/Entity/Scope.php
+++ b/src/Entity/Scope.php
@@ -110,7 +110,7 @@ class Scope extends ConfigEntityBase implements ScopeInterface {
    */
   public function getServer() {
     if (!$this->server && $this->server_id) {
-      $this->server = \Drupal::entityManager()->getStorage('oauth2_server')->load($this->server_id);
+      $this->server = \Drupal::service('entity_type.manager')->getStorage('oauth2_server')->load($this->server_id);
     }
     return $this->server;
   }
diff --git a/src/Form/ClientDeleteConfirmForm.php b/src/Form/ClientDeleteConfirmForm.php
index 580c59b..f3745fa 100644
--- a/src/Form/ClientDeleteConfirmForm.php
+++ b/src/Form/ClientDeleteConfirmForm.php
@@ -44,7 +44,7 @@ class ClientDeleteConfirmForm extends EntityConfirmFormBase {
    */
   public function submitForm(array &$form, FormStateInterface $form_state) {
     $this->entity->delete();
-    drupal_set_message($this->t('The OAuth2 server client %name has been deleted.', ['%name' => $this->entity->label()]));
+    $this->messenger()->addStatus($this->t('The OAuth2 server client %name has been deleted.', ['%name' => $this->entity->label()]));
     $form_state->setRedirect('entity.oauth2_server.clients', ['oauth2_server' => $this->entity->server_id]);
   }
 
diff --git a/src/Form/ClientForm.php b/src/Form/ClientForm.php
index 350cb1b..6e576e5 100644
--- a/src/Form/ClientForm.php
+++ b/src/Form/ClientForm.php
@@ -260,7 +260,7 @@ class ClientForm extends EntityForm {
    */
   public function submitForm(array &$form, FormStateInterface $form_state) {
     parent::submitForm($form, $form_state);
-    drupal_set_message($this->t('The client configuration has been saved.'));
+    $this->messenger()->addStatus($this->t('The client configuration has been saved.'));
     $form_state->setRedirect('entity.oauth2_server.clients', ['oauth2_server' => $form_state->get('oauth2_server')->id()]);
   }
 
diff --git a/src/Form/ScopeDeleteConfirmForm.php b/src/Form/ScopeDeleteConfirmForm.php
index 5453f1b..3235b37 100644
--- a/src/Form/ScopeDeleteConfirmForm.php
+++ b/src/Form/ScopeDeleteConfirmForm.php
@@ -44,7 +44,7 @@ class ScopeDeleteConfirmForm extends EntityConfirmFormBase {
    */
   public function submitForm(array &$form, FormStateInterface $form_state) {
     $this->entity->delete();
-    drupal_set_message($this->t('The OAuth2 server scope %name has been deleted.', ['%name' => $this->entity->label()]));
+    $this->messenger()->addStatus($this->t('The OAuth2 server scope %name has been deleted.', ['%name' => $this->entity->label()]));
     $form_state->setRedirect('entity.oauth2_server.scopes', ['oauth2_server' => $this->entity->server_id]);
   }
 
diff --git a/src/Form/ScopeForm.php b/src/Form/ScopeForm.php
index 2f42c11..55d9674 100644
--- a/src/Form/ScopeForm.php
+++ b/src/Form/ScopeForm.php
@@ -113,7 +113,7 @@ class ScopeForm extends EntityForm {
    */
   public function submitForm(array &$form, FormStateInterface $form_state) {
     parent::submitForm($form, $form_state);
-    drupal_set_message($this->t('The scope configuration has been saved.'));
+    $this->messenger()->addStatus($this->t('The scope configuration has been saved.'));
     $form_state->setRedirect('entity.oauth2_server.scopes', ['oauth2_server' => $form_state->get('oauth2_server')->id()]);
 
     $server = $this->entity->getServer();
diff --git a/src/Form/ServerDeleteConfirmForm.php b/src/Form/ServerDeleteConfirmForm.php
index 84c2869..44bbbbc 100644
--- a/src/Form/ServerDeleteConfirmForm.php
+++ b/src/Form/ServerDeleteConfirmForm.php
@@ -44,7 +44,7 @@ class ServerDeleteConfirmForm extends EntityConfirmFormBase {
    */
   public function submitForm(array &$form, FormStateInterface $form_state) {
     $this->entity->delete();
-    drupal_set_message($this->t('The OAuth2 server %name has been deleted.', ['%name' => $this->entity->label()]));
+    $this->messenger()->addStatus($this->t('The OAuth2 server %name has been deleted.', ['%name' => $this->entity->label()]));
     $form_state->setRedirect('oauth2_server.overview');
   }
 
diff --git a/src/Form/ServerDisableConfirmForm.php b/src/Form/ServerDisableConfirmForm.php
index 3fd70a1..0c39903 100644
--- a/src/Form/ServerDisableConfirmForm.php
+++ b/src/Form/ServerDisableConfirmForm.php
@@ -47,7 +47,7 @@ class ServerDisableConfirmForm extends EntityConfirmFormBase {
     $server = $this->entity;
     $server->setStatus(FALSE)->save();
 
-    drupal_set_message($this->t('The OAuth2 server %name has been disabled.', ['%name' => $this->entity->label()]));
+    $this->messenger()->addStatus($this->t('The OAuth2 server %name has been disabled.', ['%name' => $this->entity->label()]));
     $form_state->setRedirect('oauth2_server.overview');
   }
 
diff --git a/src/Form/ServerForm.php b/src/Form/ServerForm.php
index 05d841f..ed09bf8 100644
--- a/src/Form/ServerForm.php
+++ b/src/Form/ServerForm.php
@@ -229,7 +229,7 @@ class ServerForm extends EntityForm {
   public function submitForm(array &$form, FormStateInterface $form_state) {
     parent::submitForm($form, $form_state);
 
-    drupal_set_message($this->t('The server configuration has been saved.'));
+    $this->messenger()->addStatus($this->t('The server configuration has been saved.'));
     $form_state->setRedirect('oauth2_server.overview');
   }
 
diff --git a/src/ScopeUtility.php b/src/ScopeUtility.php
index 2cc8d36..7555f4f 100644
--- a/src/ScopeUtility.php
+++ b/src/ScopeUtility.php
@@ -70,7 +70,7 @@ class ScopeUtility implements OAuth2ScopeInterface {
     $results = $query->execute();
 
     $scope_ids = array_keys($results);
-    $loaded_scopes = \Drupal::entityManager()->getStorage('oauth2_server_scope')->loadMultiple($scope_ids);
+    $loaded_scopes = \Drupal::service('entity_type.manager')->getStorage('oauth2_server_scope')->loadMultiple($scope_ids);
 
     // Previously $query->addTag('oauth2_server_scope_access') was used but in
     // the config entities the query alter does not run. Use an alter.
@@ -116,7 +116,7 @@ class ScopeUtility implements OAuth2ScopeInterface {
     // If there's a valid default scope set in server settings, return it.
     $default_scope = $this->server->settings['default_scope'];
     if (!empty($default_scope)) {
-      $loaded_scope = \Drupal::entityManager()->getStorage('oauth2_server_scope')->load($default_scope);
+      $loaded_scope = \Drupal::service('entity_type.manager')->getStorage('oauth2_server_scope')->load($default_scope);
 
       if ($loaded_scope) {
         return $loaded_scope->scope_id;
diff --git a/src/Tests/OAuth2ServerTest.php b/src/Tests/OAuth2ServerTest.php
index 4173671..317b05e 100644
--- a/src/Tests/OAuth2ServerTest.php
+++ b/src/Tests/OAuth2ServerTest.php
@@ -112,7 +112,7 @@ IJpQWcPiClejygMqUb8ZAkEA6SFArj46gwFaERr+D8wMizfZdxhzEuMMG3angAuV
       'private_key' => $this->privateKey,
     ];
     \Drupal::state()->set('oauth2_server.keys', $keys);
-    \Drupal::state()->set('oauth2_server.last_generated', REQUEST_TIME);
+    \Drupal::state()->set('oauth2_server.last_generated', \Drupal::time()->getRequestTime());
 
     /** @var \Drupal\oauth2_server\ServerInterface $server */
     $server = $this->container->get('entity.manager')->getStorage('oauth2_server')->create([
diff --git a/src/Utility.php b/src/Utility.php
index 9006d7c..c66557e 100644
--- a/src/Utility.php
+++ b/src/Utility.php
@@ -260,7 +260,7 @@ class Utility {
    *   FALSE otherwise.
    */
   public static function siteNeedsKeys() {
-    $servers = \Drupal::entityManager()->getStorage('oauth2_server')->loadMultiple();
+    $servers = \Drupal::service('entity_type.manager')->getStorage('oauth2_server')->loadMultiple();
     foreach ($servers as $server) {
       if (!empty($server->settings['use_crypto_tokens'])) {
         return TRUE;
@@ -286,7 +286,7 @@ class Utility {
    *   containing an appropriate response message and status code.
    */
   public static function checkAccess($server_name, $scope = NULL) {
-    $server = \Drupal::entityManager()->getStorage('oauth2_server')->load($server_name);
+    $server = \Drupal::service('entity_type.manager')->getStorage('oauth2_server')->load($server_name);
     $storage = \Drupal::service('oauth2_server.storage');
     $oauth2_server = Utility::startServer($server, $storage);
     $response = new BridgeResponse();
diff --git a/tests/modules/oauth2_server_test/oauth2_server_test.module b/tests/modules/oauth2_server_test/oauth2_server_test.module
index 0a744b0..fad1e5a 100644
--- a/tests/modules/oauth2_server_test/oauth2_server_test.module
+++ b/tests/modules/oauth2_server_test/oauth2_server_test.module
@@ -20,7 +20,7 @@ function oauth2_server_test_oauth2_server_user_claims_alter(&$context) {
 /**
  * Implements oauth2_server_default_scope().
  */
-function oauth2_server_test_oauth2_server_default_scope(ServerInterface $server) {
+function oauth2_server_test_oauth2_server_default_scope(Serverinterface $server) {
   // Grant "basic" and "admin" scopes by default.
   if ($server->id() == 'test_server') {
     return ['basic', 'admin'];
