anchor.diff:      AccToken = proplists:get_value(<<"access_token">>, Token),
       RefToken = proplists:get_value(<<"refresh_token">>, Token),
       {AccToken, RefToken}.
  -
  -
  --spec authenticate_request(ReqData::tuple()) -> tuple().
  -authenticate_request(ReqData) -> authenticate_token("Access-Token", ReqData).
  -
  -
  --spec authenticate_token(TokenName::string(), ReqData::tuple()) -> tuple().
  -authenticate_token(TokenName, ReqData) ->
  -    case wrq:get_req_header(TokenName, ReqData) of
  -        undefined -> {error, "{\"error\": \"Not possible to perform the request. Missing " ++ TokenName ++ "\"}"};
  -        TokenVal  -> check_valid_token(TokenName, TokenVal)
  -    end.
  -
  -
  -%%% Private Functions
  -
  --spec check_valid_token(TokenName::string(), TokenValue::string()) -> tuple().
  -check_valid_token(TokenName, TokenValue) ->
  -    case verify_token(TokenValue) of
  -        {error, Msg} -> {error, "{\"error\": \"" ++ Msg ++ "\"}"};
  -        {ok, JSON}   ->
  -            case verify_token_response(TokenValue, JSON) of
  -                {error, Error}        -> {error, Error};
  -                {ok, Username, false} -> {error, "{\"error\": \"Token not valid. Expended by other system\"}"};
  -                {ok, Username, true}  -> users:replace_token(Username, TokenName, TokenValue)
  -            end
  -    end.
  -
  -
  --spec verify_token(Token::string()) -> tuple().
  -verify_token(Token) ->
  -    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, "Token not valid or already expired"}
  -    end.
  -
  -
  --spec verify_token_response(NewToken::string(), JSON::tuple()) -> tuple().
  -verify_token_response(NewToken, JSON) ->
  -    case proplists:get_value(<<"error">>, JSON) of
  -        undefined ->
  -            Username = binary_to_list(proplists:get_value(<<"user_id">>, JSON)),
  -            case binary_to_list(proplists:get_value(<<"audience">>, JSON)) of
  -                undefined -> {error, "Delivered token not valid. Audience field not found"};
  -                Audience  -> {ok, Username, Audience == ?CLIENT_ID}
  -            end;
  -        Error -> {error, binary_to_list(Error)}
  -    end.
  -
  
positive.code: %% @author Georgios Koutsoumpakis, Li Hao
  %% [www.csproj13.student.it.uu.se]
  %% @version 1.0
  %% @copyright [Copyright information]
  
  %% @doc Webmachine_resource for /users
  
  -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]).
  
  % TODO Grab these settings from a config file
  -define(APIKEY, "AIzaSyCyC23vutanlgth_1INqQdZsv6AgZRiknY").
  
negative.code:     end.
  
  
  -spec generate_idp_token(Code::string(), AuthState::string()) -> string().
  generate_idp_token(Code, AuthState) ->
      {AccToken, RefToken} = exchange_token(Code, AuthState),
  
      % RefToken = case RefreshT of
      %     undefined -> list_to_binary("undefined");
      %     % String    -> list_to_binary(string:substr(binary_to_list(String), 3))
      %     String -> list_to_binary(String)
      % end,
  
      case AccToken of
          undefined -> {false, "Not possible to authenticate. Missing Access Token"};
          _ ->
              case fetch_user_info() of
                  {error, _} -> {false, "Not possible to authenticate. Unreachable user info"};
                  {ok, UserData} ->
                      Username = binary_to_list(proplists:get_value(<<"id">>, UserData)),
                      Status = case users:user_is_new(Username) of
  