Hi @whichtransfers
The part of the registration that Nextend Social Login’s REST API can help you with is checking if there’s any user in your site who has already registered with the currently used social account. Everything else must be done with custom coding.
Before continuing please note that we can not provide support for custom coding!
Let’s say someone tries to register/login via Google. This is the process you’ll need to achieve:
1) Communication between the user and your mobile app
You need to create a way for the user to communicate with Google API. (Basically a way to display the authentication and authorization window. So the user will be able to login and authorize your Google App. Once the user logged in and authorized your app, it will return an access token, which is used for the validation.
2) “User validation”
Once you have the access token you can use this to communicate with Nextend Social Login (NSL) which will check whether there’s any user registered to your site with the given access token.
Nextend Social Login REST Api endpoints:
Method: POST
/wp-json/nextend-social-login/v1/google/get_user
For example:
https://example.com/wp-json/nextend-social-login/v1/google/get_user
the file itself can be found here: wp-content/plugins/nextend-facebook-connectNSL/REST.php if you would like to check it.
POST Args:
access_token > NSL needs the access token as a JSON, like these: https://gist.github.com/nextend/b733d402ee2e2cee59b632f6e4741a9d
So I would suggest checking your OAuth 2 access token if it is correct or not. We also have a Test form code snippet, what you could use for this purpose. So you could try posting your access token via the test form:
https://gist.github.com/nextend/4d3c701c8d99972824025e4dfdeccac0
Important: You need to replace the “xyz.com” with your own domain.
Once the Access Token is posted the endpoint it can return either:
Success -> status 200 -> json encoded WP user id, for example: “44”
Fail -> if the status code isn’t 200 then an error happened -> For example: {“code”:”error”,”message”:”The access token could not be decrypted”,”data”:null}
3a) Access token found – Login process
If NSL returns the WordPress user ID you’ll need to log them in to your mobile app.
3b) Access token not found – Registration process
If NSL did not find any user with the given access token, you need to create a new WordPress user using WordPress’ REST API. Then log them in and you can link the user with the social provider.
These codes can be helpful at the 3rd step: https://gist.github.com/nextend/012ca54957e27dbea952fc42195fb0d1
for linking the social account to the WordPress user.
line 1-11: will verify that the access token is valid, if it is valid it will retrieve the social user id ( this ISN’T the WordPress user id! )
line 13-16: will connect the social provider account with the WordPress user ID.