Social login
In your application, you can implement user authentication using their account in social networks. If the user’s first login is via a social network, a new account is created automatically. The user doesn’t need to enter a username, email address, or other data.
There are two ways to implement authentication through social networks:
- Web-based authentication. In this case, the application opens a form in the browser to complete authentication via the selected social network. This option is suitable for both mobile and desktop applications.
- Native authentication. In this case, authentication is performed via the social network application on the user’s device. This option is only suitable for mobile applications.
Social login can be your application’s primary or alternative authentication method.
If you use social login as an alternative authentication method, the social network account automatically links to an existing user account if the following conditions are met:
- A user who signed up with a username/email address and password logged into your application via a social network account.
- A social network returns an email address.
- The user’s email address in a social network matches the email address used to sign up in your application.
You can also implement manual linking of a social network account.
How-tos
SDK supports the following providers for social login:
- Amazon
- Apple
- Baidu
- Battle.net
- Discord
- GitHub
- Kakao
- MSN
- Mail.ru
- Microsoft
- Naver
- Odnoklassniki
- PayPal
- Steam
- Twitch.tv
- VK
- Vimeo
- Xbox Live
- Yahoo
- Yandex
- YouTube
To set up authentication through web services:
- In the application interface, add buttons for authentication via social networks.
- Set up social connections for a Login project in Publisher Account.
- Implement authentication logic on the application side.
Set up social connections for Login project in Xsolla Publisher Account
- Open your project in Publisher Account.
- In the side menu, click Login.
- Click Configure in the pane of a Login project.
- Go to the Authentication block and select the Social login section.
- Connect social networks that users can use to sign up and log into the application:
- To connect a social network, click the ⚙ icon and select Connect.
- To connect several social networks at once, select the required panes (their borders will turn green). Then, from the Manage drop-down menu, select Connect.
- To connect all available social networks, click Select all. Then, from the Manage drop-down menu, select Connect.
Integrate on application side
- Call the
startSocialAuth
method from the Login library. - Inside the
onActivityResult
method, call thefinishSocialAuth
method from the Login library.
Native authentication lets users log in to your application via a social network account configured on a mobile device.
The first time a user logs in, the social networking application is launched and asks for permission to authenticate the user. After that, authentication is performed automatically without requiring the user to do anything.
Currently, SDK has implemented native authentication via the following social networks:
To configure native authentication:
- In the application interface, add buttons for authentication via social networks.
- Configure the application in the developer account for the social network:
- For authentication via Facebook:
- Register and create a new application.
- Set up the application page in your Facebook developer account.
- For authentication via Google, set up the project in Google API Console.
- For authentication via WeChat:
- Register and create a new application.
- Submit the application for review.
- For authentication via QQ:
- Register and create a new application.
- Submit the application for review.
- For authentication via Facebook:
- Set up authentication via social networks on the Xsolla side:
- For Facebook and Google, set up social connections in Publisher Account.
- For WeChat and QQ, contact your Customer Success Manager or email to csm@xsolla.com.
- Install libraries for authenticating via social network. To do this, open the
build.gradle
file of your application and in the dependencies section add the following lines, where<version_number>
is the required version of the library:- For authentication via Facebook:
- groovy
implementation 'com.xsolla.android:login-facebook:<version_number>'
- For authentication via Google:
- groovy
implementation 'com.xsolla.android:login-google:<version_number>'
- For authentication via WeChat:
- groovy
implementation 'com.xsolla.android:login-wechat:<version_number>'
- For authentication via QQ:
- groovy
implementation 'com.xsolla.android:login-qq:<version_number>'
- Initialize the Login library with the following parameters:
facebook_id
— App ID from the Facebook developer accountgoogle_id
— Client ID for web application from the Google API Consolewechat_id
— AppID from the WeChat developer accountqq_id
— AppID from the QQ developer account
An example of initializing the library when authenticating via OAuth 2.0:
- kotlin
val loginConfig = LoginConfig.OauthBuilder()
.setProjectId("login-project-id")
.setOauthClientId("oauth2-client-id")
.setSocialConfig(XLogin.SocialConfig(
facebookAppId = "facebook_id",
googleServerId = "google_id",
wechatAppId = "wechat_id",
qqAppId = "qq_id"
))
.build()
XLogin.init(applicationContext, loginConfig)
- For authentication via WeChat, modify the application code:
- Add the
WXEntryActivity
class to the<your_package_name>.wxapi
package, where<your_package_name>
is the name of your application package:
- Add the
- kotlin
package <your_package_name>.wxapi
import android.app.Activity
import android.os.Bundle
import com.tencent.mm.opensdk.modelbase.BaseReq
import com.tencent.mm.opensdk.modelbase.BaseResp
import com.tencent.mm.opensdk.openapi.IWXAPI
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler
import com.tencent.mm.opensdk.openapi.WXAPIFactory
import com.xsolla.android.login.util.WechatUtils
class WXEntryActivity : Activity(), IWXAPIEventHandler {
private lateinit var iwxapi: IWXAPI
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
iwxapi = WXAPIFactory.createWXAPI(this, WechatUtils.wechatAppId, false)
iwxapi.handleIntent(intent, this)
finish()
}
override fun onReq(req: BaseReq?) {
}
override fun onResp(resp: BaseResp) {
WechatUtils.wechatResult = resp
}
}
- Add the following element to your
AndroidManifest.xml
file:
- Add the following element to your
- kotlin
<activity
android:name="<your_package_name>.wxapi.WXEntryActivity"
android:exported="true"
android:launchMode="singleTask" />
Set up application page in your Facebook developer account
- Go to project settings in the Facebook developer account.
- Go to Settings > Basic.
- Click Add Platform and select Android.
- Specify the package name of your Android application in the Google Play Package Name field.
- Specify a fully qualified class name of the default Activity in the Class Name field.
- Generate a hash key and specify it in the Key Hashes field.
- Click Save Changes.
For further native authentication configuration, you will need App ID and App Secret found in project settings in Settings > Basic section.
Set up project in Google API Console
- Go to Google API Console.
- Click New Project.
- Specify Project name and Location and click Save.
- Go to the created project and click OAuth consent screen in the side menu.
- Select External option and click Create.
- Specify the necessary parameters and click Save.
- Click Credentials in the side menu.
- Create an OAuth 2.0 client for your Android app:
- Click Create credentials and select OAuth client ID.
- Specify Android in the Application type field.
- Specify Name.
- Specify package name of your Android application in the Package name field.
- Get the SHA-key.
- Specify SHA-key generated in the previous step SHA-key in the SHA-1 certificate fingerprint field.
- Click Create.
- Click OK.
- Create an OAuth 2.0 client for the web application:
- Click Create credentials and select OAuth client ID.
- Specify Web application in the Application type field.
- Specify Name.
- Click Add URI in the Authorized redirect URIs section and specify
https://login.xsolla.com/api/social/oauth2/callback
URI. - Click Create.
- Click OK.
For further native authentication configuration, you will need Client ID and Client Secret found in settings of the Client ID for the web application.
Set up social connections for Login project in Xsolla Publisher Account
- Open your project in Publisher Account.
- In the side menu, click Login.
- Click Configure in the pane of a Login project.
- Go to the Authentication block and select Social login section.
- To set up a social network, go to the social network card, click the ⚙ icon to the right of the title, and select Connect.
Integrate on application side
- Call the
startSocialAuth
method from the Login library. - Inside the
onActivityResult
method, call thefinishSocialAuth
method from the Login library.
Useful links
Last updated: July 31, 2024Found a typo or other text error? Select the text and press Ctrl+Enter.