Tell me, please, how to log in to the system using a social network. I can not find any detailed information on how to do it correctly. There is a Java + Spring server (Tomcat) and an Android mobile application. The question is how to build an authorization mechanism? I can use the SDK from VK to authorize a user on a mobile device, yes, but what does it give me? How to authorize it in the system? Authorization in VC will give me some kind of token? Which I will send to my server, and the server should check the validity of this token using the same API from VK? Where can I read about it? Tell me how you solved such problems.
1 answer
There are several possible solutions. I would do something like this:
- On the mobile, the user is
access_tokenin to the VC, gettingaccess_token. - Sends a token to the server.
- The server on the token gets the user profile with the VK API.
- Checks if there is such a user in the database by its
idin the VC. - If not, creates a user in his database, writing his
idto the VC in the field of the user table. - If the user already has one, or he has just been created, he generates his token for him by login (for example,
idin VC) and password (even if it is a random string generated when creating the user) - It sends the generated token to the mobile phone.
- Mobil writes it to
SharedPreferencesand uses it to query the server.
As a result, for the user it will look like a login through VC, and you will have on the server all of his available info from VC, the ability to login the user by login and password and all requests to your server will nicely require a token.
|