Added RequestEncryptedAppTicketAsync

This commit is contained in:
Garry Newman 2019-05-07 20:21:06 +01:00
parent 503d8964ea
commit a020474856
2 changed files with 83 additions and 0 deletions

View File

@ -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" ) ) )}" );
}
}
}

View File

@ -338,5 +338,68 @@ public static async Task<string> GetStoreAuthUrlAsync( string url )
/// </summary>
public static bool IsPhoneRequiringVerification => Internal.BIsPhoneRequiringVerification();
/// <summary>
/// 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/
/// </summary>
public static async Task<byte[]> 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 );
}
}
/// <summary>
/// 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/
/// </summary>
public static async Task<byte[]> 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;
}
}
}