Authentication
Browsing and installing free mods works for any player. Everything tied to a person needs the player signed in: subscriptions that follow them across devices, rating mods, creating and publishing their own mods, and owning and buying premium mods. If you turn on subscriptions in the prebuilt mod browser, installing needs a signed-in player too.
On PC and console, sign-in can be invisible. Your game passes the player's existing Steam, PlayStation Network, Xbox Live, GOG or Epic identity to CurseForge, and the player never types a password. A one-time code sent by email is the fallback for anyone a platform sign-in cannot cover.
Before a player's first sign-in, they must see CurseForge's terms and agree to them. The SDK fetches the current terms text from CurseForge, so wording changes reach your shipped game without a patch.
Once signed in, a player stays signed in between launches. On a device shared by several local players, each keeps their own sign-in.
For concepts, the provider list and Developer Portal setup, see Authentication overview.
What needs a session
These areas act for the signed-in player:
| Area | Covers |
|---|---|
ICFCore.Api.Authorized | Ratings, the player's own mods, subscriptions, premium ownership and purchases |
ICFCore.PremiumMods | Verified premium ownership |
ICFCore.Api.Creation | Creating and updating mods |
ICFCore.Creation | Creating, updating and uploading mods |
The SDK does not check for a session before sending these calls. Without one, the request still goes out and fails. Check IsAuthenticated before you offer any of these features.
Method reference
All of these are on ICFCore.Authentication, and none needs an existing session.
| Member | What it does |
|---|---|
IsAuthenticated | true when a session token is stored for the current player |
AuthenticatedUser | The signed-in player's profile, a Me, or null |
GetTerms | Fetches the current terms text |
SendSecurityCode | Emails the player a one-time code |
GenerateAuthToken | Signs in with the email and the code |
GenerateAuthTokenByExternalProvider | Signs in with a platform token |
Logout | Signs the player out on this device |
Failure delegates receive a CFCoreError. A failure from the server sets ErrorCode to ApiError and carries the server's ApiResponseError. See Error handling.
Terms and consent
Signing in creates or uses a CurseForge account, so the player must see CurseForge's terms and agree before your game calls a sign-in method.
The core API has no call that records acceptance. Your game shows the terms, keeps the moment the player agreed, and passes that time with a platform sign-in. The player's profile reports when they last agreed, in Me.EulaLastAgreed.
How it works
- Call
GetTerms. It needs no session. - Render the text, both button labels and the links from the returned
Terms. - If the player declines, stop. Do not sign them in.
- If the player agrees, record
DateTime.UtcNowand start sign-in. - For a returning player, compare
Terms.updateDatewithMe.EulaLastAgreed, and show the terms again when they have changed since the player last agreed.
The terms are fetched in the language set in Settings.Language, en by default.
using Overwolf.CFCore.Base;
using Overwolf.CFCore.Base.Api.Common;
using Overwolf.CFCore.Base.Api.Models.Terms;
using Overwolf.CFCore.Base.Common;
using UnityEngine;
public class TermsScreen : MonoBehaviour {
private ICFCore _core;
public void Show(ICFCore core) {
_core = core;
_core.Authentication.GetTerms(
(ApiResponse<Terms> response) => {
Terms terms = response.Data;
TermsContent content = terms.content;
Debug.Log(content.PlainText);
Debug.Log($"{content.Buttons.Agree.Text} / {content.Buttons.Disagree.Text}");
Debug.Log($"{content.links.Terms.Text}: {content.links.Terms.Url}");
},
(CFCoreError error) => {
// Do not sign the player in without showing the terms.
Debug.LogError($"Could not load terms: {error.Description}");
});
}
}
Prebuilt UI: CFUnity.EulaTerms holds the terms CFUnity fetched at startup, and CFUnity.AcceptEula records the player's agreement. See Signing in with CFUnity below.
The terms model
Some members of the terms model start with a lowercase letter. Use them exactly as listed.
| Member | Type | What it holds |
|---|---|---|
Terms.updateDate | DateTime | When the terms last changed |
Terms.content | TermsContent | The text, buttons and links |
TermsContent.Language | string | The language of the returned text |
TermsContent.PlainText | string | The terms as plain text |
TermsContent.Html | string | The same terms as HTML |
TermsContent.Buttons | TermsButtons | The agree and disagree buttons |
TermsContent.links | TermsLinks | The website, terms and privacy links |
TermsButtons holds Agree and Disagree, each a TermsButton with one field, Text. Use the labels as they come. TermsLinks holds Website, Terms and Privacy, each a TermsLink with three fields:
| Field | Type | What it holds |
|---|---|---|
Text | string | The link label |
Url | string | The address to open |
Required | bool | When true, show the link on the terms screen. The SDK does not enforce this |
PlainText and Html are two renderings of one document. Show whichever your interface can render.
Email one-time code sign-in
Two calls with a step for the player in between.
How it works
- Collect the player's email address and call
SendSecurityCode. - CurseForge emails the player a code. Show a field for it.
- Call
GenerateAuthTokenwith the same email address and the code as along. - On success, the session is stored and your success delegate runs.
Your success delegate also runs when the session could not be written to disk, and when the profile request that follows sign-in fails. If that profile request reports the session expired, the session is erased before your delegate runs. Check IsAuthenticated inside the delegate before relying on the session.
Both GenerateAuthToken and GenerateAuthTokenByExternalProvider clear any stored session before they send their request. A signed-in player who enters a wrong code for another account ends up signed out.
using Overwolf.CFCore.Base;
using Overwolf.CFCore.Base.Api.Common;
using Overwolf.CFCore.Base.Common;
using UnityEngine;
public class EmailSignIn : MonoBehaviour {
private ICFCore _core;
private string _email;
public void SendCode(ICFCore core, string email) {
_core = core;
_email = email;
_core.Authentication.SendSecurityCode(
_email,
() => Debug.Log("Code sent. Ask the player to enter it."),
(CFCoreError error) => Debug.LogError(error.Description));
}
public void SubmitCode(string codeText) {
if (!long.TryParse(codeText, out long code)) {
Debug.LogWarning("The code must be a number.");
return;
}
_core.Authentication.GenerateAuthToken(
_email,
code,
() => Debug.Log($"Signed in as {_core.Authentication.AuthenticatedUser?.DisplayName}"),
(CFCoreError error) => {
ApiResponseError api = error.ApiError;
if (api != null && (api.BadRequest || api.ResourceExpired)) {
Debug.LogWarning("That code was not accepted. Request a new one.");
return;
}
Debug.LogError(error.Description);
});
}
}
Prebuilt UI: CFUnity.SendSecurityCode, then CFUnity.TryAuthenticateWithEmail.
External provider sign-in
Your game gets a token from the platform's own SDK and passes it to CurseForge with the provider it came from. Pick the provider for each build target in your own code.
AuthExternalProviders value | Platform | What to pass as the token |
|---|---|---|
Steam | Steam | A base64 representation of a session ticket from ISteamUser::GetAuthSessionTicket |
PSN | PlayStation Network | An access token obtained with an authorization code |
XBL | Xbox Live | An access token obtained with an XSTS token |
GOG | GOG Galaxy | A base64 representation of the raw ticket bytes from an encrypted app ticket request |
Epic | Epic Games | The JWT returned by the EOS SDK function EOS_Auth_CopyIdToken |
GOG sign-in also needs the Encrypted App Ticket Key configured in your game's Authentication section in the Developer Portal at console.curseforge.com. The GOG ticket comes from galaxy::api::User()->RequestEncryptedAppTicket().
Every provider takes the same AuthExternalAdditionalInfo:
| Field | Type | Default | What it does |
|---|---|---|---|
EulaAcceptTime | DateTime | The time the object was created | When the player agreed to the terms |
Environment | string | Empty | PSN only. The PSN environment, listed below |
For PSN, Environment is optional and takes dev, qa or prod. Leave it empty for every other provider.
Set EulaAcceptTime to the moment the player agreed. Its default is the time you created the object, which reports an agreement whether or not the player saw the terms.
How it works
- Show the terms and record the acceptance time, unless the player already agreed to the current terms.
- Get the platform token in the form listed above. The SDK does not inspect it, so a token in the wrong form fails on the server.
- Fill an
AuthExternalAdditionalInfo. - Call
GenerateAuthTokenByExternalProvider. - On failure, offer the email one-time code rather than leaving the player without a session.
using System;
using Overwolf.CFCore.Base;
using Overwolf.CFCore.Base.Api.Models;
using Overwolf.CFCore.Base.Api.Models.Enums;
using Overwolf.CFCore.Base.Common;
using UnityEngine;
public class PlatformSignIn : MonoBehaviour {
public void SignIn(ICFCore core, string platformToken, DateTime termsAcceptedAt) {
AuthExternalAdditionalInfo info = new AuthExternalAdditionalInfo {
EulaAcceptTime = termsAcceptedAt
};
core.Authentication.GenerateAuthTokenByExternalProvider(
AuthExternalProviders.Steam,
platformToken,
info,
() => Debug.Log("Signed in"),
(CFCoreError error) => {
Debug.LogWarning($"Platform sign-in failed: {error.Description}");
// Offer the email one-time code here.
});
}
}
Prebuilt UI: CFUnity.TryAuthenticateWithToken, which reads the provider and token from the function you pass to CFUnity.Initialize.
Checking, persisting and ending the session
Checking the session
IsAuthenticated is a property, not a call. It is true whenever a session token is stored for the current player, and it never contacts the server.
AuthenticatedUser holds the player's profile. It is filled in two places: when the SDK starts with a stored session, and after a successful sign-in, before your success delegate runs. If the profile request fails, AuthenticatedUser stays null while IsAuthenticated can still be true, for example when the player starts your game offline.
Field of Me | Type | What it holds |
|---|---|---|
Id | uint | The player's CurseForge user id |
Username | string | The account username |
DisplayName | string | The name to show |
Email | string | The account email. Treat it as personal data |
AvatarUrl | string | The player's avatar image |
DateCreated | DateTime | When the account was created |
EulaLastAgreed | DateTime | When the player last agreed to the terms |
How long a session lasts
When the SDK initializes with a stored session, it checks the session with the server. If the server reports the session expired, the SDK erases it and initialization still succeeds. Check IsAuthenticated after initialization.
Later in the run, a call that fails with TokenExpired does not erase the stored session, and IsAuthenticated stays true. When you receive TokenExpired, sign the player in again.
Where the session is kept
The session is stored per user context id, in the user data directory under <game id>/<context id>. Two players on one device who start the game with different context ids keep separate sessions. See Initialization and settings.
Choose the context id before the first Initialize. Calling Initialize again with a different context id reloads only the player's saved state, and when the new context has no saved state yet, the previous player's session stays loaded. CFUnity always uses the same context id, so with CFUnity every player on a device shares one session.
On Windows builds and in the Windows editor, the stored token is encrypted for the operating system user. A session file copied from another machine or another Windows user cannot be read, and the player is signed out. If encryption fails, the token is stored as is. On other platforms the token is stored as is, so keep the user data directory out of crash reports and shared folders.
Signing out
Logout clears the session on this device and runs its delegate at once. It sends no request to CurseForge. You do not need to call it before signing a different player in, because both sign-in methods clear the stored session first.
core.Authentication.Logout(() => Debug.Log("Signed out"));
Signing in with CFUnity
CFUnity wraps the same calls and adds terms tracking, so games using the prebuilt browser write very little sign-in code.
How it works
- Pass a function to
CFUnity.Initializethat returns aTask<CFUnity.AuthRequestData>, holding aProviderand aToken.CFUnitycalls it each time it signs the player in, and whenCFUnity.Premiumstarts a checkout. - On startup,
CFUnityfetches the terms intoCFUnity.EulaTermsand setsCFUnity.EulaAccepted. Your success delegate runs only after the terms arrive. If they cannot be fetched, for example while offline, your error delegate runs instead. - If
EulaAcceptedisfalse, show the terms and callCFUnity.AcceptEulawhen the player agrees. - Call
CFUnity.TryAuthenticateWithToken. It calls your function and signs in with the result, passing the recorded acceptance time. - If platform sign-in fails, use
CFUnity.SendSecurityCodeandCFUnity.TryAuthenticateWithEmailas the fallback.
using System.Threading.Tasks;
using Overwolf.CFCore.Base.Api.Models.Enums;
using Overwolf.CFCore.Unity;
using UnityEngine;
public class CFUnitySignIn : MonoBehaviour {
[SerializeField] private CurseForgeSettings _settings;
private void Start() {
CFUnity.Initialize(_settings, GetAuthData, OnReady, OnError);
}
private Task<CFUnity.AuthRequestData> GetAuthData() {
CFUnity.AuthRequestData data = new CFUnity.AuthRequestData {
Provider = AuthExternalProviders.Steam,
Token = GetPlatformToken()
};
return Task.FromResult(data);
}
private void OnReady() {
if (!CFUnity.EulaAccepted) {
// Show CFUnity.EulaTerms first, then call AcceptAndSignIn on agree.
return;
}
SignIn();
}
public void AcceptAndSignIn() {
CFUnity.AcceptEula(SignIn, error => Debug.LogError(error));
}
private void SignIn() {
CFUnity.TryAuthenticateWithToken(
() => Debug.Log("Signed in"),
error => Debug.LogWarning($"Sign-in failed: {error}"));
}
private void OnError(string error) {
Debug.LogError(error);
}
private string GetPlatformToken() {
// Return the token from your platform's SDK.
return string.Empty;
}
}
CFUnity members for sign-in
| Member | What it does |
|---|---|
IsAuthenticated | Whether a session is stored |
IsAuthenticating | Whether a sign-in started through CFUnity is in progress |
AuthenticatedUser | The player's profile, or null |
EulaTerms | The terms fetched at startup |
EulaAccepted | Whether the player agreed to the current terms on this device |
GetTerms | Fetches the terms again, without updating EulaTerms |
AcceptEula | Records that the player agreed, as of now |
TryAuthenticateWithToken | Signs in through your auth data function |
SendSecurityCode | Emails a code and remembers the address |
TryAuthenticateWithEmail | Signs in with the code, using the remembered address |
CFUnity keeps the acceptance time in Unity's PlayerPrefs, so it applies to everyone who plays on the device, not to one user context id. EulaAccepted is true when that time is on or after Terms.updateDate.
TryAuthenticateWithToken does not check EulaAccepted itself. Make sure the player has agreed before you call it.
If the player is already signed in, TryAuthenticateWithEmail does not call your success delegate. Check CFUnity.IsAuthenticated before you show the email screen.
CFUnity has no sign-out, and both of its sign-in methods do nothing new while a session is stored. A session that expires during a run stays stored until the next launch, when the startup check clears it.
Authentication events
| Event | When it fires |
|---|---|
CFUnity.OnAuthenticationSuccess | After a sign-in through CFUnity, after the player accepts the terms while signed in, and at startup when a stored session exists and the current terms are accepted |
CFUnity.OnAuthenticationError | When the server rejects a TryAuthenticateWithToken sign-in. See below |
A sign-in through ICFCore.Authentication does not raise these events. TryAuthenticateWithToken called while a session is stored does not raise OnAuthenticationSuccess. When your auth data function throws, and for email sign-in failures, only the error delegate you passed runs.
After OnAuthenticationSuccess fires, CFUnity removes every handler from both events. Subscribe again if your game needs to hear about a later sign-in.
After every successful sign-in, CFUnity also loads the player's ratings, their owned premium mods and their own mods. With Use Subscriptions on, it fetches the player's subscriptions and raises CFUnity.OnModsToSyncReceived when they differ from the installed mods. See Subscriptions.
What the prebuilt browser does
When a player opens the browser, it shows the terms if they are not accepted, then calls TryAuthenticateWithToken. If that fails and Allow Email Auth is on, the browser opens its email code page. Otherwise it shows the error with a retry button. See Mod browser.
Error signals
| Signal | What it means |
|---|---|
ApiError.BadRequest | The server answered 400 and rejected the input |
ApiError.TokenExpired | The server answered 401. The session is no longer valid. Sign the player in again |
ApiError.ResourceExpired | The server answered 410. The resource expired |
ApiError.ServerUnreachable | The server answered 500, 502, 503 or 504. Retry later |
ApiError.MissingPriviliges | The server answered 403. See below |
MissingPriviliges covers a request without a session as well as a session or API key without the privilege the call needs.
Getting help
Provider setup, including the GOG Encrypted App Ticket Key, is in the Authentication section of your game in the Developer Portal at console.curseforge.com. For a provider that is not listed here, contact cfforstudios@overwolf.com.