void saveClientAuthDetailsToKeychain(ClientAuthDetails details)
 {
     if (!string.IsNullOrEmpty(details?.Token))
     {
         saveItemToKeychain(KeychainServiceName(details.ClientAuthProvider, ClientAuthDetailTypes.Token), ClientAuthDetailTypes.Token.ToString(), details.Token);
     }
     if (!string.IsNullOrEmpty(details?.Name))
     {
         saveItemToKeychain(KeychainServiceName(details.ClientAuthProvider, ClientAuthDetailTypes.Name), ClientAuthDetailTypes.Name.ToString(), details.Name);
     }
     if (!string.IsNullOrEmpty(details?.GivenName))
     {
         saveItemToKeychain(KeychainServiceName(details.ClientAuthProvider, ClientAuthDetailTypes.GivenName), ClientAuthDetailTypes.GivenName.ToString(), details.GivenName);
     }
     if (!string.IsNullOrEmpty(details?.FamilyName))
     {
         saveItemToKeychain(KeychainServiceName(details.ClientAuthProvider, ClientAuthDetailTypes.FamilyName), ClientAuthDetailTypes.FamilyName.ToString(), details.FamilyName);
     }
     if (!string.IsNullOrEmpty(details?.Username))
     {
         saveItemToKeychain(KeychainServiceName(details.ClientAuthProvider, ClientAuthDetailTypes.Username), ClientAuthDetailTypes.Username.ToString(), details.Username);
     }
     if (!string.IsNullOrEmpty(details?.Email))
     {
         saveItemToKeychain(KeychainServiceName(details.ClientAuthProvider, ClientAuthDetailTypes.Email), ClientAuthDetailTypes.Email.ToString(), details.Email);
     }
     if (!string.IsNullOrEmpty(details?.AuthCode))
     {
         saveItemToKeychain(KeychainServiceName(details.ClientAuthProvider, ClientAuthDetailTypes.AuthCode), ClientAuthDetailTypes.AuthCode.ToString(), details.AuthCode);
     }
     if (!string.IsNullOrEmpty(details?.AvatarUrl))
     {
         saveItemToKeychain(KeychainServiceName(details.ClientAuthProvider, ClientAuthDetailTypes.AvatarUrl), ClientAuthDetailTypes.AvatarUrl.ToString(), details.AvatarUrl);
     }
 }
        public void SetClientAuthDetails(ClientAuthDetails details)
        {
            Log.Debug(details?.ToString());

            ClientAuthDetails = details;

            AuthorizationChanged?.Invoke(this, ClientAuthDetails);
        }
        ClientAuthDetails initClientAuthDetails()
        {
            var providers = new [] { ClientAuthProviders.Google, ClientAuthProviders.Facebook, ClientAuthProviders.Microsoft, ClientAuthProviders.Twitter };

            var clientAuthDetails = new ClientAuthDetails();

            ClientAuthProviders?provider = null;

            string token = null;            // = getItemFromKeychain (KeychainServiceName (ClientAuthProviders.Google, ClientAuthDetailTypes.Token));

            foreach (var item in providers)
            {
                token = getItemFromKeychain(KeychainServiceName(item, ClientAuthDetailTypes.Token)).PrivateKey;

                if (!string.IsNullOrEmpty(token))
                {
                    provider = item;

                    break;
                }
            }

            if (provider.HasValue)
            {
                Log.Debug($"Existing ClientAuthProvider found: {provider.Value}");

                clientAuthDetails.ClientAuthProvider = provider.Value;
                clientAuthDetails.Token      = token;
                clientAuthDetails.Name       = getItemFromKeychain(KeychainServiceName(provider.Value, ClientAuthDetailTypes.Name)).PrivateKey;
                clientAuthDetails.GivenName  = getItemFromKeychain(KeychainServiceName(provider.Value, ClientAuthDetailTypes.GivenName)).PrivateKey;
                clientAuthDetails.FamilyName = getItemFromKeychain(KeychainServiceName(provider.Value, ClientAuthDetailTypes.FamilyName)).PrivateKey;
                clientAuthDetails.Username   = getItemFromKeychain(KeychainServiceName(provider.Value, ClientAuthDetailTypes.Username)).PrivateKey;
                clientAuthDetails.Email      = getItemFromKeychain(KeychainServiceName(provider.Value, ClientAuthDetailTypes.Email)).PrivateKey;
                clientAuthDetails.AuthCode   = getItemFromKeychain(KeychainServiceName(provider.Value, ClientAuthDetailTypes.AuthCode)).PrivateKey;
                clientAuthDetails.AvatarUrl  = getItemFromKeychain(KeychainServiceName(provider.Value, ClientAuthDetailTypes.AvatarUrl)).PrivateKey;

                return(clientAuthDetails);
            }

            return(null);
        }