-
Notifications
You must be signed in to change notification settings - Fork 0
Telegram
Nate River edited this page Jun 3, 2024
·
2 revisions
The asset provides Telegram sign-in for Android, iOS, Windows, macOS, Universal Windows Platform (UWP) and WebGL apps made with Unity.
- Cross-platform user auth for cross-platform games and apps
- No plugins, no 3rd party libs, no dependencies
- No impact to build size
- SFSafariViewController is used on iOS (required by App Store review)
- Deep linking for Windows (UNITY_STANDALONE_WIN)
- Please visit Terminology section
- Your app navigates users to
Authorization Middleware
using a default web browser (embedded webviews are not allowed) -
Authorization Middleware
showsTelegram Widget
or performs silent auth call (depending onShowTelegramWidget
setting) - Users perform sign-in inside Telegram popup
-
Telegram Widget
returns auth data toAuthorization Middleware
-
Authorization Middleware
redirects auth data to your app with deep linking (when possible) -
Authorization Middleware
returns data by app request when deep linking is not possible (Editor, WebGL)
- For Android, iOS, macOS, Windows and UWP (platforms that support deep linking): COME UP WITH your
Custom URI scheme
(orProtocol
). It MUST contain the period symbol.
and small alphanumeric symbols only (no spaces, no undercores). In my example it issimple.oauth
, but it can bejelly.bean
(note thatCustom URI scheme
is not the same as your actual package name or bundle id). - For Android, iOS, UWP: enable deep linking as described in Unity documentation or as described below.
- For Android: create
AndroidManifest.xml
insideAssets/Plugins/Android/
, SET yourCustom URI scheme
inside, like<data android:scheme="simple.oauth" />
. You can useAndroidManifestExample.xml
from the asset as an example, just copy, rename and edit. AGAIN, DON'T FORGET TO REPLACEsimple.oauth
with yourCustom URI scheme
! - For iOS and macOS: navigate to
Player Settings > Other > Configuration
and add yourCustom URI scheme
toSupported URL schemes
. In Xcode, make sure that the URL scheme is added (Register your URL scheme). - For Universal Windows Platform: navigate to
Player Settings > Publishing Settings
and setProtocol
(it MUST contain a period symbol, for examplesimple.oauth
), then enableInternetClient
inCapabilities
. - For Windows: navigate to
Player Settings
and enableResolution and Presentation > Force Single Instance
and setOther Settings > Api Compatibility Level = .NET Framework
- Add @BotFather on Telegram
- Create a new bot with
/newbot
command, provide name andusername
- Execute
/setdomain
command and addhttps://hippogames.dev
(Authorization Middleware
) - Configure
Resources/TelegramAuthSettings.asset
- Set
Bot Id
(digits only, without #) which is displayed in Telegram conversation with your bot - Set
Bot Name
(without @) which isusername
from step 2 - Set
Custom Uri Scheme
picked in Preconditions - Set
ShowTelegramWidget
if needed (otherwise silent auth will be called)
- Set
-
Custom URI scheme
is picked, and it has a different value thansimple.oauth
-
Custom URI scheme
is set in 2 places: [1] Resources/TelegramAuthSettings.asset, [2] your application manifest (AndroidManifest.xml for Android,Supported URL schemes
for iOS,Protocol
for UWP) -
Bot Name
is copied to Resources/TelegramAuthSettings.asset
- Check our
Example
scene and C# code ofExample.cs
- Create an instance of
TelegramAuth
- Call
TelegramAuth.SignIn
- Create
OnSignIn
callback as the first argument forTelegramAuth.SignIn
to obtainUserInfo
- Build and test
- Write a review on the Asset Store :)
- Call
TelegramAuth.SignIn
withcaching: true
to return cachedUserInfo
- Call
TelegramAuth.SignIn
withcaching: false
to requestUserInfo
from Telegram each time - You can use
TelegramAuth.SavedAuth
to getUserInfo
(don't forget to check all values for null) - Call
TelegramAuth.SignOut
when 'Sign out` button is pressed (optional) - Disable debug logs for production by setting
TelegramAuth.DebugLog = false
- It's recommended to deploy your own trusted
Authorization Middleware
to handle sensitive data. Please refer to Authorization Middleware article. - You can use this asset with
async
methods, just refer toTelegramAuthAsync.cs
for examples.
- Please refer to User data disclosure
- Don't use default credentials that come with the asset in production, they are for test purposes only and can be disabled/blocked
- Check Manual cancellation if needed
- Common issues
- When
ShowTelegramWidget
is set to False some browsers may block popups or promt a user