GameService.Sdk.Auth
1.0.5
dotnet add package GameService.Sdk.Auth --version 1.0.5
NuGet\Install-Package GameService.Sdk.Auth -Version 1.0.5
<PackageReference Include="GameService.Sdk.Auth" Version="1.0.5" />
<PackageVersion Include="GameService.Sdk.Auth" Version="1.0.5" />
<PackageReference Include="GameService.Sdk.Auth" />
paket add GameService.Sdk.Auth --version 1.0.5
#r "nuget: GameService.Sdk.Auth, 1.0.5"
#:package GameService.Sdk.Auth@1.0.5
#addin nuget:?package=GameService.Sdk.Auth&version=1.0.5
#tool nuget:?package=GameService.Sdk.Auth&version=1.0.5
GameService Auth SDK
The Auth SDK handles user authentication, session management, and basic player profile operations (balance, daily rewards). It is the entry point for any application connecting to the GameService.
Installation
Include GameService.Sdk.Auth.dll and its dependencies in your project.
Usage
1. Initialize the Client
using GameService.Sdk.Auth;
var authClient = new AuthClient("http://localhost:5525");
2. Login or Register
Guest Login
Quickly create a temporary account.
var result = await authClient.GuestLoginAsync();
if (result.Success)
{
Console.WriteLine($"Logged in as guest!");
var session = result.Session;
}
Email/Password Login
var result = await authClient.LoginAsync("user@example.com", "password123");
Register
var result = await authClient.RegisterAsync("user@example.com", "password123");
if (result.Success)
{
// Now login
}
3. Managing the Session
The LoginResult returns a GameSession object which manages your access tokens and provides access to authenticated
features.
var session = result.Session;
// Check balance
var balance = await session.GetBalanceAsync();
// Get Profile
var profile = await session.GetProfileAsync();
Console.WriteLine($"User: {profile.UserName}, Coins: {profile.Coins}");
// Claim Daily Rewards
var claim = await session.ClaimDailyLoginAsync();
if (claim.Success)
{
Console.WriteLine($"Claimed {claim.Reward} coins!");
}
4. Connecting to Game Server
The session provides a helper to connect to the real-time game hub.
var gameClient = await session.ConnectToGameAsync();
5. Token Refresh
The GameSession automatically handles token expiration and refreshing when you use its methods or
ConnectToGameAsync.
Get Started with Unity
The Auth SDK handles user authentication and profile management.
Key Classes
AuthClient: Authentication operationsGameSession: User session with token managementPlayerProfile: User profile data
Authentication Flow
using GameService.Sdk.Auth;
public class AuthManager : MonoBehaviour
{
private AuthClient authClient;
private GameSession session;
private void Start()
{
authClient = new AuthClient("https://your-server.com");
}
// Guest login (no registration required)
public async Task<bool> LoginAsGuest()
{
var result = await authClient.GuestLoginAsync();
if (result.Success)
{
session = result.Session;
Debug.Log("Guest login successful!");
return true;
}
Debug.LogError($"Guest login failed: {result.Error}");
return false;
}
// Email/password registration
public async Task<bool> Register(string email, string password)
{
var result = await authClient.RegisterAsync(email, password);
if (result.Success)
{
Debug.Log("Registration successful!");
return await Login(email, password);
}
Debug.LogError($"Registration failed: {result.Error}");
return false;
}
// Email/password login
public async Task<bool> Login(string email, string password)
{
var result = await authClient.LoginAsync(email, password);
if (result.Success)
{
session = result.Session;
Debug.Log("Login successful!");
return true;
}
Debug.LogError($"Login failed: {result.Error}");
return false;
}
// Google OAuth login
public async Task<bool> LoginWithGoogle(string idToken)
{
var result = await authClient.GoogleLoginAsync(idToken);
if (result.Success)
{
session = result.Session;
Debug.Log("Google login successful!");
return true;
}
Debug.LogError($"Google login failed: {result.Error}");
return false;
}
}
Profile Management
// Get user profile
var profile = await session.GetProfileAsync();
if (profile != null)
{
Debug.Log($"User: {profile.UserName}");
Debug.Log($"Email: {profile.Email}");
Debug.Log($"Coins: {profile.Coins}");
}
// Get coin balance
var balance = await session.GetBalanceAsync();
Debug.Log($"Balance: {balance} coins");
// Daily rewards
var loginReward = await session.ClaimDailyLoginAsync();
if (loginReward.Success)
{
Debug.Log($"Daily login: +{loginReward.Reward} coins!");
Debug.Log($"New balance: {loginReward.NewBalance}");
}
var spinReward = await session.ClaimDailySpinAsync();
if (spinReward.Success)
{
Debug.Log($"Daily spin: +{spinReward.Reward} coins!");
}
// Transaction history
var history = await session.GetTransactionHistoryAsync(page: 1, pageSize: 20);
foreach (var transaction in history.Items)
{
Debug.Log($"{transaction.CreatedAt}: {transaction.Amount} coins - {transaction.Description}");
}
Session to GameClient
// Connect to game hub using session
var gameClient = await session.ConnectToGameAsync();
// The session automatically handles token refresh
Debug.Log($"Connected with token: {session.AccessToken}");
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- GameService.Sdk.Core (>= 1.0.5)
- Newtonsoft.Json (>= 13.0.4)
-
net8.0
- GameService.Sdk.Core (>= 1.0.5)
- Newtonsoft.Json (>= 13.0.4)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on GameService.Sdk.Auth:
| Package | Downloads |
|---|---|
|
Project01.Practice
A basic SignalR Chat Hub and client assets. |
GitHub repositories
This package is not used by any popular GitHub repositories.