anchor.diff:  -module(openidc).
   -export([init/1,
            auth_gen_token/2,
  +         authenticate_request/1,
            authenticate_token/2,
  +         authorize_priviledge_request/1,
  +         is_priviledge/1,
            exchange_token/2,
            fetch_user_info/0,
            process_auth_request/2,
            process_auth_redirect/2]).
  -
  -% -include("webmachine.hrl").
  -% -include_lib("erlastic_search.hrl").
  -% -include("field_restrictions.hrl").
   
   % TODO Grab these settings from a config file
   -define(APIKEY, "AIzaSyCyC23vutanlgth_1INqQdZsv6AgZRiknY").
   -define(CLIENT_ID, "995342763478-fh8bd2u58n1tl98nmec5jrd76dkbeksq.apps.googleusercontent.com").
   -define(CLIENT_SECRET, "fVpjWngIEny9VTf3ZPZr8Sh6").
   -define(REDIRECT_URL, "http://localhost:8000/users/_openid").
  +
  +-define(FRONTEND_ID, "107908217220817548513").
  +-define(PUB_SUB_ID,  "<< add here ... >>").
  +-define(POLLING_ID,  "<< add here ... >>").
  +
   
   % %% @doc
   % %% Function: init/1
  
positive.code:     AuthURL = "https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=" ++ Token,
      case plus_srv:get_url(httpc:request(get,{AuthURL,[]},[],[])) of
          {ok, Json} -> {ok, Json};
          {error, _} -> {error, "Delivered token already expired"}
      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().
  