In a Xamarin.Forms project and I'd like to use Xamarin.Auth just to store and retrieve Account object securely. Please note that I am not taking about integrating with Facebook, Google or any other service that serves end-to-end oAuth login experience.
3 Answers
If you are only after secure storage of objects then XLabs.Platform has ISecureStorage interface which is implemented for iOS, Android & WP. If you are working with Forms I would suggest installing XLabs.Forms package from NuGet and then using Ioc (XLabs.Ioc) inject the implementations to PCL code. You can also use XLabs.Serialization to serializer/deserialize bytes using Json.NET, ServiceStack or other serializers like ProtoBuffer (available as XLabs.Serialization plugins).

- 5,234
- 1
- 16
- 25
This topic is being discussed over at the Xamarin Forums. You might want to check out the thread there.
Xamarin.Auth is not a PCL and platform specific. You'll need to work with custom renderers. First create a Forms page for your login:
public class LoginPage : ContentPage
{
}
then implement it for the platforms, here for instance iOS:
[assembly: ExportRenderer (typeof (LoginPage), typeof (LoginPageRenderer))]
namespace Demo.XForms.iOS
{
public class LoginPageRenderer : PageRenderer
{
public override void ViewDidAppear (bool animated)
{
base.ViewDidAppear (animated);
var auth = new OAuth2Authenticator (
clientId: ...,
scope: "basic",
authorizeUrl: new Uri ("..."),
redirectUrl: new Uri ("..."));
auth.Completed += (sender, eventArgs) => {
DismissViewController (true, null);
if (eventArgs.IsAuthenticated) {
App.SaveToken(eventArgs.Account.Properties["access_token"]);
} else {
// The user cancelled
}
};
PresentViewController (auth.GetUI (), true, null);
}
}
}
With that in place you can use it from within Forms:
this.MainPage = new LoginPage ();

- 32,180
- 27
- 124
- 263
In 2019, you can use SecureStorage from Xamarin.Essentials to store account information. Under the hood, it uses the the platform standards: Keychain on iOS, Keystore on Android. Thus it also supports backup to cloud, but also needs permissions.
https://learn.microsoft.com/en-us/xamarin/essentials/secure-storage
Also, the AccountStore in Xamarin.Auth is deprecated now and they are advising to use SecureStorage from Xamarin.Essentials now.

- 2,101
- 2
- 22
- 36