MyGames🔗

Login with MyGames makes it easier for users to log into your applications. Thanks to the single brand under which MY.GAMES games are released, now you can easily authorize a user using a platform that is understandable to him. Moreover, registration of a new user in MY.GAMES can be done through other social networks, such as Facebook, VK, Google, so the user can have a single entry point in the form of MY.GAMES authorization.
Important
Below in the sections of preliminary configuration and configuration of MRGS parameters everything is described for iOS and Android, if you are interested in working with MY.GAMES authorization on a desktop, refer to section below.
Presetting🔗
Obtaining keys and required data🔗
Before starting work, Need to get some data and register the application in MY.GAMES system. For each platform, need to receive:
- Client ID - unique application identifier in MY.GAMES authorization system
In order to register the application in the system and receive the above data, need to go to MRGS site, go to the editing window of your application, select the "Integrations" section, and find the "My.Games" section, in which there will be a "Create Project" button.

After clicking, the project will be created in MY.GAMES system, and the ClientID and ClientSecret values are displayed. The client only needs the received ClientID, and you can use the ClientSecret on your server to interact with MY.GAMES.

Using the same project for all platforms
At the moment, with the standard approach for each application in the MRGS system (mrgs appId), you need to create a new application in MY.GAMES by pressing the button (described above), so in the end for each application you will have your own MyGames clientId/secret pair, which is not always convenient and logical. You can use one application (MyGames clientId/secret pair) for all platforms, for this you need to create a task for the MRGS project, specify the MRGS appId list, and the previously obtained MyGames clientId/secret pair (interface for adding of this data manually is under development, so far it is possible only through a task), and we will add it to all the specified applications.
Using Previously Created Projects
If you already have a registered project in MY.GAMES system and want to use it for authorization, you need to add the keys to the MRGS website. To do this, you need to create a task for the MRGS project, specify MRGS appId, Sezam ClientId, Sezam Secret (the interface for adding this data manually is under development, so far it is possible only through a task). Please note that ClientId and Secret are required from the Sezam authorization system, they are not equal to MyGamesID/MyGames AppID (GMRID) and so on. To get Sezam ClientId, Sezam Secret, you need to contact your colleagues from MY.GAMES (the interface for displaying this data on MY.GAMES developer site is under development, check with colleagues from MY.GAMES about the status)
Project setup🔗
In order for the authorization to work correctly, need to add some changes to the project:
For Unity
For iOS:
Add a new url scheme to open the app from the outside in the Info.plist of the app. Add a new application opening scheme so that the browser can bring the user back to your application. The schema to add looks like this: mygms-<BUNDLE_ID>, where BUNDLE_ID is the package ID (for example, if BUNDE_ID is games.my.mrgs.testapp, then the schema will look like mygms-games.my.mrgs.testapp). Details about adding URL schemes in the generated project are written in this article, but Unity has an easier method for adding data to the application plist. To do this, add the code to the Unity post build process:
[PostProcessBuild]
public static void PostProcessBuild(BuildTarget target, string path)
{
string plistPath = path + "/Info.plist";
PlistDocument plist = new PlistDocument();
plist.ReadFromString(File.ReadAllText(plistPath));
PlistElementDict rootDict = plist.root;
// Adding a URL Scheme
PlistElementArray appSchemes = rootDict.CreateArray("CFBundleURLTypes");
PlistElementDict appSchemesDict = appSchemes.AddDict();
appSchemesDict.SetString("CFBundleURLName", "");
PlistElementArray appSchemesArray = appSchemesDict.CreateArray("CFBundleURLSchemes");
appSchemesArray.AddString("<YOUR_NEW_SCHEME>"); // Where YOUR_NEW_SCHEME is the new schema of your application, e.g. mygms-mrgs.test.app
File.WriteAllText(plistPath, plist.WriteToString());
}
Or modify the existing code for adding properties in the Info.plist of the application, if you have one.
For iOS
Add a new url scheme to open the app from the outside in the Info.plist of the app. Add a new application opening scheme so that the browser can bring the user back to your application. The schema to add looks like this: mygms-<BUNDLE_ID>, where BUNDLE_ID is the package ID (for example, if BUNDE_ID is games.my.mrgs.testapp, then the schema will look like mygms-games.my.mrgs.testapp). Details about adding URL schemes in the generated project are written in this article.
Via UI:
To add a URL scheme, you need:
- Go to the Info.plist of your application
- Add the line "URL types"
- Expand the first item ("Item0"), add the line "URL identifier" and add a value with your app ID (for example, com.company.appname).
- Add a line to the first item ("item0") in "URL types" and name it "URL Schemes" and add a new item (desired URL scheme) to "URL Schemes"
As a result, you get the following structure:

