code: @Override
      protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
          SessionConfiguration config = Server.createSessionConfiguration();
          if (oAuth2Credentials == null) {
              oAuth2Credentials = Server.createOAuth2Credentials(config);
          }
  
          // Load the user from their user ID (derived from the request).
          HttpSession httpSession = req.getSession(true);
          if (httpSession.getAttribute(Server.USER_SESSION_ID) == null) {
              httpSession.setAttribute(Server.USER_SESSION_ID, new Random().nextLong());
          }
          credential = oAuth2Credentials.loadCredential(httpSession.getAttribute(Server.USER_SESSION_ID).toString());
  
          if (credential != null && credential.getAccessToken() != null) {
  
              if (uberRidesService == null) {
  
                  CredentialsSession session = new CredentialsSession(config, credential);
  
  //                Set up the Uber API Service once the user is authenticated.
                  UberRidesApi api = UberRidesApi.with(session).build();
                  uberRidesService = api.createService();
              }
  
              super.service(req, resp);
          } else {
              resp.sendRedirect(oAuth2Credentials.getAuthorizationUrl());
          }
      }
docs: Before each request, fetch an OAuth2 credential for the user or redirect them to the
  OAuth2 login page instead.