     ;; Future enhancement: validate that min fields are provided
     (token-db/create context info)))
 
+(defn- strip-bearer-if-exists
+  "Remove 'Bearer ' from the front of the token if it exists"
+  [token]
+  (if (and (>= (count token) 7) (= "Bearer " (subs token 0 7)))
+    (subs token 7)
+    token))
+
 (defn- get-token-or-error
   "Helper for getting the token if it exists or thowing an error"
   [context token-id]
-  (if-let [token (token-db/fetch context token-id)]
-    token
-    (svc-errors/throw-service-error :unauthorized (str "Token [" token-id "] does not exist"))))
+  (let [token-id (strip-bearer-if-exists token-id)]
+    (if-let [token (token-db/fetch context token-id)]
+      token
+      (svc-errors/throw-service-error :unauthorized (str "Token [" token-id "] does not exist")))))
 
 (defn logout
   [context token-id]


(defn build-routes [system]
  (routes
    (context "/tokens" []
      ;; Login
      (POST "/" {params :params context :request-context body :body}
        (let [token (login context (slurp body))
              url (str "http://localhost:3000/tokens/" (:id token))]
          {:status 201
           :content-type :json
           :headers {"Location" url}
           :body {:token token}}))
      (POST "/get_token_info" {context :request-context headers :headers {token-id :id} :params}
        (get-token-info context headers token-id))
      (context "/:token-id" [token-id]
        ;; Logout
        (DELETE "/" {context :request-context}
          (logout context token-id)
          {:status 200})
        (GET "/current_sids" {context :request-context}
          ;; Does not require sys admin token
          (if (= "expired-token" token-id)
            ;; echo-rest returns status code 400 for request with expired token
            (ah/status-bad-request {:errors ["Token [expired-token] has expired."]})
            (ah/status-ok (get-current-sids context token-id))))
        (GET "/token_info" {context :request-context headers :headers}
          (get-token-info context headers token-id))))
    (GET "/availability" {context :request-context}
      {:status 200})))

   [compojure.core :refer :all]))

(def token-keys
  #{;; Fields provided during login
    :username
    :client_id
    :password