As XML:
Add the following data to your Info.plist:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>YOUR_NEW_SCHEME</string>
</array>
</dict>
</array>
Note: for URL schemes, if you already have such a structure in a plist with other schemes, then you can simply add one more element to the schemes array (CFBundleURLSchemes)
Add dependencies🔗
Add the MRGS SDK to the project:
Unity:
Adding to the project (general instruction)
Step 1. Add Sources
To add MRGS to a project via the Unity Package Manager (available from Unity 2018+) simply add a scopedRegistries section to the Packages/manifest.json file by adding the following entry:
{
"dependencies": {
...
},
"scopedRegistries": [
{
"name": "MRGS",
"url": "https://mrgs-nexus.my.games/repository/mrgs-uninty-plugins/",
"scopes": [
"games.my.mrgs"
]
}
]
}
Alternatively, you can click Edit -> Project Settings -> Package Manager -> '+' in scoped registry section, and fill in the fields according to the data above.
Step 2. Add dependency
- Click
Window -> Package Manager -> select 'Packages: MyRegistries' from dropdown list, select packageMRGSAuthenticationfrom the list, then click "Install" - Import the module:
using MRGS;
- Download the latest version of the library. Unzip the archive.
- (For unitypackage integration) In Unity, click
Assets -> Import Package -> Custom Package, and select thegames.my.mrgs.authentication.unitypackagepackage from the downloaded archive. - (For tgz integration) In Unity, click
Window -> Package Manager -> '+' -> Add package from tarball, and select thegames.my.mrgs.authentication-<version> package. tgzfrom the downloaded archive. - Import the module:
using MRGS;
iOS:
Adding to the project (general instruction)
Step 1: Add dependencies
Via Package collection
- In Xcode select File > Add Packages
- Select "+" > "Add Swift Package Collection"
- Insert URL:
https://mrgs-nexus.my.games/repository/ios-sdks/MRGSPackageCollection.json - Select module MRGSAuthentication from "MRGS Package Collection".
- Or you can select "MRGS" package from "MRGS Package Collection" (contains all mrgs modules as products) and then select "MRGS/Authentication" product only.
Individual packages
- In Xcode select File > Add Packages
- In the search bar at the top right, paste the URL:
https://mrgs-gitea.my.games/mrgs/mrgsauthentication-ios-sdk.git - Add a module to your project
- Or you can paste the url
https://mrgs-gitea.my.games/mrgs/ios-sdks.gitto include the "MRGS" package which contains all mrgs modules as products and then select only the product" MRGS/Authentication".
Step 2: Add support for ObjectiveC categories
- Set the
-ObjCflag in the "Other linker Flags" field in the project settings. - Import the module in code:
@import MRGServiceKit;or@import MRGSAuthentication;or#import <MRGSAuthentication/MRGSAuthentication.h>
Step 1. Add Sources
In your podfile, add sources to the top of the file:
source 'https://github.com/CocoaPods/Specs.git' # For main repo
source 'https://mrgs-gitea.my.games/mrgs/cocoapods-specs.git' # For MRGS repo
Step 2: Add dependencies
Add the latest version of MRGSAuthentication to target:
To add via subspecs:
To add via individual modules:
To add all mrgs modules:
Step 3: Install dependencies
- Run
pod install(orpod install --repo-updateif necessary) - Import the module in code:
@import MRGServiceKit;or@import MRGSAuthentication;or#import <MRGSAuthentication/MRGSAuthentication.h>
Step 1: Add dependencies
Add the dependency to your Cartfile:
binary "https://mrgs-nexus.my.games/repository/ios-sdks/MRGSAuthentication/MRGSAuthentication.json" ~> 5.0.0
Step 2: Install dependencies
- Run
carthage update --use-xcframeworks - Add downloaded frameworks to your project (make sure "do not embed" option is enabled)
- Set the
-ObjCflag in the "Other linker Flags" field in the project settings. - Import the module in code:
@import MRGServiceKit;or@import MRGSAuthentication;or#import <MRGSAuthentication/MRGSAuthentication.h>
- Download the latest version of the library. Unzip the archive.
-
Add
MRGSAuthentication.xcframeworkfrom the downloaded archive to your project (Drag the libraries to the "Linked frameworks and Libraries" section) (Also contains MRGSAuthentication.framework for compatibility - fat framework) -
Set the
-ObjCflag in the "Other linker Flags" field in the project settings. - Import the module in code:
@import MRGSAuthentication;or#import <MRGSAuthentication/MRGSAuthentication.h> - Also, you can add the
MRGServiceKit.handmodule.modulemapfiles from the archive to your project, or specify the path to them in the project settings in theBuild Settings -> Header search pathssection. Now, instead of importing each of our frameworks separately, you can only import one header file:@import MRGServiceKit;
Android:
Adding to the project
Add a dependency in build.gradle file:
Copy the MRGSAuthentication.aar file into the libs directory of your project. Add the dependencies into the build.gradle file.
Configuring MRGS parameters🔗
Pass received ClientID to MRGS SDK. To do this, when starting the MRGS SDK, add the appropriate setting in the parameters of the external SDK:
using MRGS;
public class MasterController : MonoBehaviour
{
void Awake()
{
// Configuring MRGS Parameters
// ...
var modulesParams = new List<MRGSExternalSDKSettings>
modulesParams.Add(new MRGSMyGamesParams("<MYGAMES_CLIENT_ID>")
// Configuring External SDKs and initializing MRGS
// ...
MRGService.Instance.Initialize(serviceParams, sdkParams)
}
}
@import MRGService;
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Configuring MRGS Parameters
// ...
//Configuring External SDKs
MRGSMyGamesParams* mygamesLoginParams = [[MRGSMyGamesParams alloc] initWithClientId:@"CLIENT_ID"];
NSArray *externalParams = @[ ..., mygamesLoginParams];
[MRGService startWithServiceParams:<params> externalSDKParams:externalParams delegate:nil];
}
import java.util.ArrayList;
import java.util.List;
import games.my.mrgs.MRGSModuleParams;
import games.my.mrgs.MRGService;
import games.my.mrgs.authentication.MRGSMyGamesAuthParams;
public class YourApplicationClass extends Application {
@Override
public void onCreate() {
super.onCreate();
// Setting MRGService
final MRGServiceParams serviceParams = ...;
// Setting External SDKs
final List<MRGSModuleParams> moduleParams = new ArrayList<>();
moduleParams.add(MRGSMyGamesAuthParams.init("<CLIENT_ID>"));
MRGService.service(context, serviceParams, moduleParams);
}
}
Authorization via VKPlay🔗
To change the authorization method from MyGames to VKPlay, it's enough to pass the following parameter to the config:
DEV environment🔗
To enable/disable the DEV environment (use urls that lead to servers with a test environment), it is enough to pass the following parameter to the config:
The test environment is only available from under the corporate VPN
Working with MRGSAuthentication interface🔗
To work with MyGames authorization, use the MRGSAuthenticationMyGames class. Please note that this class implements main interface MRGSAuthentication, so it includes all the methods of this interface. The following describes the standard implementation of the MRGSAuthentication interface:
Delegate🔗
Before you start working with the API, you need to install and implement a delegate that accepts callbacks:
// Setting
// 'this' conforms to 'IMRGSAuthenticationDelegate' protocol
MRGSAuthenticationMyGames.Instance.Delegate = this;
// Implementation
// The method that is called when the user has logged out of the social network remotely, or his session has ended.
public void OnAuthenticationProviderDidLogoutUser(MRGSAuthentication provider, MRGSAuthenticationUser user){
Debug.Log("MRGSAuthentication<Unity> - OnAuthenticationProviderDidLogoutUser: " + user + "\nNetwork: " + provider.SocialId().ToString());
}
// Setting
[MRGSAuthenticationMyGames sharedInstance].delegate = self;
//Implementation
// The method that is called when the user has remotely logged out of the social network, or his session has ended.
- (void)authenticationProvider:(id<MRGSAuthentication>)provider didLogoutUser:(MRGSAuthenticationUser *)user{
NSLog(@"User did logout: \n%@", user);
}
// The method that is called when the controller needs to be displayed to authorize the user.
- (void)shouldPresentAuthorizationController:(UIViewController *)viewController {
UIViewController *rootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
[rootVC presentViewController:viewController animated:YES completion:nil];
}
import androidx.annotation.NonNull;
import games.my.mrgs.authentication.MRGSAuthentication.OnExternalLogoutListener;
import games.my.mrgs.authentication.mygames.MRGSMyGames;
// Set a listener
MRGSMyGames.getInstance().setOnExternalLogoutListener(new OnExternalLogoutListener() {
@Override
public void onUserLogout(@NonNull String socialId) {
// Handel result.
}
});
Status🔗
Then, you need to check the authorization status (whether the user is logged in):
Login🔗
For a regular login, use one of the following methods:
// If error occured, error object will be non-null
MRGSAuthenticationMyGames.Instance.Login((MRGSError error) => {
if (error == null) {
// Auth success
}
});
// The response will include an object describing the user and the token, and an error object, if any.
MRGSAuthenticationMyGames.Instance.Login((MRGSAuthenticationCredential credentials, MRGSError error) => {
Debug.Log("MRGSAuthenticationMyGames:\nCredentials: " + credentials + "\nError:\n" + error);
if (error == null) {
// Auth success
}
});
// Only the error object will be returned in the response if it happened
[[MRGSAuthenticationMyGames sharedInstance] login:^(NSError *error) {
if (!error) {
// Auth success
}
}];
// The response will contain an object describing the user and the token, and an error object if it happened
[[MRGSAuthenticationMyGames sharedInstance] loginWithCompletionHandler:^(MRGSAuthenticationCredential *credentials, NSError *error) {
NSLog(@"Result - %@. Error - %@", credentials, error);
if (!error) {
// Auth success
}
}];
import android.app.Activity;
import androidx.annotation.NonNull;
import games.my.mrgs.MRGSError;
import games.my.mrgs.authentication.MRGSCredentials;
import games.my.mrgs.authentication.MRGSLoginCallback;
import games.my.mrgs.authentication.mygames.MRGSMyGames;
MRGSMyGames.getInstance().login(activity, new MRGSLoginCallback() {
@Override
public void onSuccess(@NonNull MRGSCredentials credentials) {
// Handle result.
}
@Override
public void onError(@NonNull MRGSError error) {
// Handle error.
}
});
Additional permissions are not available for MyGames, so this method will work the same as the method above.
import android.app.Activity;
import androidx.annotation.NonNull;
import java.util.Arrays;
import games.my.mrgs.MRGSError;
import games.my.mrgs.authentication.MRGSCredentials;
import games.my.mrgs.authentication.MRGSLoginCallback;
import games.my.mrgs.authentication.mygames.MRGSMyGames;
MRGSMyGames.getInstance().login(activity, Collections.emptyList(), new MRGSLoginCallback() {
@Override
public void onSuccess(@NonNull MRGSCredentials credentials) {
// Handle result
}
@Override
public void onError(@NonNull MRGSError error) {
// Handle error.
}
});
Re-calling Login
When the login method is called again, the browser will pull up data from cookie and users will see their current session and a continue button. Starting with MRGS 6.3.0 version , it is possible to ignore the current session so that users does the entire authorization process from the beginning.
Authorization status🔗
To get all information about the current state of authorization, user information, authorization status, use the following methods:
// The information about the user, identifier, name, email, etc.
MRGSAuthenticationMyGames.Instance.GetCurrentUser((MRGSAuthenticationUser user, MRGSError error) => {
Debug.Log("MRGSAuthenticationMyGames:\User: " + user + "\nError:\n" + error);
if (error == null) {
// Work with user data
}
});
// Information about the token, lifetime, etc.
MRGSAuthenticationMyGames.Instance.GetAccessToken((MRGSAuthenticationAccessToken token, MRGSError error) => {
Debug.Log("MRGSAuthenticationMyGames:\Token: " + token + "\nError:\n" + error);
if (error == null) {
// Work with token info
}
else if (error.Code == (int)MRGSAuthenticationErrorCode.ConnectionFailed)
{
// No network, try later
}
else
{
// Logout user from app (MRGS will logout automatically in SDK)
}
});
// An object is returned that combines information about the user (identifier, name, email, etc.) and about the token.
[[MRGSAuthenticationMyGames sharedInstance] getCredentials:^(MRGSAuthenticationCredential *credentials, NSError *error) {
NSLog(@"Result - %@. Error - %@", credentials, error);
if(!error){
// Credentials data work
}
}];
// Returns separately information about the user, ID, name, email, etc.
[[MRGSAuthenticationMyGames sharedInstance] getCurrentUser:^(MRGSAuthenticationUser *user, NSError *error) {
NSLog(@"User - %@. Error - %@", user, error);
if(!error){
// User data work
}
}];
// Information about the token, lifetime, etc. is returned separately.
[[MRGSAuthenticationMyGames sharedInstance] getAccessToken:^(MRGSAuthenticationAccessToken *token, NSError *error) {
if (!error) {
NSLog(@"getAccessToken result - %@", token);
} else {
NSLog(@"getAccessToken error - %@", error);
}
}];
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import games.my.mrgs.MRGSError;
import games.my.mrgs.authentication.MRGSAccessToken;
import games.my.mrgs.authentication.MRGSAuthentication;
import games.my.mrgs.authentication.MRGSUser;
import games.my.mrgs.authentication.mygames.MRGSMyGames;
import games.my.mrgs.utils.optional.BiConsumer;
// Returns user's information.
MRGSMyGames.getInstance().getCurrentUser(new MRGSAuthentication.UserCallback() {
@Override
public void onSuccess(@NonNull final MRGSUser user) {
}
@Override
public void onError(@NonNull MRGSError error) {
}
});
// Returns authentication's information.
MRGSMyGames.getInstance().getAccessToken(new BiConsumer<MRGSAccessToken, MRGSError>() {
@Override
public void accept(@Nullable MRGSAccessToken accessToken, @Nullable MRGSError error) {
if (error != null) {
Log.d("MRGSAuthentication", "AccessToken error: " + error.getErrorText());
} else {
Log.d("MRGSAuthentication", "AccessToken success: " + accessToken);
}
}
});
Logout🔗
In order to "log out" from a user account, use the method:
Hiding mention of MY.GAMES brand🔗
Actually, this only removes all visual mentions of the brand MY.GAMES, all network requests will be made to the same address. This is achieved by: disabling the feature to run authorization in the browser (now it will run only through WebView) and hiding all the buttons for authorization through other social networks. To enable this mode, it is enough to call the function before starting authorization:
MyGames Desktop🔗
Presetting🔗
Before starting work, make sure that you have correctly configured the application on the MRGS website, namely, add the MyGames AppID (GMRID) or SteamID. You can read more about setting in the Unity Desktop section. If configured correctly, MRGS will automatically receive the necessary validation keys for authorizing MyGames. No additional settings are required either on the server or on the client.
Features of MyGames authorization on a desktop🔗
When you start the game from MY.GAMES GC, the user is already logged into the GC, so there is no authorization as such, we just receive a special token and validate it on MY.GAMES server, checking that the user is real and hasn't faked anything. Then we get the user's data. Therefore, at the start of the application automatically we do the verification data and receive information about the user.
All standard methods of our authorization API described above work as usual. With the help of them, you can check if the user is logged in, get the necessary information about him, and more.
MY.GAMES GC recommends not to let the user play if his session is not confirmed by the server. Thus, at each start, you can call the login method (there will be no additional request, we will notify you as soon as the confirmation operation started earlier is completed) and get information about the result in the callback. The second option - you can check at the start using the standard methods of our authorization API if the user is logged in. In case the user is not logged in (for example, we did not have time to receive a response from the server), you can call the login method and wait for the result. But if the user is logged in (IsLoggedIn () == true), you need to listen the delegate, which will inform you if the user is logged out (that is, it will not be possible to validate information about him ).
Created: 2020-05-28