Single Sign-on
How it works
If you have several connected services with a common single account for user authentication, you can use Single Sign-on. The game website works as a service. It will allow a user to enter their credentials only once. After that, when opening one of the connected services, the user will already be authenticated.
Interaction flow
- Unauthenticated user opens one of the services.
- Your client sends the
Check user authentication request to the Xsolla Login server and gets error 401. - Your client opens the authentication form (Login Widget or your login UI) for the user.
- The user authenticates via a username and password or via a social network.
- Your client authenticates the user in your Login project:
- The following requests are used when integrating Login via API calls:
- The OAuth 2.0 protocol is used when integrating Login via the Widget.
login_urithat containsredirect_uriwithcodein the query-parameter.
- Your client redirects the user to
redirect_uri. - Your server sends the
Generate JWT request to exchange the receivedcodefor a JWT. The user is authenticated on the service. - The user opens another service.
- Your client sends the
Check user authentication request to the Xsolla Login server and receiveslogin_urithat containsredirect_uriwithcodein the query-parameter. - Your server sends the
Generate JWT request to exchange the receivedcodefor a JWT. The user is authenticated on the second service.
%%{init: {'themeVariables': { 'noteBkgColor': 'transparent', 'noteBorderColor': 'transparent' }}}%%
sequenceDiagram
participant U as User
participant CS1 as Connected service 1
participant XL as Xsolla Login server
participant LW as Login widget
participant CS2 as Connected service 2
U->>CS1: Opens service
CS1->>XL: Sends request to check user authentication
activate XL
XL-->>CS1: Sends “Unauthorized” error (401)
deactivate XL
CS1->>LW: Opens authentication form
U->>LW: Enters credentials
activate LW
LW->>XL: Authenticates user
deactivate LW
activate XL
XL-->>LW: Returns link with authorization code
deactivate XL
activate LW
LW-->>CS1: Redirects user to received link
deactivate LW
activate CS1
CS1->>XL: Sends request to generate user’s JWT
deactivate CS1
activate XL
XL-->>CS1: Returns user’s JWT
deactivate XL
U->>CS2: Opens another service
activate CS2
CS2->>XL: Sends request to check user authentication
deactivate CS2
activate XL
XL-->>CS2: Redirects user to received link
deactivate XL
activate CS2
CS2->>XL: Sends request to generate user’s JWT
deactivate CS2
activate XL
XL-->>CS2: Returns user’s JWT
deactivate XL
Differentiating access rights for different services
To differentiate user account access rights for different services, you can use special values of the scope=playfab) in different OAuth 2.0 clients.
Who can use it
Partners who have already integrated Login and use Xsolla, Firebase, or PlayFab database.
How to get it
To connect Single Sign-on:
Connecting OAuth 2.0 protocol
Follow the instruction to connect the OAuth 2.0 protocol. You can use one OAuth 2.0 client for all services or create a separate OAuth 2.0 client for every service.
Calling request for getting user session
Implement the
Example of the request:
http
- http
- curl
1GET https://login.xsolla.com/api/oauth2/sso?client_id=<client_id>&redirect_uri=<redirect_uri>&scope=<scope>&state=<state>&response_type=code HTTP/1.1
1curl --request GET \
2 --url 'https://login.xsolla.com/api/oauth2/sso?redirect_uri=redirect_uri&response_type=code&state=state&scope=scope&client_id=client_id'
Example of the response when the user is authenticated:
- http
1HTTP/1.1 200 OK
2Content-Type: application/json
3
4{
5 "login_url": "<redirect_uri>?code=<code>"
6}
To get a user JWT:
- Your client implements and uses the request that redirects the user to the received
redirect_uri. - Your server sends the
Generate JWT request with receivedcodeandgrant_type=authorization_codefor getting a JWT.
Example of the response when the user is not authenticated:
- http
1HTTP/1.1 401 Unauthorized
2Content-Type: application/json
3
4{
5 "error": {
6 "code": "003-040",
7 "description": "User is unauthorized."
8 }
9}
Found a typo or other text error? Select the text and press Ctrl+Enter.