public override async Task <SocialAuthIdentity> GetIdentity(string code)
        {
            try
            {
                using var client = new HttpClient();

                var url    = $"https://api.vk.com/method/users.get?access_token={code}&v=5.110";
                var result = await client.GetAsync(url);

                var str = await result.Content.ReadAsStringAsync();

                const string toDeleteFirst = "{\"response\":[";
                const string toDeleteLast  = "]}";
                str = str.Remove(str.IndexOf("{\"response\":["), toDeleteFirst.Length);
                str = str.Remove(str.IndexOf("]}"), toDeleteLast.Length);

                var profile        = JsonConvert.DeserializeObject <VkIdentity>(str);
                var socialIdentity = new SocialAuthIdentity
                {
                    Id    = profile.id,
                    Email = profile.email,
                    Name  = profile.first_name + " " + profile.last_name
                };

                return(socialIdentity);
            }
            catch
            {
                return(null);
            }
        }
        public async Task <User> FindUser(SocialAuthIdentity identity)
        {
            if (identity == null)
            {
                return(null);
            }

            return(await _db.Users.SingleOrDefaultAsync(u =>
                                                        u.SocialAccounts.Any(a => a.Provider.Name == ProviderName && a.Key == identity.Id)));
        }
        public async Task <SocialAccount> CreateAccount(SocialAuthIdentity identity)
        {
            if (identity == null || await _db.SocialAccounts.AnyAsync(a => a.Key == identity.Id && a.UserId != null))
            {
                return(null);
            }

            return(new SocialAccount
            {
                Key = identity.Id,
                Provider = await _db.SocialAccountsProviders.FirstOrDefaultAsync(r =>
                                                                                 r.Name == ProviderName)
            });
        }