NuGet.Services.Operations.AzureTokenManager.StoreToken C# (CSharp) Method

StoreToken() public method

public StoreToken ( AzureToken token ) : System.Threading.Tasks.Task
token AzureToken
return System.Threading.Tasks.Task
        public async Task StoreToken(AzureToken token)
        {
            string dir = Path.Combine(_root, "Subscriptions");
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            string path = Path.Combine(dir, token.SubscriptionId + ".dat");

            string content = JsonFormat.Serialize(token);
            var protectedData = Convert.ToBase64String(
                ProtectedData.Protect(
                    Encoding.UTF8.GetBytes(content),
                    null,
                    DataProtectionScope.CurrentUser));

            using (var writer = new StreamWriter(path))
            {
                await writer.WriteAsync(protectedData);
            }
        }
    }