Copied to clipboard

Flag this post as spam?

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


  • Jin Botol 134 posts 287 karma points
    Apr 16, 2018 @ 08:00
    Jin Botol
    0

    Facebook Login using Skybrud Social Error

    Hi,

    I want to create a Facebook authentication using Skybrud.Social. I've already install the package via Umbraco Packages Section.

    But got this error

    The type or namespace 'Authentication' does not exist in the namespace 'Skybrud.Social.Facebook.Responsses' (are you missing an assembly reference?)
    

    Am I missing something?

    Here's my Partial View called _Facebook

    @using Skybrud.Social.Facebook
    @using Skybrud.Social.Facebook.OAuth
    @using Skybrud.Social.Facebook.Responses.Authentication
    @using Skybrud.Social.Facebook.Scopes
    @inherits WebViewPage
    
    @{
        // Initialize and configure the OAuth client
        FacebookOAuthClient client = new FacebookOAuthClient
        {
            ClientId = "MY_CLIENT_ID",
            ClientSecret = "MY_CLIENT_SECRET",
            RedirectUri = "https://localhost:44304/"
        };
    
        if (Request.QueryString["do"] == "login")
        {
    
            // Generate a random scope
            string state = Guid.NewGuid().ToString();
    
            // Generate the session key for the state
            string stateKey = "FacebookOAuthState_" + state;
    
            // Store the state in the session of the user
            Session[stateKey] = Request.RawUrl;
    
            // Generate the authorization URL
            string authorizationUrl = client.GetAuthorizationUrl(state, FacebookScopes.Email + FacebookScopes.PublishActions);
    
            // Redirect the user
            Response.Redirect(authorizationUrl);
    
        }
        else if (Request.QueryString["code"] != null)
        {
    
            // Get the state from the query string
            string state = Request.QueryString["state"];
    
            // Get the code from the query string
            string code = Request.QueryString["code"];
    
            // Generate the session key for the state
            string stateKey = "FacebookOAuthState_" + state;
    
            if (Session[stateKey] == null)
            {
                <p>Has your session expired?</p>
                <p>
                    <a class="btn btn-default" href="@Url.Action("OAuth")?do=login">Re-try login</a>
                </p>
                return;
            }
    
            // Exchange the authorization code for an access token
            FacebookTokenResponse response = client.GetAccessTokenFromAuthCode(code);
    
            // Initialize a new service instance from an access token
            FacebookService service = FacebookService.CreateFromAccessToken(response.Body.AccessToken);
    
            <div>Access Token:</div>
            <pre>@response.Body.AccessToken</pre>
    
            <div>Expires in:</div>
            <pre>@response.Body.ExpiresIn</pre>
    
            <div>Token type:</div>
            <pre>@response.Body.TokenType</pre>
    
            return;
    
        }
    
        <p>
            <a class="btn btn-default" href="@Url.Action("OAuth")?do=login">Login with Facebook</a>
        </p>
    
    }
    

    Appreciate any help.

    Regards

    Jin

  • Jin Botol 134 posts 287 karma points
    Apr 17, 2018 @ 01:15
    Jin Botol
    0

    Hi all,

    Any ideas about this error?

    Jin

  • Jin Botol 134 posts 287 karma points
    Apr 17, 2018 @ 07:24
    Jin Botol
    0

    Hi,

    I need help for this

    Jin

  • Jin Botol 134 posts 287 karma points
    Apr 19, 2018 @ 05:22
    Jin Botol
    0

    Hi,

    I've changed my partial view into this code. source : https://social.skybrud.dk/facebook/authentication/user-access-token/

    @using Skybrud.Social.Facebook
    @using Skybrud.Social.Facebook.OAuth
    @inherits WebViewPage
    
    @{
    
        // Initialize a new instance of the OAuth client
        FacebookOAuthClient oauth = new FacebookOAuthClient
        {
            AppId = "Your application ID",
            AppSecret = "Your application secret (keep this secret)",
            RedirectUri = "The return URI (where users should be redirected after the login)"
        };
    
        // Read some input from the query string
        string code = Request.QueryString["code"];
        string action = Request.QueryString["do"];
        string error = Request.QueryString["error"];
        string errorCode = Request.QueryString["error_code"];
        string errorDescription = Request.QueryString["error_description"];
    
    
        // 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["Facebook_" + state] = redirect;
    
            // Construct the authorization URL
            string authorizatioUrl = oauth.GetAuthorizationUrl(state, FacebookScope.Email);
    
            // Redirect the user to the OAuth dialog
            Response.Redirect(authorizatioUrl);
            return;
    
        }
    
        // Handle if an error occurs during the Facebook authentication (eg. if the user cancels the login)
        if (!String.IsNullOrWhiteSpace(error))
        {
            <div class="alert alert-danger">
                <strong>Login failed</strong><br />
                @errorDescription (code: @errorCode)
            </div>
            return;
        }
    
        // Handle the state when the user is redirected back to our page after a successful login with the Facebook 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["Facebook_" + state] as string;
            if (session == null)
            {
                <div class="alert alert-danger">Session expired?</div>
                return;
            }
    
            // 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)
            <div class="alert alert-info">
                <strong>Access token:</strong> @accessToken
            </div>
    
            // 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");
    
            <div class="alert alert-info">
                <strong>ID:</strong> @response.Body.Id<br />
                <strong>Name:</strong> @response.Body.Name<br />
                <strong>Email:</strong> @response.Body.Email
            </div>
    
            return;
    
        }
    
        <a href="?do=login" class="btn btn-primary">Login with Facebook</a>
    
    }
    

    But it gives me an error : (The type or namespace name 'FacebookUserResponse' could not be found (are you missing a using directive or an assembly reference?)

    Am I missing any references? I need help. Appreciate any help!

    regards,

    Jin

Please Sign in or register to post replies

Write your reply to:

Draft