Flutter App connection
-
hi, if I want to ake an ios and android app with FLUTTER language, how could I do social login trough that code too and not only trough the wordpress website?
The page I need help with: [log in to see the link]
-
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/b733d402ee2e2cee59b632f6e4741a9dSo 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.Thank you so much for this plugin. Could you please help me out here?
Where do I add following code to link the user with the social provider?https://gist.github.com/nextend/012ca54957e27dbea952fc42195fb0d1
Looking forward for your prompt response.
Hi @maniwp001
I am sorry, but as my colleague mentioned above we can not provide support for custom coding.
Anyways you should run this code, when you passed the user’s access token to Nextend Social Login’s REST API and it didn’t manage to find any users on your site with the given access token.
So basically after the registration.Note:
Since the usage of our REST API was a common topic, we have already created a documentation that I am sure you will find useful. If you are interested you can find the documentation of our REST API here:The part you are interested in, can be found under the “How can I use the REST API in my application?” section at the 3rd point.
Best regards,
Laszlo.
The topic ‘Flutter App connection’ is closed to new replies.