Authenticate from Facebook/Steam/Windows/iOS etc.

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

Luke64
Posts: 21
Joined: 08 Nov 2020, 23:15

Authenticate from Facebook/Steam/Windows/iOS etc.

Postby Luke64 » 08 Jan 2021, 16:19

Hello and happy new year everyone!

I have a question regarding non-username/password logins I'd like to ask for your help with.

Scenario
For a game of ours we authenticate users server-side using tokens/keys/whatever from client SDKs of various vendors, like Facebook:
The client retrieves some access token from Facebook's SDK and sends it to the server, letting it identify the user safely with Facebook's servers, then getting the real user name (or id) from our own database.

The problem
We don't have a username or password the user can authenticate with in the first place. Also, any logged in user should only be able to be logged in once (so we need to use that SFS2X option to log out multiple sessions).

Planned solution
I use a zone extension with custom login functionality (=handling the USER_LOGIN event).
As it's possible in the client's LoginRequest to pass a SFSObject as parameters, I'll be using that to submit access tokens and other custom data required to identify the user. The login username/password will always be set to a static value like "user".
Now, my extension would ignore username and password but use the data from the parameter SFSObject to authenticate the user with Facebook, then find her in the local database and finally set her username as described here in section 4):
https://smartfoxserver.com/blog/how-to-create-an-extension-based-custom-login/

Questions
1) Will the user name change mentioned above also be picked up by SFS2X? Will it use that name for logging out other sessions with the same name? Or will it eventually stick to the originally submitted name (e.g. above "user"), in which case my solution won't work?
2) I couldn't find that mentioned explicitly in the docs, but what event parameter key denotes the custom SFSObject parameters in the event received by the handleServerEvent method? Is it LOGIN_IN_DATA:

Code: Select all

ISFSObject params = (ISFSObject) event.getParameter(SFSEventParam.LOGIN_IN_DATA);
?

Thanks a lot in advance!
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Authenticate from Facebook/Steam/Windows/iOS etc.

Postby Lapo » 11 Jan 2021, 10:14

Hello,
and happy new year to you too :)

1) Will the user name change mentioned above also be picked up by SFS2X? Will it use that name for logging out other sessions with the same name? Or will it eventually stick to the originally submitted name (e.g. above "user"), in which case my solution won't work?

Yes, you can override the user name sent by the client with a custom value that is decided at runtime.
See this article:
https://smartfoxserver.com/blog/how-to- ... tom-login/

in particular section 4

2) I couldn't find that mentioned explicitly in the docs, but what event parameter key denotes the custom SFSObject parameters in the event received by the handleServerEvent method? Is it LOGIN_IN_DATA:

Yes, you can access the custom object sent from client side like this:

Code: Select all

public void handleServerEvent(ISFSEvent event) throws Exception
{
   // Data coming from the client side

   String userName    = (String) event.getParameter(SFSEventParam.LOGIN_NAME);
   String password     = (String) event.getParameter(SFSEventParam.LOGIN_PASSWORD);
   ISFSObject inData    = (ISFSObject) event.getParameter(SFSEventParam.LOGIN_IN_DATA);
}


Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
Luke64
Posts: 21
Joined: 08 Nov 2020, 23:15

Re: Authenticate from Facebook/Steam/Windows/iOS etc.

Postby Luke64 » 11 Jan 2021, 12:03

Lapo wrote:
1) Will the user name change mentioned above also be picked up by SFS2X? Will it use that name for logging out other sessions with the same name? Or will it eventually stick to the originally submitted name (e.g. above "user"), in which case my solution won't work?

Yes, you can override the user name sent by the client with a custom value that is decided at runtime.
See this article:
https://smartfoxserver.com/blog/how-to- ... tom-login/

in particular section 4

That's literally what I was referring to in my question. ;) Great, so the username change gets picked up by SFS2X, that is awesome and a great relief (could've been a showstopper).

Everything turned out working really fine so far! I have the extension .jar in place for custom Facebook access token login, the server picks up my .war file for the "private push API" I've been setting up, everything compiles and runs smooth under Java 11.

I wish I had been reminded of SmartFoxServer sooner, would have spared me time and hurt.

Thank you for the help!

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 46 guests