Skip to main content

Set up Snapchat as an identity provider

Last updated on April 23, 2024

Overview

This guide is intended to help verified Snapchat developers to connect Snapchat Accounts to AccelByte Gaming Services (AGS). You may need to set up additional features within Snapchat services which are not listed here. For full information about setting up Snapchat services, we recommend contacting your Snapchat representative and reviewing Snapchat documentation directly.

important

This guide is intended for public use and contains limited information due to confidentiality. We recommend you refer to the full confidential guide first. To request a copy of the confidential guide, contact your AccelByte Technical Producer.

Goals

Enable the Snapchat authentication method for your game with the AccelByte Game SDK.

Prerequisites

  • A Snapchat Developer account.
  • An Organization Under Developer Account
  • If you use Unreal Engine, install UE version 4.27 or 5.0.
  • An AccelByte Admin Portal Account to set up authentication and manage permissions.
  • A Publisher Namespace for your Player Portal and Launcher, and a Game Namespace for your game.
  • A Player Portal.
  • A Unity or Unreal game project with the latest version of the AccelByte Game SDK imported.
  • Familiarity with AGS Identity and Access Management (IAM) Clients.

Setting up Snapchat Kit App

Create Snap Kit App

Create a Snap Kit App under your Snapchat Developer Account. Follow the Setting up your first app guide

Activate Snap Login Kit

