• Resolved ycv005

    (@ycv005)


    Hello, I want to create a user after successful token authentication. I was looking into filename- wp-content/plugins/nextend-facebook-connectNSL/REST.php

    Into method called- get_user, a line was
    $user = $provider->findUserByAccessToken($request['access_token']);

    What data does the $user variable contain? Does it contain email, name, username?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Laszlo

    (@laszloszalvak)

    Hi @ycv005

    Registration:
    Our REST API can not help you in registering WordPress accounts, that must be done with custom coding.

    Also please note that, when you register a new WordPress account, you will need to make REST API requests to the official endpoint of the provider. ( So not the REST API of Nextend Social Login, but the REST API of the provider e.g. Facebook User Graph API: https://developers.facebook.com/docs/graph-api/reference/user/ )

    Username:
    You will need to generate a unique username with custom coding. ( Tip: Nextend Social Login tries to generate unique usernames from the first name / last name if it is possible. If we can not generate a valid username from those strings, then we will rather generate unique random username. So actually you could do the same way. )

    Returning to your question:
    If you inspect the findUserByAccessToken method in Nextend Social Login’s source code you will see the following code:

        public function findUserByAccessToken($access_token) {
            return $this->getUserIDByProviderIdentifier($this->findSocialIDByAccessToken($access_token));
        }

    and as it name suggests the “getUserIDByProviderIdentifier” method will return the user id of the WordPress account, that you access token is associated with
    ( Please note that this method will only return the user id if there is a user already registered with your access token. )

    Best regards,
    Laszlo.

    Thread Starter ycv005

    (@ycv005)

    I have searched about 1 day then coming back to you, so I searched how to create a user on WordPress using rest API and I found that I have to install 2 plugin from outside that are

    – WP REST API- https://github.com/WP-API/WP-API
    – JWT AUTH TOKEN- https://ww.wp.xz.cn/plugins/jwt-authentication-for-wp-rest-api/

    How can I do without plugin(as you do using token(most probably) and create user on site). If that’s not possible with rest api then what approach do I need to follow, does installing above plugin shows that I am in right direction.

    Also, why do I need to call to official rest API URL of the provider as you already provided a way to connect a WordPress user with social id.

    https://gist.github.com/nextend/012ca54957e27dbea952fc42195fb0d1

    Your any direction/guidance will be helpful.

    Thanks in advance.

    • This reply was modified 5 years, 12 months ago by ycv005.
    Plugin Support Laszlo

    (@laszloszalvak)

    Hi @ycv005

    Please note that this is already out of the scope of Nextend Social Login and we can not provide support for custom coding, but the information below may help you.

    So, actually WordPress has its own REST API:

    what you can use for creating users. However you are only able to use the REST API with some kind of authentication:

    and for that if you don’t want to write the authentication on your own, then you will indeed need a custom plugin like the ones the documentation mentioned above. ( The one you mentioned is also on the list. )

    If you would like to simply make some test requests for creating users with the REST API of WordPress,then this topic may help you:

    As for: “Also, why do I need to call to official rest API URL of the provider as you already provided a way to connect a WordPress user with social id.
    As I mentioned above, our REST API can not help you in registering WordPress accounts. You can only use it for checking whether there is a user on your site with the access token or not.

    To clarify the code in the gist linked above:

    • line 1-11: will check whether the provider is enabled or not, and after that it will try to get the social ID of the user according to the access token that you also sent to NSL REST API endpoint of the provider. ( Important note: The Social ID is not the WordPress ID, but it is a unique identifier that the provider use in your App to identify the users – so it comes from your App. If you check the <wp_preffix>social_users table in your database, you will see this under the “identifier” column. And we actually use this information as a link between the WordPress account and the social media account. )
    • line 13-16: creates the earlier mentioned link between the social media account and the WordPress account. This can be used for logging in the user with social login to the associated WordPress account.

    So if you want to register the users in your App via social login, then you probably want to get their name and email address, what you will only be able to get over the official REST API of the provider. In this process Nextend Social Login can not help you, I am sorry.

    Best regards,
    Laszlo.

    Thread Starter ycv005

    (@ycv005)

    I have got a way to create a user via JWT plugin but I have some question-

    1. Do I need to implement this gist – https://gist.github.com/nextend/012ca54957e27dbea952fc42195fb0d1
    if yes, then where?

    2. Is this gist common for all providers? (for example- google provides access token and id token but in gist, it is only given)

    3. I am able to create a user on WordPress and apply your above gist to connect WordPress with a social account(if I applied successfully). Do I still need to call the official rest api of provider?

    4. Apple sign-in(Yeah, pro version which I am supposed to buy). If I complete user creation & connecting them to the provider successfully via REST api, do I need to implement extra steps in Apple sign-in(in term of rest api side & not setup on website or apple site)?

    Your any direction/guidance will be helpful.

    Thanks in advance.

    • This reply was modified 5 years, 11 months ago by ycv005.
    Plugin Support Laszlo

    (@laszloszalvak)

    Hi @ycv005

    1.) That gist is just an example that shows how you can link a social account to an existing WordPress account. Linking these accounts is necessary, to make the user be able to login to his/her WordPress account whenever he/she connects with a certain social account.
    Please note that, we can not provide support for questions and problems related to custom coding, but you should implement the linking at the part where:
    – you handle the registration with social login
    – you handle the login, when the user logs in with a social account which email address matches with a registered WordPress account.

    2.) Linking works the same for all providers. But if we take the gist above as an example then you need to make sure the value of the $providerID variable is always the ID of the provider the user is trying to connect with.
    Also if you check the “REST API endpoints and Access Token format” section of our REST API documentations:
    https://nextendweb.com/nextend-social-login-docs/nextend-social-login-rest-api/#access_token_format
    then you will see the access token is always a JSON encoded string. E.g.: the Access token of Google looks something like this:
    {"access_token": "*************", "expires_in": 3600, "token_type": "Bearer", "id_token": "*************"}
    So to sum things up, this string is your access token, and as you see it contains the id_token, as well.

    3.) If you have already managed to register a WordPress account, then you don’t need to make additional requests to the official REST API. ( Those extra requests are necessary, when you need some user details when you register the account. )

    4.) As per the forum rules, on this forum we are only allowed to answer questions related to the Free version. Since the Apple provider is a Pro provider, available with Nextend Social Login Pro Addon, please rather open a support ticket at: https://nextendweb.com/contact-us/nextend-social-login-support/?ref=https://ww.wp.xz.cn/support/topic/rest-php-detail-about-data-in-user/#post-12983978

    Best regards,
    Laszlo.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Rest.php: Detail about data in $user’ is closed to new replies.