Skip to main content

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:

AreaCovers
ICFCore.Api.AuthorizedRatings, the player's own mods, subscriptions, premium ownership and purchases
ICFCore.PremiumModsVerified premium ownership
ICFCore.Api.CreationCreating and updating mods
ICFCore.CreationCreating, 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.

MemberWhat it does
IsAuthenticatedtrue when a session token is stored for the current player
AuthenticatedUserThe signed-in player's profile, a Me, or null
GetTermsFetches the current terms text
SendSecurityCodeEmails the player a one-time code
GenerateAuthTokenSigns in with the email and the code
GenerateAuthTokenByExternalProviderSigns in with a platform token
LogoutSigns 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.

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

  1. Call GetTerms. It needs no session.
  2. Render the text, both button labels and the links from the returned Terms.
  3. If the player declines, stop. Do not sign them in.
  4. If the player agrees, record DateTime.UtcNow and start sign-in.
  5. For a returning player, compare Terms.updateDate with Me.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.

MemberTypeWhat it holds
Terms.updateDateDateTimeWhen the terms last changed
Terms.contentTermsContentThe text, buttons and links
TermsContent.LanguagestringThe language of the returned text
TermsContent.PlainTextstringThe terms as plain text
TermsContent.HtmlstringThe same terms as HTML
TermsContent.ButtonsTermsButtonsThe agree and disagree buttons
TermsContent.linksTermsLinksThe 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:

FieldTypeWhat it holds
TextstringThe link label
UrlstringThe address to open
RequiredboolWhen 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

  1. Collect the player's email address and call SendSecurityCode.
  2. CurseForge emails the player a code. Show a field for it.
  3. Call GenerateAuthToken with the same email address and the code as a long.
  4. 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 valuePlatformWhat to pass as the token
SteamSteamA base64 representation of a session ticket from ISteamUser::GetAuthSessionTicket
PSNPlayStation NetworkAn access token obtained with an authorization code
XBLXbox LiveAn access token obtained with an XSTS token
GOGGOG GalaxyA base64 representation of the raw ticket bytes from an encrypted app ticket request
EpicEpic GamesThe 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:

FieldTypeDefaultWhat it does
EulaAcceptTimeDateTimeThe time the object was createdWhen the player agreed to the terms
EnvironmentstringEmptyPSN only. The PSN environment, listed below

For PSN, Environment is optional and takes dev, qa or prod. Leave it empty for every other provider.

warning

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

  1. Show the terms and record the acceptance time, unless the player already agreed to the current terms.
  2. 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.
  3. Fill an AuthExternalAdditionalInfo.
  4. Call GenerateAuthTokenByExternalProvider.
  5. 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 MeTypeWhat it holds
IduintThe player's CurseForge user id
UsernamestringThe account username
DisplayNamestringThe name to show
EmailstringThe account email. Treat it as personal data
AvatarUrlstringThe player's avatar image
DateCreatedDateTimeWhen the account was created
EulaLastAgreedDateTimeWhen 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

  1. Pass a function to CFUnity.Initialize that returns a Task<CFUnity.AuthRequestData>, holding a Provider and a Token. CFUnity calls it each time it signs the player in, and when CFUnity.Premium starts a checkout.
  2. On startup, CFUnity fetches the terms into CFUnity.EulaTerms and sets CFUnity.EulaAccepted. Your success delegate runs only after the terms arrive. If they cannot be fetched, for example while offline, your error delegate runs instead.
  3. If EulaAccepted is false, show the terms and call CFUnity.AcceptEula when the player agrees.
  4. Call CFUnity.TryAuthenticateWithToken. It calls your function and signs in with the result, passing the recorded acceptance time.
  5. If platform sign-in fails, use CFUnity.SendSecurityCode and CFUnity.TryAuthenticateWithEmail as 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​

MemberWhat it does
IsAuthenticatedWhether a session is stored
IsAuthenticatingWhether a sign-in started through CFUnity is in progress
AuthenticatedUserThe player's profile, or null
EulaTermsThe terms fetched at startup
EulaAcceptedWhether the player agreed to the current terms on this device
GetTermsFetches the terms again, without updating EulaTerms
AcceptEulaRecords that the player agreed, as of now
TryAuthenticateWithTokenSigns in through your auth data function
SendSecurityCodeEmails a code and remembers the address
TryAuthenticateWithEmailSigns 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.

warning

TryAuthenticateWithToken does not check EulaAccepted itself. Make sure the player has agreed before you call it.

note

If the player is already signed in, TryAuthenticateWithEmail does not call your success delegate. Check CFUnity.IsAuthenticated before you show the email screen.

warning

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​

EventWhen it fires
CFUnity.OnAuthenticationSuccessAfter 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.OnAuthenticationErrorWhen 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.

warning

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​

SignalWhat it means
ApiError.BadRequestThe server answered 400 and rejected the input
ApiError.TokenExpiredThe server answered 401. The session is no longer valid. Sign the player in again
ApiError.ResourceExpiredThe server answered 410. The resource expired
ApiError.ServerUnreachableThe server answered 500, 502, 503 or 504. Retry later
ApiError.MissingPriviligesThe 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.