public async Task <Account> GetAccount(User user, CancellationToken cancellationToken) { Ensure.Any.IsNotNull(user, nameof(user)); var cachedAccount = _accountCache.GetAccount(user.Username); if (cachedAccount != null) { return(cachedAccount); } var parsedAccount = new Account(user.Username); var account = await _accountStore.GetAccount(parsedAccount.Provider, parsedAccount.Subject, cancellationToken).ConfigureAwait(false); if (account.IsNewAccount) { // This account has just been created var profile = await CreateProfile(account.Id, user, cancellationToken).ConfigureAwait(false); _profileCache.StoreProfile(profile); } _accountCache.StoreAccount(account); return(account); }