Skip to content

Commit c80acac

Browse files
committed
Use session keyring on Linux.
1 parent 46f2c81 commit c80acac

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

src/Authentication/Authentication/Constants.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ public static class Constants
1313
internal const string UserParameterSet = "UserParameterSet";
1414
internal const string AppParameterSet = "AppParameterSet";
1515
internal const int MaxDeviceCodeTimeOut = 120; // 2 mins timeout.
16-
internal const string UserCacheFileName = "userTokenCache.bin3";
17-
internal const string AppCacheFileName = "appTokenCache.bin3";
1816
internal static readonly string TokenCacheDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".graph");
1917
internal const string TokenCahceServiceName = "com.microsoft.graph.powershell.sdkcache";
2018
}

src/Authentication/Authentication/Helpers/AuthenticationHelpers.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal static IAuthenticationProvider GetAuthProvider(IAuthContext authConfig)
2424
.WithTenantId(authConfig.TenantId)
2525
.Build();
2626

27-
ConfigureTokenCache(publicClientApp.UserTokenCache, authConfig.ClientId, Constants.UserCacheFileName);
27+
ConfigureTokenCache(publicClientApp.UserTokenCache, authConfig.ClientId);
2828
return new DeviceCodeProvider(publicClientApp, authConfig.Scopes, async (result) => {
2929
await Console.Out.WriteLineAsync(result.Message);
3030
});
@@ -37,7 +37,7 @@ internal static IAuthenticationProvider GetAuthProvider(IAuthContext authConfig)
3737
.WithCertificate(string.IsNullOrEmpty(authConfig.CertificateThumbprint) ? GetCertificateByName(authConfig.CertificateName) : GetCertificateByThumbprint(authConfig.CertificateThumbprint))
3838
.Build();
3939

40-
ConfigureTokenCache(confidentialClientApp.AppTokenCache, authConfig.ClientId, Constants.AppCacheFileName);
40+
ConfigureTokenCache(confidentialClientApp.AppTokenCache, authConfig.ClientId);
4141
return new ClientCredentialProvider(confidentialClientApp);
4242
}
4343
}
@@ -50,7 +50,7 @@ internal static void Logout(IAuthContext authConfig)
5050
}
5151
}
5252

53-
private static void ConfigureTokenCache(ITokenCache tokenCache, string appId, string tokenCacheFile)
53+
private static void ConfigureTokenCache(ITokenCache tokenCache, string appId)
5454
{
5555
tokenCache.SetBeforeAccess((TokenCacheNotificationArgs args) => {
5656
lock (FileLock)

src/Authentication/Authentication/TokenCache/LinuxTokenCache.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ public static byte[] GetToken(string appId)
2424
type: LinuxNativeKeyUtils.KeyTypes.User,
2525
description: $"{Constants.TokenCahceServiceName}:{appId}",
2626
callout_info: IntPtr.Zero,
27-
dest_keyring: (int)LinuxNativeKeyUtils.KeyringType.KEY_SPEC_USER_SESSION_KEYRING);
27+
dest_keyring: (int)LinuxNativeKeyUtils.KeyringType.KEY_SPEC_SESSION_KEYRING);
2828

2929
if (key == -1)
3030
return new byte[0];
3131

3232
LinuxNativeKeyUtils.keyctl_read_alloc(
3333
key: key,
3434
buffer: out IntPtr contentPtr);
35-
string content = Marshal.PtrToStringAuto(contentPtr);
35+
string content = Marshal.PtrToStringAnsi(contentPtr);
3636
Marshal.FreeHGlobal(contentPtr);
3737

3838
if (string.IsNullOrEmpty(content))
@@ -55,15 +55,15 @@ public static void SetToken(string appId, byte[] plainContent)
5555
type: LinuxNativeKeyUtils.KeyTypes.User,
5656
description: $"{Constants.TokenCahceServiceName}:{appId}",
5757
callout_info: IntPtr.Zero,
58-
dest_keyring: (int)LinuxNativeKeyUtils.KeyringType.KEY_SPEC_USER_SESSION_KEYRING);
58+
dest_keyring: (int)LinuxNativeKeyUtils.KeyringType.KEY_SPEC_SESSION_KEYRING);
5959

6060
if (key == -1)
6161
LinuxNativeKeyUtils.add_key(
6262
type: LinuxNativeKeyUtils.KeyTypes.User,
6363
description: $"{Constants.TokenCahceServiceName}:{appId}",
6464
payload: encodedContent,
6565
plen: encodedContent.Length,
66-
keyring: (int)LinuxNativeKeyUtils.KeyringType.KEY_SPEC_USER_SESSION_KEYRING);
66+
keyring: (int)LinuxNativeKeyUtils.KeyringType.KEY_SPEC_SESSION_KEYRING);
6767
else
6868
LinuxNativeKeyUtils.keyctl_update(
6969
key: key,
@@ -82,7 +82,7 @@ public static void DeleteToken(string appId)
8282
type: LinuxNativeKeyUtils.KeyTypes.User,
8383
description: $"{Constants.TokenCahceServiceName}:{appId}",
8484
callout_info: IntPtr.Zero,
85-
dest_keyring: (int)LinuxNativeKeyUtils.KeyringType.KEY_SPEC_USER_SESSION_KEYRING);
85+
dest_keyring: (int)LinuxNativeKeyUtils.KeyringType.KEY_SPEC_SESSION_KEYRING);
8686
if (key != -1)
8787
{
8888
int removedState = LinuxNativeKeyUtils.keyctl_revoke(key);

0 commit comments

Comments
 (0)