2

After reviewing my options regarding saving JWT token, I chose Xamarin.Essentials Secure Storage.

Problem being that my app always breaks when trying to save a token within the storage with the following error:

"System.AggregateException has been thrown"

The details are as follow:

"Xamarin.Essentials.NotImplementedInReferenceAssemblyException

This functionality is not implemented in the portable version of this assembly. You should reference the NuGet package from your main application project in order to reference the platform-specific implementation."

This clearly means that something went wrong in the installaion of the nuget package, so I:

  • Uninstalled and reinstalled the xamarin.essentials package.
  • Upgraded .Netstandard to 2.0, thinking that 1.6 wasn't compatible.
  • Checked if the package is referenced within the csproj file.

So forth, nothing.

For now, I have a TokenStorageController with the following lines of codes :

    public bool SaveToken(string token)
    {
        if(token != null)
        {
            Preferences.Set(key, token);

            if(Preferences.ContainsKey(key))
            {
                return true;
            }
        }    
        return false;
    }

The RestService class from where the controller gets called looks like this :

        //await SecureStorage.SetAsync("oauth_token", "booommmmmm"); // changed to this simply to check if my controller was the problem
        TokenStorageController tokenStorage = new TokenStorageController();
        await tokenStorage.SaveToken("boommmmm"); // where I get an error

And here is the exact line where the error occurs:

      var loginTask = Task.Run(() => restService.LoginAsync(user)).Result;

If no solutions, I will remove all packages and reinstall them all. ONE BY ONE! I swear I'll do it! And if no solutions at all, I will store the token within SQL as I already have a controller in place to do so.

I am a Xamarin and C# noob so bear with me please.

FYI: I am using a macOS client for testing purposes, as the cause could be that SecureStorage doesn't work for macOS apps.

Thanks!

Prashant Cholachagudda
  • 13,012
  • 23
  • 97
  • 162
Khal_Tech
  • 315
  • 1
  • 3
  • 13
  • 2
    If you look at the code, `Xamarin.Mac` is not currently a supported platform, just iOS, Android, UWP: https://github.com/xamarin/Essentials/tree/master/Xamarin.Essentials/SecureStorage – SushiHangover May 24 '18 at 04:21
  • Thanks. My fear all along. If you could answer so that I could select your answer as THE ANSWER! I will try this NUGET package then: http://nugetmusthaves.com/Package/sameerIOTApps.Plugin.SecureStorage Even though I don't know how secure it really is. Thanks again! – Khal_Tech May 24 '18 at 05:01

1 Answers1

2

Xamarin.Mac is not currently a supported platform, just iOS, Android, UWP.

The code is available for review at:

SushiHangover
  • 73,120
  • 10
  • 106
  • 165