Telegram - hippogamesunity/SimpleSignIn GitHub Wiki
Welcome to Simple Telegram Sign-In wiki!
The asset provides Telegram sign-in for Android, iOS, Windows, macOS, Universal Windows Platform (UWP) and WebGL apps made with Unity.
Benefits
- 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)
Terminology
- Please visit Terminology section
Understanding how it works
- Your app navigates users to
Authorization Middlewareusing a default web browser (embedded webviews are not allowed) Authorization MiddlewareshowsTelegram Widgetor performs silent auth call (depending onShowTelegramWidgetsetting)- Users perform sign-in inside Telegram popup
Telegram Widgetreturns auth data toAuthorization MiddlewareAuthorization Middlewareredirects auth data to your app with deep linking (when possible)Authorization Middlewarereturns data by app request when deep linking is not possible (Editor, WebGL)
Preconditions
- 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 schemeis 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.xmlinsideAssets/Plugins/Android/, SET yourCustom URI schemeinside, like<data android:scheme="simple.oauth" />. You can useAndroidManifestExample.xmlfrom the asset as an example, just copy, rename and edit. AGAIN, DON'T FORGET TO REPLACEsimple.oauthwith yourCustom URI scheme! - For iOS and macOS: navigate to
Player Settings > Other > Configurationand add yourCustom URI schemetoSupported 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 Settingsand setProtocol(it MUST contain a period symbol, for examplesimple.oauth), then enableInternetClientinCapabilities. - For Windows: navigate to
Player Settingsand enableResolution and Presentation > Force Single Instanceand setOther Settings > Api Compatibility Level = .NET Framework
Setup steps
- Add @BotFather on Telegram
- Create a new bot with
/newbotcommand, provide name andusername - Execute
/setdomaincommand 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 isusernamefrom step 2 - Set
Custom Uri Schemepicked in Preconditions - Set
ShowTelegramWidgetif needed (otherwise silent auth will be called)
- Set
Checklist
-
Custom URI schemeis picked, and it has a different value thansimple.oauth -
Custom URI schemeis set in 2 places: [1] Resources/TelegramAuthSettings.asset, [2] your application manifest (AndroidManifest.xml for Android,Supported URL schemesfor iOS,Protocolfor UWP) -
Bot Nameis copied to Resources/TelegramAuthSettings.asset
Usage
- Check our
Examplescene and C# code ofExample.cs - Create an instance of
TelegramAuth - Call
TelegramAuth.SignIn - Create
OnSignIncallback as the first argument forTelegramAuth.SignInto obtainUserInfo - Build and test
- Write a review on the Asset Store :)
Best practices
- Call
TelegramAuth.SignInwithcaching: trueto return cachedUserInfo - Call
TelegramAuth.SignInwithcaching: falseto requestUserInfofrom Telegram each time - You can use
TelegramAuth.SavedAuthto getUserInfo(don't forget to check all values for null) - Call
TelegramAuth.SignOutwhen 'Sign out` button is pressed (optional) - Disable debug logs for production by setting
TelegramAuth.DebugLog = false
Next steps (optional)
- It's recommended to deploy your own trusted
Authorization Middlewareto handle sensitive data. Please refer to Authorization Middleware article. - You can use this asset with
asyncmethods, just refer toTelegramAuthAsync.csfor examples.
Notes
- 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
Known issues
- Common issues
- When
ShowTelegramWidgetis set to False some browsers may block popups or promt a user