Copied to clipboard

Flag this post as spam?

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


  • Carlos Casalicchio 80 posts 332 karma points
    Apr 14, 2017 @ 14:59
    Carlos Casalicchio
    0

    Implementation Tutorial / Sample

    Great package. I did install it and configure all the Apis (Google, Facebook, Twitter, Instagram) in the backoffice, but am not sure how to implement it in the front-end (login page).

    Are there any tutorials or sample code for this?

  • Anders Bjerner 304 posts 1741 karma points mvp c-trib
    Apr 15, 2017 @ 00:37
    Anders Bjerner
    0

    Hi Carlos,

    Are you trying to setup a login in the frontend of your site?

    Skybrud.Social for Umbraco 7 isn't really for handling that use case. The package is for letting developers/editors authenticate in the backoffice so you as a developer have a context for calling the various APIs.

    There are other packages to handle login in the frontend - you can for instance use Skybrud.Social directly. You can read more about this at the following links:

    Facebook: http://social.skybrud.dk/facebook/authentication/user-access-token/ Twitter: https://gist.github.com/abjerner/10997293 (old WebForms example) http://social.skybrud.dk/google/authentication/

    However these examples are for ASP.NET in general.

  • Carlos Casalicchio 80 posts 332 karma points
    Apr 19, 2017 @ 20:13
    Carlos Casalicchio
    0

    Anders,

    Thank you for your response. I did implement it using your example, but now I'm getting this error:

    An active access token must be used to query information about the current user.
    
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
    Exception Details: Skybrud.Social.Facebook.Exceptions.FacebookException: An active access token must be used to query information about the current user.
    
    Source Error: 
    
    
    Line 93: 
    Line 94:         // Make a call to the API to get information about the authenticated user (aka "me")
    Line 95:         FacebookUserResponse response = service.Users.GetUser("me");
    Line 96: 
    Line 97: 
    

    How can I fix this?

    The code snippet is:

    ...
    // Remove the state from the session
            Session.Remove("facebook_" + state);
    
            // Exchange the auth code for an access token
            string accessToken = oauth.GetAccessTokenFromAuthCode(code);
    
            // Print out the access token to the user (we really shouldn't do this in a live environment)
            <strong>Access token:</strong> @accessToken
    
            // Initialize a new instance of the FacebookService class so we can make calls to the API
            FacebookService service = FacebookService.CreateFromAccessToken(accessToken);
    
            // Make a call to the API to get information about the authenticated user (aka "me")
            FacebookUserResponse response = service.Users.GetUser("me");
    
    
            if (!string.IsNullOrEmpty(accessToken))
            {
    ...
    

    When I comment out the buggy code, I see that the URL returned from facebook is

    http://localhost:19127/minha-conta/login?code=[long code]&state=86cfc634-489e-4a1e-84f8-23e45a931727#_=_
    

    Does the #_=_ messes it up?

    string accessToken = oauth.GetAccessTokenFromAuthCode(code);
    

    is returning an empty string...

  • Anders Bjerner 304 posts 1741 karma points mvp c-trib
    Apr 19, 2017 @ 20:28
    Anders Bjerner
    100

    What version of Skybrud.Social are you using? Facebook has recently deprecated an older version of their API, which affects authentication if you're using an older version of Skybrud.Social.

    Assuming this is the issue you're also experiencing, it should be fixed with the latest release:

    https://github.com/abjerner/Skybrud.Social/releases/tag/v0.9.5

  • Carlos Casalicchio 80 posts 332 karma points
    Apr 19, 2017 @ 20:53
    Carlos Casalicchio
    0

    That is probably why. I was using version 0.9.4.8

    I'll update it and let you know if that was the issue.

    Thanks!

  • Carlos Casalicchio 80 posts 332 karma points
    Apr 20, 2017 @ 22:45
    Carlos Casalicchio
    0

    Anders,

    After updating the dll it worked. I have implemented Facebook, Google, and Twitter. Now I'm looking into implementing Instagram.

    Do you have a code sample anywhere that I can follow? (twitter was different from google and facebook)

  • Anders Bjerner 304 posts 1741 karma points mvp c-trib
    Apr 21, 2017 @ 14:15
    Anders Bjerner
    0

    Instagram uses the same version of OAuth as Google and Facebook, so it should be be very similar. Other you can have a look at the Instagram dialog in my Umbraco package:

    https://github.com/abjerner/Skybrud.Social.Umbraco/blob/master/src/Skybrud.Social.Umbraco/App_Plugins/Skybrud.Social/Dialogs/InstagramOAuth.aspx.cs

    Twitter uses another version of OAuth, which is why that is different.

Please Sign in or register to post replies

Write your reply to:

Draft