Activate Snap Login Kit under your Snap Kit App and fill Redirect URI for OAuth with your domain URL (e.g., https://prod.gamingservices.accelbyte.io). More Info about Login Kit you can refer to Login Kit Overview

Setting Up In Game Login for Snapchat

Use the following steps to set up Snapchat logins in your game. This will allow your players to sign in to your game using their Snapchat accounts

  1. Login into the AccelByte Admin portal, choose your Game Namespace and click Login Method below the User Management sidebar, and click the + Add New button on the right side. AccelByte Admin Portal Login

  2. Click on Snapchat Button. Snapchat

  3. Fill Client ID with your Snap Kit Client ID, Client Secret with your Snap Kit Client Secret and Redirect URI with your Snapchat Login Kit OAuth Redirect URI/ Snapchat Create Configuration

  4. You will be redirected to the detail page, at this point you just need to activate it and it will able to be used. Activate Snapchat

Create IAM Client

An IAM client is a representation of the game client that you want to release on your target platform.

If you already have an IAM Client for your game on a specific SDK Platform (e.g., Xbox, Steam, or Playstation), you don’t have to create a new IAM Client. Since Snapchat is not a platform on which to build games, you can use an existing IAM Client. Learn more about IAM Clients by reading Manage access control for applications.

In Game Login Instructions

The setup for each game engine is different. Please choose your game engine from the available tabs.

Unreal In-game login integration

You can integrate your Snapchat Game to sign-in with AccelByte SDK so that your players can log in to games using Snapchat credentials.

Unreal Preparation and Configuration

Snapchat doesn’t support integration for UE4. So, the implementation uses web login and retrieving login code from SnapChat Auth as a token to Login into AccelByte. The Snapchat account will be linked to the AccelByte account as well, by default it will be a headless account

Ref: https://docs.snap.com/snap-kit/login-kit/Tutorials/web

Adding dependency

First you need to add public dependency modules called AccelbyteUe4Sdk, This dependencies needed for integrating your project to use the our Accelbyte SDK Plugin within Unreal Engine.

public ABThirdPartyLogin(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" , "AccelByteUe4Sdk", "Slate", "SlateCore" });

PrivateDependencyModuleNames.AddRange(new string[] { "Json", "HTTP" });

}

Add AccelbyteUe4Sdk inside <YourProject>.Target.cs and <YourProjectEditor>.Target.cs

public ABThirdPartyLoginTarget( TargetInfo Target) : base(Target)
{
Type = TargetType.Game;
DefaultBuildSettings = BuildSettingsVersion.V2;
ExtraModuleNames.AddRange( new string[] { "ABThirdPartyLogin", "AccelByteUe4Sdk" } );
}
public ABThirdPartyLoginEditorTarget( TargetInfo Target) : base(Target)
{
Type = TargetType.Editor;
DefaultBuildSettings = BuildSettingsVersion.V2;
ExtraModuleNames.AddRange( new string[] { "ABThirdPartyLogin", "AccelByteUe4Sdk" } );
}

Unreal Engine Project Setting for Snapchat

Inside your DefaultEngine.ini file please Add Accelbyte credential here on DefaultEngine.ini

[/Script/AccelByteUe4Sdk.AccelByteSettings]
ClientId=<Your Client_Id>
ClientSecret=<Your Client_Secret>
Namespace=<Your Namespace>
PublisherNamespace=<Your Publisher Namespace>
RedirectURI="http://127.0.0.1"
BaseUrl="https://prod.gamingservices.accelbyte.io"
IamServerUrl="https://prod.gamingservices.accelbyte.io/iam"
PlatformServerUrl="https://prod.gamingservices.accelbyte.io/platform"

[SnapChatConfig]
SnapChatClientId=<SnapChatClientId>

Unreal Sample Code Implementation

Next step, we will show you how to implement the Snapchat authentication method for your game with sample code below.

  1. Create WebBrowser item in BluePrint as a login container.

  2. Load Login Snapchat Url : https://accounts.snapchat.com/accounts/oauth2/auth

    And add auth params :

    1. redirect_uri: RedirectURL when login is done. Since redirection is back to the game fill value with BaseURL (FRegistry::Settings.BaseUrl). Also, put the BaseUrl value in the Redirect Uri config in the Snapchat developer portal to whitelist.
    2. response_type: Put value with “code”.
    3. scope: Put value with permission scope \
https://auth.snapchat.com/oauth2/api/user.display_nameGrants access to the user's Snapchat display name
https://auth.snapchat.com/oauth2/api/user.bitmoji.avatarGrants access to the user's Bitmoji avatar; toggleable by user
https://auth.snapchat.com/oauth2/api/user.external_idGrants access to the user's external id which can be used to onboard the user into an application
void UAccelByteAuth::SnapChatLogin()
{
FString SnapChatClientId;
GConfig->GetString(TEXT("SnapChatConfig"), TEXT("SnapChatClientId"), SnapChatClientId, GEngineIni);
FString RedirectUri = FRegistry::Settings.BaseUrl;
FString Scope = TEXT("https://auth.snapchat.com/oauth2/api/user.display_name https://auth.snapchat.com/oauth2/api/user.bitmoji.avatar https://auth.snapchat.com/oauth2/api/user.external_id");

FString Url = FString::Printf(TEXT("https://accounts.snapchat.com/accounts/oauth2/auth?client_id=%s&redirect_uri=%s&response_type=%s&scope=%s"),
*FGenericPlatformHttp::UrlEncode(SnapChatClientId),
*FGenericPlatformHttp::UrlEncode(RedirectUri),
TEXT("code"),
*FGenericPlatformHttp::UrlEncode(Scope));

WBrowser_SnapChatAuth->LoadURL(Url);
WBrowser_SnapChatAuth->OnUrlChanged.AddUniqueDynamic(this, &UAccelByteAuth::AccelByteLoginWithSnapChat);
}

void UAccelByteAuth::AccelByteLoginWithSnapChat(const FText& NewUrl)
{
FString Url = NewUrl.ToString();
FString RedirectUri = FRegistry::Settings.BaseUrl;
FString LoginCode = TEXT("");

if (Url.Contains(RedirectUri))
{
LoginCode = FGenericPlatformHttp::GetUrlParameter(Url, TEXT("code")).GetValue();
}

if (!LoginCode.IsEmpty())
{
FRegistry::User.LoginWithOtherPlatform(EAccelBytePlatformType::SnapChat, LoginCode, FVoidHandler::CreateWeakLambda(this, [this]()
{
// Handle Success Login
}),
FCustomErrorHandler::CreateWeakLambda(this, [](int32 ErrorCode, const FString& ErrorMessage, const FJsonObject& ErrorJson)
{
// Handle Error Login
}));

// Close Login Page (Hide WebBrowser)
}
}
note

platform_token for Snapchat Authentication is Auth Code

After adding this sample code to your project, compile, build, and run your project. That's it!

Sample Code Testing

The image below shows a successful login using an Snapchat account to our test app. Unreal Code Testing