Comment on page
Authentication
Access the Steam authentication system with Heathen's Steam API
Support us as a GitHub Sponsor and get instant access to all our assets, exclusive tools and assets, escalated support and issue tracking and our gratitude.
These articles are made possible by our GitHub Sponsors ... become a sponsor today!
using API = HeathenEngineering.SteamworksIntegration.API;
public static class API.Authentication
The Authentication API will use the Server or Client version of Valve's Steam API as required. It is not separated into a .Client or .Server version like other APIs as all features are exactly the same between them.
The Authentication has both client and server interfaces that are identical. Heathen's Steam API wrap's these in a single call which will call the appropriate client or server interface for you based on the build type in Unity.
The Authentication interface can be used to generate and validate session tickets. This is most commonly used with Steam Game Server but can also be used to for inventory verification or other similar verified processes.
public static List<AuthenticationTicket> ActiveTickets;
public static List<AuthenticationSession> ActiveSessions;
public static bool IsAuthTicketValid(AuthenticationTicket ticket);
Determines if the provided ticket handle is valid
public static string EncodedAuthTicket(AuthenticationTicket ticket);
Encodes a ticket to hex string format
This is most commonly used with web calls such as https://partner.steamgames.com/doc/webapi/ISteamUserAuth#AuthenticateUserTicket​
//Ticket for a Steam User or Steam Game Server
public static void GetAuthSessionTicket(CSteamID identity,
Action<AuthenticationTicket, bool> callback);
//Native use of Steam Networking Identity
public static void GetAuthSessionTicket(SteamNetworkingIdentity identity,
Action<AuthenticationTicket, bool> callback);
//Ticket for Steam Web API use
public static void GetAuthSessionTicket(string identity,
Action<AuthenticationTicket, bool> callback);
The callback delegate should be in the form of
void CallbackHandler(AuthenticationTicket result, bool IOError);
Requests a new Auth Session Ticket
public static void CancelAuthTicket(AuthenticationTicket ticket);
Cancels the auth ticket rather its client or server based.
public static EBeginAuthSessionResult BeginAuthSession(byte[] authTicket,
CSteamID user,
Action<AuthenticationSession> callback);
The callback deligate should be in the form of
void CallbackHandler(AuthenticationSession result);
Starts an authorization session with the indicated user given the applied auth ticket
public static void EndAuthSession(CSteamID user);
Ends the auth session with the indicated user if any
public static EUserHasLicenseForAppResult UserHasLicenseForApp(CSteamID user,
AppId_t appId);
Checks if the user owns a specific piece of Downloadable Content (DLC).
public static void EndAllSessions();
Ends all tracked sessions
public static void CancelAllTickets();
Cancels all tracked tickets
To authenticate the user who needs to be authenticated will first get a ticket and then send that data to the entity that will be doing the authentication ... so typically a client gets a ticket and sends it to a server.
API.Authentication.GetAuthSessionTicket(targetSteamId, (result, IOError) =>
{
if(!IOError)
{
//result.Data is your ticket data, use it well
}
});
The act of sending your ticket data to your server or the other client that wishes to authenticate you is up to your networking solution. Rather that is Mirror, MLAPI, Forge, etc. you will need to send the ticket.Data to that user.
Valve added a new parameter to the Get Authentication Ticket process where its necessary to identify who the ticket is intended for. The targetSteamId parameter is simply that the Steam ID of the user or Steam Game Server that will be using the ticket.
When ticket data is recieved you need to begin the auth session with that user and confirm the status of that session.
var result = API.Authentication.BeginAuthSession(ticket, user, (responce) =>
{
// responce is an AuthenticationSession
// You can use this value to understand the state of the session
});
​
if(result != EBeginAuthSessionResult.k_EBeginAuthSessionResultOK)
{
// The ticket is not valid,
// result is and enum of type EBeginAuthSessionResult
// its value indicates what is wrong
}
You can find details on the possible values for the EBeginAuthSessionResult result here:
Rather from the authenticated user or the authenticating system a session should be ended when its no longer needed.
To cancel a ticket you sent out
API.Authentication.CencelAuthTicket(ticket);
To cancel all tickets you sent out
API.Authentication.CancelAllTickets();
To end a session you started
API.Authentication.EndAuthSession(user);
To end all sessions you started
API.Authentication.EndAllSessions();
Your systems should maintain track of its tickets and sessions however the Authenticaitton API does keep a record of all active sessions and tickets.
Do not add or remove tickets or sessions manually
the API.Authentication.ActiveTickets and API.Authenticaiton.ActiveSessions lists can be used to iterate over the active tickets and sessions as required.
Last modified 4mo ago