Ejemplo n.º 1
0
        private async Task RefreshToken(BerlinGroupUserConsent consent)
        {
            try
            {
                var content = new StringContent($"client_id={_settings.NcaId}&grant_type=refresh_token&refresh_token={consent.RefreshToken}",
                                                Encoding.UTF8, "application/x-www-form-urlencoded");

                var client = GetClient();
                var result = await client.PostAsync($"/ASK/oauth/token/1", content);

                var auth = JsonConvert.DeserializeObject <BerlinGroupAccessData>(await result.Content.ReadAsStringAsync());
                consent.Token           = auth.Token;
                consent.TokenValidUntil = DateTime.Now.AddSeconds(auth.expires_in - 60);
                consent.RefreshToken    = auth.refresh_token;
            }
            catch (Exception e)
            {
                // An error occured in refreshing, this is not recoverable. Set the date to yesterday to show it invalid
                consent.TokenValidUntil = DateTime.Now.AddDays(-1);
                throw e;
            }
            finally
            {
                UserContextChanged = true;
            }
        }
Ejemplo n.º 2
0
        private void RemoveConsent(BerlinGroupUserConsent consent)
        {
            if (consent?.ConsentId == null)
            {
                return;
            }

            _userContextLocal.Accounts.Where(x => x.BalancesConsentId == consent.ConsentId).ToList().ForEach(x =>
            {
                x.BalancesConsentId = null;
            });
            _userContextLocal.Accounts.Where(x => x.TransactionsConsentId == consent.ConsentId).ToList().ForEach(x =>
            {
                x.TransactionsConsentId = null;
            });

            _userContextLocal.Accounts.RemoveAll(x => x.TransactionsConsentId == null && x.BalancesConsentId == null);
            _userContextLocal.Consents.Remove(consent);
            UserContextChanged = true;
        }