Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Paul Seal 400 posts 2167 karma points MVP 2x c-trib
    Feb 23, 2020 @ 15:42
    Paul Seal
    0

    Hello Can anyone help me get a basic member login with facebook working on an Umbraco 7 site please?

    I’m looking for code examples.

    Cheers

    Paul

  • Graham Davis 84 posts 293 karma points
    Feb 23, 2020 @ 16:01
    Graham Davis
    0

    Hi Paul... Here is mine:

    First, you will need this link:

    <script async defer src="https://connect.facebook.net/en_US/sdk.js"></script>
    

    Code

    function FacebookSignIn() {
    
    FB.init({
        appId: "[/FaceBookAppId]",  // App ID
        status: true,           // check login status
        cookie: true,           // enable cookies to allow the server to access the session
        xfbml: true,            // parse page for xfbml or html5 social plugins like login button below
        version: 'v3.3'
    });
    
    FB.login(function (response) {
        if (response.authResponse) {
            FB.api('/me', function (userInfo) {
                FB.api(
                    "/" + userInfo.id,
                    'get',
                    {
                        access_token: response.authResponse.accessToken,
                        fields: 'id, first_name, last_name,  email, picture'
                    },
                    function (loginResponse) {
                        try {
                            var data = SerializeData("#LoginForm");
                            data.FirstName = GetSafeString(loginResponse.first_name);
                            data.LastName = GetSafeString(loginResponse.last_name);
                            data.Email = GetSafeString(loginResponse.email);
                            data.Password = GetSafeString(loginResponse.id);
                            data.ImageURL = GetSafeString(loginResponse.picture.data.url);
                            SingleSignIn(data);
                        } catch (e) {
                            // alert(e);
                        }
                    }
                );
            });
        }
    });
    

    }

  • Paul Seal 400 posts 2167 karma points MVP 2x c-trib
    Feb 23, 2020 @ 16:44
    Paul Seal
    0

    Thanks Graham Is it that simple then?

  • Graham Davis 84 posts 293 karma points
    Feb 23, 2020 @ 16:51
    Graham Davis
    0

    Yes. It's pretty simple once you find the right documentation. Just make sure you have an https cert on your site, and then create your app and get your ID at https://developers.facebook.com/

    I am using it here: http://zbestpartners.com

  • Bo Jacobsen 354 posts 1531 karma points
    Feb 23, 2020 @ 17:07
    Bo Jacobsen
    0

    Hi Graham.

    I guess you would have to run FB.init() and FacebookSignIn() on every single page request?

    Do you know any way to use it with document protection?

  • Graham Davis 84 posts 293 karma points
    Feb 23, 2020 @ 17:13
    Graham Davis
    0

    FB.Init is a part of the function FacebookSignIn() and is only called when FacebookSignIn() is called. I include it in my "Layout.js" / master layout so it is possible for the user to login from any page.

  • Paul Seal 400 posts 2167 karma points MVP 2x c-trib
    Feb 23, 2020 @ 17:16
    Paul Seal
    0

    I couldn’t get it to work by just adding the script to my master view. I guess I need more details on how to get it to work.

  • Graham Davis 84 posts 293 karma points
    Feb 23, 2020 @ 17:21
    Graham Davis
    0

    Have you created your app at facebook and have they "approved" it.

    you may also have to modify function (loginResponse)….

    I am capturing the data they return and storing it to a database.

    you can change it to this to see if you are getting any data back:

    function (loginResponse) {
                    try {
                        alert(loginResponse.first_name);
                    } catch (e) {
                         alert(e);
                    }....
    
  • Graham Davis 84 posts 293 karma points
    Feb 23, 2020 @ 17:23
    Graham Davis
    0

    If you are not getting back data, check your app settings at facebook.

  • Graham Davis 84 posts 293 karma points
    Feb 23, 2020 @ 17:25
    Graham Davis
    0

    I am also assuming there aren't any difference between the US and UK.

  • Graham Davis 84 posts 293 karma points
    Feb 25, 2020 @ 15:19
    Graham Davis
    0

    Hi Paul!

    Just following up. Were you able to get it to work the way you needed?

    Graham

  • Paul Seal 400 posts 2167 karma points MVP 2x c-trib
    Feb 25, 2020 @ 22:53
    Paul Seal
    0

    Hi Graham

    Thank you so much for your effort to help me.

    I wasn't able to get it working with what you gave me, but I was able to get it working by using the firebase auth with facebook libraries.

    I might blog about it one day, but I'm just glad I got it to work.

    Cheers

    Paul

  • Graham Davis 84 posts 293 karma points
    Feb 25, 2020 @ 23:08
    Graham Davis
    0

    Hey Paul,

    Glad you got it working. Wondering if there may be difference between the US and UK.

    Be sure to "tag me" if you are attending the Umbraco Festival in Chicago this April.

    Graham

Please Sign in or register to post replies

Write your reply to:

Draft