Beispiel #1
0
        private bool SaveTokens(IDictionary <string, object> tokens)
        {
            _checkedTokens = true;
            if (tokens == null)
            {
                return(DeleteTokens());
            }

            if (!tokens.ContainsKey("refresh_token") && RefreshToken != null)
            {
                tokens ["refresh_token"] = RefreshToken;
            }

            var itemData = Manager.GetObjectMapper().WriteValueAsBytes(tokens);
            var request  = CreateRequest();

            request.Data = itemData;
            var storage = InjectableCollection.GetImplementation <ISecureStorage>();

            try {
                storage.Write(request);
            } catch (Exception e) {
                Log.To.Sync.W(Tag, $"{this} failed to save OpenID Connect token", e);
                return(false);
            }

            Log.To.Sync.I(Tag, "{0} saved ID token to storage", this);
            return(true);
        }
Beispiel #2
0
        private bool LoadTokens()
        {
            if (_checkedTokens)
            {
                return(IDToken != null);
            }

            _checkedTokens = true;
            var storage = InjectableCollection.GetImplementation <ISecureStorage>();
            var stored  = default(IEnumerable <byte>);

            try {
                stored = storage.Read(CreateRequest());
            } catch (Exception e) {
                Log.To.Sync.W(Tag, $"{this} Error reading ID token from storage", e);
                return(false);
            }

            if (stored == null)
            {
                Log.To.Sync.I(Tag, "{0} No ID token found in storage", this);
                return(false);
            }

            var tokens = Manager.GetObjectMapper().ReadValue <IDictionary <string, object> >(stored);

            if (ParseTokens(tokens))
            {
                Log.To.Sync.I(Tag, "{0} Read ID token from storage", this);
            }

            return(true);
        }
Beispiel #3
0
        private bool DeleteTokens()
        {
            var storage = InjectableCollection.GetImplementation <ISecureStorage>();

            try {
                storage.Delete(CreateRequest());
            } catch (Exception e) {
                Log.To.Sync.W(Tag, $"{this} failed to delete ID token", e);
                return(false);
            }

            return(true);
        }
        public static void Run()
        {
#if __ANDROID__
            if (global::Android.OS.Build.VERSION.SdkInt >= global::Android.OS.BuildVersionCodes.M)
            {
                InjectableCollection.RegisterImplementation <ISecureStorage>(() => new SecureStorageAES());
            }
            else
            {
                InjectableCollection.RegisterImplementation <ISecureStorage>(() => new SecureStorageRSA());
            }
#else
            InjectableCollection.RegisterImplementation <ISecureStorage>(() => new SecureStorage());
#endif
        }
 public static void Run()
 {
     InjectableCollection.RegisterImplementation <ISecureStorage>(() => new SecureStorage());
 }