Skip to content

Commit 89158d0

Browse files
committed
Fix dll ref error on Linux.
1 parent 8b58b3f commit 89158d0

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

src/Authentication/Authentication/Constants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ public static class Constants
1515
internal const int MaxDeviceCodeTimeOut = 120; // 2 mins timeout.
1616
internal const string UserCacheFileName = "userTokenCache.bin3";
1717
internal const string AppCacheFileName = "appTokenCache.bin3";
18-
internal static readonly string TokenCacheDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".Graph");
18+
internal static readonly string TokenCacheDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".graph");
1919
}
2020
}

src/Authentication/Authentication/Helpers/AuthenticationHelpers.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace Microsoft.Graph.PowerShell.Authentication.Helpers
55
{
66
using Microsoft.Graph.Auth;
77
using Microsoft.Graph.PowerShell.Authentication.Models;
8+
using Microsoft.Graph.PowerShell.Authentication.TokenCache;
89
using Microsoft.Identity.Client;
910
using System;
1011
using System.IO;
@@ -64,7 +65,7 @@ private static void ConfigureTokenCache(ITokenCache tokenCache, string tokenCach
6465
lock (FileLock)
6566
{
6667
args.TokenCache.DeserializeMsalV3(File.Exists(tokenCacheFilePath)
67-
? TokenCryptoHelpers.DecryptToken(File.ReadAllBytes(tokenCacheFilePath))
68+
? TokenCryptographer.DecryptToken(File.ReadAllBytes(tokenCacheFilePath))
6869
: null,
6970
shouldClearExistingCache: true);
7071
}
@@ -75,7 +76,7 @@ private static void ConfigureTokenCache(ITokenCache tokenCache, string tokenCach
7576
{
7677
if (args.HasStateChanged)
7778
{
78-
File.WriteAllBytes(tokenCacheFilePath, TokenCryptoHelpers.EncryptToken(args.TokenCache.SerializeMsalV3()));
79+
File.WriteAllBytes(tokenCacheFilePath, TokenCryptographer.EncryptToken(args.TokenCache.SerializeMsalV3()));
7980
}
8081
}
8182
});

src/Authentication/Authentication/Helpers/TokenCryptoHelpers.cs renamed to src/Authentication/Authentication/TokenCache/TokenCryptographer.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
// ------------------------------------------------------------------------------
22
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
33
// ------------------------------------------------------------------------------
4-
namespace Microsoft.Graph.PowerShell.Authentication.Helpers
4+
namespace Microsoft.Graph.PowerShell.Authentication.TokenCache
55
{
66
using System;
7-
using System.Security.Cryptography;
87

98
/// <summary>
109
/// Helper class to handle token encryption and decryption.
1110
/// </summary>
12-
internal static class TokenCryptoHelpers
11+
internal static class TokenCryptographer
1312
{
1413
/// <summary>
1514
/// Encrypts the passed buffer based on the host platform.
@@ -19,7 +18,7 @@ internal static class TokenCryptoHelpers
1918
public static byte[] EncryptToken(byte[] buffer)
2019
{
2120
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
22-
return ProtectedData.Protect(buffer, null, DataProtectionScope.CurrentUser);
21+
return WindowsTokenCache.EncryptToken(buffer);
2322
return buffer;
2423
}
2524

@@ -31,7 +30,7 @@ public static byte[] EncryptToken(byte[] buffer)
3130
public static byte[] DecryptToken(byte[] buffer)
3231
{
3332
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
34-
return ProtectedData.Unprotect(buffer, null, DataProtectionScope.CurrentUser);
33+
return WindowsTokenCache.DecryptToken(buffer);
3534
return buffer;
3635
}
3736
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// ------------------------------------------------------------------------------
2+
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
3+
// ------------------------------------------------------------------------------
4+
5+
namespace Microsoft.Graph.PowerShell.Authentication.TokenCache
6+
{
7+
using System.Security.Cryptography;
8+
internal static class WindowsTokenCache
9+
{
10+
/// <summary>
11+
/// Encrypts the passed buffer using Windows DPAPI.
12+
/// </summary>
13+
/// <param name="buffer">A <see cref="byte[]"/> to encrypt.</param>
14+
/// <returns>An encrypted <see cref="byte[]"/>.</returns>
15+
public static byte[] EncryptToken(byte[] buffer)
16+
{
17+
return ProtectedData.Protect(buffer, null, DataProtectionScope.CurrentUser);
18+
}
19+
20+
/// <summary>
21+
/// Decrypts the passed buffer Windows DPAPI.
22+
/// </summary>
23+
/// <param name="buffer">A <see cref="byte[]"/> to decrypt.</param>
24+
/// <returns>An decrypted <see cref="byte[]"/>.</returns>
25+
public static byte[] DecryptToken(byte[] buffer)
26+
{
27+
return ProtectedData.Unprotect(buffer, null, DataProtectionScope.CurrentUser);
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)