/// <summary>
        /// Returns an authentication context using a token cache created from the current identity. Assumes that the identity
        /// is a <see cref="ClaimsIdentity"/> identity instance.
        /// </summary>
        public static AuthenticationContext CreateAuthenticationContext(this IIdentity identity)
        {
            var cache = new AdalTokenCache(identity.NameIdentifier());
            AuthenticationContext authContext = new AuthenticationContext(identity.Authority(), cache);

            return(authContext);
        }
        public static ActiveDirectoryClient CreateActiveDirectoryClient(this IIdentity identity)
        {
            var tenantId = identity.TenantId();
            var root     = new Uri(new Uri(AppSettings.GraphResourceId), tenantId);

            return(new ActiveDirectoryClient(root, async() =>
            {
                List <TokenCacheItem> items = null;

                await Task.Run(() =>
                {
                    var cache = new AdalTokenCache(identity.NameIdentifier());
                    items = cache.ReadItems().ToList();
                });

                if (items.Count > 0)
                {
                    return items.First().AccessToken;
                }

                return null;
            }));
        }