Copied to clipboard

Flag this post as spam?

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


  • Nguyen Dung Tri 106 posts 606 karma points
    Aug 01, 2016 @ 20:07
    Nguyen Dung Tri
    0

    Where is the interface of Skyburd.Social management page on Installed Umbraco CMS?

    Hi,

    I have installed Skyburd.Social package on my Umbraco, but cannot find any page on back-end that can manage the package. Like list of user, social etc...

    enter image description here

    I also want to know how to make Google appear on login page of back-end and front-end.

  • Anders Bjerner 487 posts 2989 karma points MVP 7x admin c-trib
    Aug 04, 2016 @ 19:54
    Anders Bjerner
    0

    Hi Nguyen,

    Can you elaborate a bit on what you're trying to do?

    Generally there seems to be some confusion about what this package can do. It is also worth noticing that Skybrud.Social and Skybrud.Social for Umbraco 7 are two different packages (although the latter uses the first internally).

    So to summarize the package a bit, Skybrud.Social for Umbraco 7 will not:

    • let your editors log into the Umbraco backoffice
    • let your visitors log into your website

    Technically both these use cases can be implemented using Skybrud.Social alone, but this requires some extra code.

    Skybrud.Social for Umbraco 7 will instead add a number of data types to let your editors authenticate with Facebook (or one of the other supported services) when already logged into the backoffice. The purpose of these data types is that an editor (when editing a given page where this data type is added), can authenticate with Facebook so a bit of information about the Facebook user is saved (along with an access token which at a later time can be used for accessing the Facebook API).

    The purpose of this package is not to let your editors log into the backoffice with Facebook, Twitter or similar. Or your visitors into the website for that matter.

    If you're looking to setup OAuth authentication (eg. with Google), you should have a look at this blog post from Sebastiaan from the Umbraco HQ (since this is now possible with very little code):

    http://umbraco.com/follow-us/blog-archive/2016/7/26/log-into-umbraco-with-google-authentication/

    For setting up authentication in your frontend, you can have a look at some of the documentation for Skybrud.Social - eg. for Google and Facebook:

    The documentation is for .NET / ASP.NET in general. I don't have any examples specific to Umbraco, but both examples describes how to obtain the email address of the user. You can then use the email address to validate the user against the members in Umbraco.

  • Nguyen Dung Tri 106 posts 606 karma points
    Aug 05, 2016 @ 02:10
    Nguyen Dung Tri
    0

    Hi Anders Bjerner,

    This is what I am doing so far:

    I have use your package to create a login page with google account:

    enter image description here

    Until this phase, I got Access token, ID, Name, Email from Google account. So then, how can I save those data to database and for next time user click on link "Login with Google" it will automatic login into my Umbraco?

    To archive the screen above, I have followed your code:

        @using Skybrud.Social.Google
    @using Skybrud.Social.Google.OAuth
    @inherits WebViewPage
    
    @{
    
        // Initialize a new instance of the OAuth client
        GoogleOAuthClient oauth = new GoogleOAuthClient {
            ClientId = "857672463365-n09cg4vfvktua2kvlpq2rvaa7kfku66t.apps.googleusercontent.com",
            ClientSecret = "K5dSWIybdhCCYqZrweq7ZUBE",
            RedirectUri = "http://localhost:62195/"
        };
    
        // Read some input from the query string
        string code = Request.QueryString["code"];
        string action = Request.QueryString["do"];
        string error = Request.QueryString["error"];
    
    
        // Handle the state when the user clicks our login button
        if (action == "login") {
    
            // Get the redirect URI (if present)
            string redirect = (Request.QueryString["redirect"] ?? "/");
    
            // Set the state (a unique/random value)
            string state = Guid.NewGuid().ToString();
            Session["Google_" + state] = redirect;
    
            // Construct the authorization URL
            string authorizationUrl = oauth.GetAuthorizationUrl(state, GoogleScopes.Email + GoogleScopes.Profile, GoogleAccessType.Online, GoogleApprovalPrompt.Force);
    
            // Redirect the user to the OAuth dialog
            Response.Redirect(authorizationUrl);
            return;
    
        }
    
        // Handle if an error occurs during the Google authentication (eg. if the user cancels the login)
        if (!String.IsNullOrWhiteSpace(error)) {
    <div class="alert alert-danger">
        <strong>Login failed</strong><br />
        Error received from Google: @error
    </div>
            return;
        }
    
        // Handle the state when the user is redirected back to our page after a successful login with the Google API
        if (!String.IsNullOrWhiteSpace(code)) {
    
            // Get the state from the query string
            string state = Request.QueryString["state"];
    
            // Validate state - Step 1
            if (state == null) {
    <div class="alert alert-danger">No <strong>state</strong> specified in the query string.</div>
                return;
            }
    
            // Validate state - Step 2
            string session = Session["Google_" + state] as string;
            if (session == null) {
    <div class="alert alert-danger">Session expired?</div>
                return;
            }
    
            // Remove the state from the session
            Session.Remove("Google_" + state);
    
            // Exchange the authorization code for an access token
            GoogleAccessTokenResponse response = oauth.GetAccessTokenFromAuthorizationCode(code);
            string accessToken = response.AccessToken;
    
            // Print out the access token to the user (we really shouldn't do this in a live environment)
    <div class="alert alert-info">
        <strong>Access token:</strong> @accessToken
    </div>
    
            // Initialize a new instance of the GoogleService class so we can make calls to the API
            GoogleService service = GoogleService.CreateFromAccessToken(accessToken);
    
            // Make a call to the API to get information about the authenticated user
            GoogleUserInfo user = service.GetUserInfo();
    
    <div class="alert alert-info">
        <strong>ID:</strong> @user.Id<br />
        <strong>Name:</strong> @user.Name<br />
        <strong>Email:</strong> @user.Email
    </div>
    
            return;
    
        }
    
    <a href="?do=login" class="btn btn-primary">Login with Google</a>
    
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft