diff --git a/Facepunch.Steamworks.Test/UserTest.cs b/Facepunch.Steamworks.Test/UserTest.cs index 106c061..2b5a4f3 100644 --- a/Facepunch.Steamworks.Test/UserTest.cs +++ b/Facepunch.Steamworks.Test/UserTest.cs @@ -114,6 +114,26 @@ public void IsPhoneRequiringVerification() { Console.WriteLine( $"User.IsPhoneRequiringVerification: {SteamUser.IsPhoneRequiringVerification}" ); } + + + [TestMethod] + public async Task RequestEncryptedAppTicketAsyncWithData() + { + var data = await SteamUser.RequestEncryptedAppTicketAsync( new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 } ); + Assert.IsNotNull( data ); + + Console.WriteLine( $"data: {string.Join( "", data.Select( x => x.ToString( "x" ) ))}" ); + } + + [TestMethod] + public async Task RequestEncryptedAppTicketAsync() + { + var data = await SteamUser.RequestEncryptedAppTicketAsync(); + Assert.IsNotNull( data ); + + Console.WriteLine( $"data: {string.Join( "", data.Select( x => x.ToString( "x" ) ) )}" ); + } + } } diff --git a/Facepunch.Steamworks/SteamUser.cs b/Facepunch.Steamworks/SteamUser.cs index 5f43cfd..b30c3b5 100644 --- a/Facepunch.Steamworks/SteamUser.cs +++ b/Facepunch.Steamworks/SteamUser.cs @@ -338,5 +338,68 @@ public static async Task GetStoreAuthUrlAsync( string url ) /// public static bool IsPhoneRequiringVerification => Internal.BIsPhoneRequiringVerification(); + /// + /// Requests an application ticket encrypted with the secret "encrypted app ticket key". + /// The encryption key can be obtained from the Encrypted App Ticket Key page on the App Admin for your app. + /// There can only be one call pending, and this call is subject to a 60 second rate limit. + /// This can fail if you don't have an encrypted ticket set for your app here https://partner.steamgames.com/apps/sdkauth/ + /// + public static async Task RequestEncryptedAppTicketAsync( byte[] dataToInclude ) + { + var dataPtr = Marshal.AllocHGlobal( dataToInclude.Length ); + Marshal.Copy( dataToInclude, 0, dataPtr, dataToInclude.Length ); + + try + { + var result = await Internal.RequestEncryptedAppTicket( dataPtr, dataToInclude.Length ); + if ( !result.HasValue || result.Value.Result != Result.OK ) return null; + + var ticketData = Marshal.AllocHGlobal( 1024 ); + uint outSize = 0; + byte[] data = null; + + if ( Internal.GetEncryptedAppTicket( ticketData, 1024, ref outSize ) ) + { + data = new byte[outSize]; + Marshal.Copy( ticketData, data, 0, (int) outSize ); + } + + Marshal.FreeHGlobal( ticketData ); + + return data; + } + finally + { + Marshal.FreeHGlobal( dataPtr ); + } + } + + /// + /// Requests an application ticket encrypted with the secret "encrypted app ticket key". + /// The encryption key can be obtained from the Encrypted App Ticket Key page on the App Admin for your app. + /// There can only be one call pending, and this call is subject to a 60 second rate limit. + /// This can fail if you don't have an encrypted ticket set for your app here https://partner.steamgames.com/apps/sdkauth/ + /// + public static async Task RequestEncryptedAppTicketAsync() + { + var result = await Internal.RequestEncryptedAppTicket( IntPtr.Zero, 0 ); + if ( !result.HasValue || result.Value.Result != Result.OK ) return null; + + var ticketData = Marshal.AllocHGlobal( 1024 ); + uint outSize = 0; + byte[] data = null; + + if ( Internal.GetEncryptedAppTicket( ticketData, 1024, ref outSize ) ) + { + data = new byte[outSize]; + Marshal.Copy( ticketData, data, 0, (int)outSize ); + } + + Marshal.FreeHGlobal( ticketData ); + + return data; + + } + } } \ No newline at end of file