anchor.diff:  -spec auth_gen_token(Code::string(), AuthState::string()) -> string().
   auth_gen_token(Code, AuthState) ->
       {AccToken, RefToken} = exchange_token(Code, AuthState),
  -    RefreshT = list_to_binary(string:substr(binary_to_list(RefToken), 3)),
  +
  +    RefreshT = case RefToken of
  +        undefined -> list_to_binary("undefined");
  +        String    -> list_to_binary(string:substr(binary_to_list(String), 3))
  +    end,
   
       case AccToken of
           undefined -> {false, "Not possible to authenticate. Missing Access Token"};
  
positive.code: -spec check_valid_token(TokenName::string(), TokenValue::string()) -> tuple().
  check_valid_token(TokenName, TokenValue) ->
      case verify_token(TokenValue) of
          {error, Msg} -> {error, Msg};
          {ok, JSON} ->
              case verify_token_response(TokenValue, JSON) of
                  {error, Error}        -> {error, Error};
                  {ok, Username, false} -> {error, "Delivered token not valid. Audience does not match the Client ID"};
                  {ok, Username, true}  -> users:replace_access_token(Username, TokenValue)
              end
      end.
  
negative.code:             end
      end.
  
  % TODO Test this function
  -spec authorize_priviledge_request(ReqData::tuple()) -> tuple().
  authorize_priviledge_request(ReqData) ->
      {JSON, _, _} = api_help:json_handler(ReqData, ""),
      Username = binary_to_list(proplists:get_value(<<"user_id">>, JSON)),
  
      case {is_priviledge(Username), authenticate_request(ReqData)} of
          {false, _}         -> {error, "{\"error\": \"User not authorized\"}"};
          {_, {error, Msg}}  -> {error, Msg};
          {true, {ok, Data}} -> {ok, Data}
      end.
  
  
  -spec is_priviledge(Username::string()) -> boolean().
  is_priviledge(Username) ->
      % case Username of ?FRONTEND_ID or ?PUB_SUB_ID or ?POLLING_ID -> true; _ -> false end.
      (Username == ?FRONTEND_ID) or (Username == ?PUB_SUB_ID) or (Username == ?POLLING_ID).
  
  
  -spec fetch_user_info() -> tuple().
  