def get_token(required_role: Roles::PUBLIC)
        token = params[:token]

        # Look up the cache. If present, use it and skip the verification.
        # Use token itself (and not a session UUID) as part of the key so
        # it can be considered *verified*.
        @auth_session = Cache.get(kind: :session, token: token)

        # Cache miss. So proceed to verify the token and get user and
        # session data from database. Then set the cache for later.
        if @auth_session.nil?
          @auth_session = verify_token(token)
          @auth_session.role  # NOTE: no-op
          Cache.set({kind: :session, token: token}, @auth_session)
        end

        # Obtained session may not have enough permission. Check here.
        if @auth_session.role < required_role
          logger.error("Not enough permission (role: #{@auth_session.role})")
          raise UNAUTHORIZED_ERROR, "Invalid token"
        end
        @auth_user = @auth_session.user
        @token = @auth_session.token
        return true
      end
def get_token(required_role: Roles::PUBLIC)
        token = params[:token]

        # Look up the cache. If present, use it and skip the verification.
        # Use token itself (and not a session UUID) as part of the key so
        # it can be considered *verified*.
        @auth_session = Cache.get(kind: :session, token: token)

        # Cache miss. So proceed to verify the token and get user and
        # session data from database. Then set the cache for later.
        if @auth_session.nil?
          @auth_session = verify_token(token)
          @auth_session.role  # NOTE: no-op
          Cache.set({kind: :session, token: token}, @auth_session)
        end

        # Obtained session may not have enough permission. Check here.
        if @auth_session.role < required_role
          logger.error("Not enough permission (role: #{@auth_session.role})")
          raise UNAUTHORIZED_ERROR, "Invalid token"
        end
        @auth_user = @auth_session.user
        @token = @auth_session.token
        return true
      end
Attempt to get a token for the session. Token must be specified in
 query string or part of the JSON object.

 Raises a UNAUTHORIZED_ERROR if cached session has less role
 than what's required.