anchor.diff:      List = lists:reverse(lists:foldl(Extract, [], Services)),
       jsx:encode(#{service_list => List}).
   
  -return_oidc_list(Oidc) ->
  -    Id = fun({OidcId, Pid}, List) ->
  -                 Result = oidcc:get_openid_provider_info(Pid),
  -                 case Result of
  -                 {ok, #{issuer := Issuer, ready := true}}  ->
  -                         [#{ id => OidcId, issuer => Issuer} | List];
  +return_json_oidc_list(Oidc) ->
  +    Id = fun(OidcInfo, List) ->
  +                 case OidcInfo of
  +                 #{issuer := Issuer, id := Id, ready := true}  ->
  +                         [#{ id => Id, issuer => Issuer} | List];
                        _ -> List
                    end
            end,
       List = lists:reverse(lists:foldl(Id, [], Oidc)),
       jsx:encode(#{openid_provider_list => List}).
   
  -return_credential_list(Credentials) ->
  +return_json_credential_list(Credentials) ->
       Id = fun(CredId, List) ->
                    [#{ id => CredId} | List]
            end,
  
positive.code: 
  resource_exists(Req, #state{id=undefined} = State) ->
      {true, Req, State};
  resource_exists(Req, #state{type=oidcp, id=Id} = State) ->
      case oidcc:get_openid_provider_info(Id) of
          {ok, Info} ->
              {true, Req, State#state{object = Info}};
          _ -> {false, Req, State}
      end;
  resource_exists(Req, #state{type=service, id=Id} = State) ->
      case tts_service:get_info(Id) of
          {ok, Info} ->
              {true, Req, State#state{object = Info}};
          _ -> {false, Req, State}
      end;
  resource_exists(Req, #state{type=credential, id=Id,
                              user_info=#{site := #{uid :=UserId}}}=State) ->
      Result = tts_credential:exists(UserId, Id),
      {Result, Req, State};
  resource_exists(Req, #state{type=cred_data}=State) ->
      {true, Req, State};
  resource_exists(Req, State) ->
      {false, Req, State}.
  
  delete_resource(Req, #state{type=credential,
                              id=CredentialId, user_info=UserInfo}=State) ->
       case tts_credential:revoke(CredentialId, UserInfo) of
           {ok, _, _} -> {true, Req, State};
           _ -> {false, Req, State}
       end.
  
  
  get_json(Req, #state{version=Version, type=Type, id=Id, method=get,
                       object=Object, user_info=UserInfo } = State) ->
      Result = perform_get(Type, Id, Object, UserInfo, Version),
      {Result, Req, State}.
  
  
  post_json(Req, #state{version=Version, type=Type, id=Id, method=post,
                        user_info=UserInfo, json=Json} = State) ->
      Result = perform_post(Type, Id, Json, UserInfo, Version),
      {Result, Req, State}.
  
  perform_get(service, undefined, _, #{ site := #{uid:=UserId}}, _Version) ->
      {ok, ServiceList} = tts_service:get_list(UserId),
      return_service_list(ServiceList);
  perform_get(oidcp, undefined, _, _, _Version) ->
      {ok, OIDCList} = oidcc:get_openid_provider_list(),
      return_oidc_list(OIDCList);
  perform_get(credential, undefined, _, #{ site := #{uid := UserId}}, _Version) ->
      {ok, CredList} = tts_credential:get_list(UserId),
      return_credential_list(CredList);
  perform_get(cred_data, Id, _, #{ site := #{uid := UserId}}, _Version) ->
      case tts_rest_cred:get_cred(Id, UserId) of
          {ok, Cred} -> jsx:encode(Cred);
          _ -> jsx:encode(#{})
      end.
  
  perform_post(credential, undefined, #{service_id:=ServiceId}, UserInfo, Ver) ->
      IFace = <<"REST interface">>,
      case  tts_credential:request(ServiceId, UserInfo, IFace, rest, []) of
          {ok, Credential, _Log} ->
              #{ site := #{ uid := UserId }} = UserInfo,
              {ok, Id} = tts_rest_cred:add_cred(Credential, UserId),
              Url = id_to_url(Id, Ver),
              {true, Url};
          _ ->
              false
      end.
  
  return_service_list(Services) ->
      Extract = fun(Map, List) ->
                        Keys = [id, type, host, port],
                        [ maps:with(Keys, Map) | List]
  
negative.code: 
  is_authorized(Req, #state{type=oidcp} = State) ->
      {true, Req, State};
  is_authorized(Req, #state{type=Type, token=Token, issuer=Issuer} = State)
    when Type==service; Type==credential; Type==cred_data ->
      case tts:login_with_access_token(Token, Issuer) of
          {ok, #{session_pid := SessionPid}} ->
              {true, Req, State#state{session_pid = SessionPid}};
          {error, _} ->
              {{false, <<"Authorization">>}, Req, State}
  
      end;
  is_authorized(Req, State) ->
      {{false, <<"Authorization">>}, Req, State}.
  