Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4026806
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:01:05+00:00 2026-05-20T11:01:05+00:00

I am trying to implement facebook Connect to my cakephp Application. i am using

  • 0

I am trying to implement facebook Connect to my cakephp Application. i am using Nick’s Facebook Plugin.

I wanna implement it this way

  1. When a user Visits the Site he should be able to login via Registration on the site or Facebook Connect
  2. Existing users should be able to connect their account to their FB account
  3. People who first time login to the site using FB Connect and dont have an account on the site. should be redirected to a page where they have to enter details to complete the profile.

What i have done –
I have followed the instruction of Nick to implement it and when i click Login – it connects to my app. but i dont understand how to create a username and password associated with the Fb Connect Id. and user it against the FB token.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:01:06+00:00Added an answer on May 20, 2026 at 11:01 am

    Apparently I’m doing the same thing a little before you… 😉

    Here’s a method for Facebook login I’m using (slightly redacted and annotated):

    public function facebook($authorize = null) {
        App::import('Lib', 'Facebook.FB');
        $Fb = new FB();
    
        $session = $Fb->getSession();
    
        // not logged into Facebook and not a callback either,
        // sending user over to Facebook to log in
        if (!$session && !$authorize) {
            $params = array(
                'req_perms'  => /* the permissions you require */,
                'next'       => Router::url(array('action' => 'facebook', 'authorize'), true),
                'cancel_url' => Router::url(array('action' => 'login'), true)
            );
            $this->redirect($Fb->getLoginUrl($params));
        }
    
        // user is coming back from Facebook login,
        // assume we have a valid Facebook session
        $userInfo = $Fb->api('/me');
    
        if (!$userInfo) {
            // nope, login failed or something went wrong, aborting
            $this->Session->setFlash('Facebook login failed');
            $this->redirect(array('action' => 'login'));
        }
    
        $user = array(
            'User' => array(
                'firstname'       => $userInfo['first_name'],
                'lastname'        => $userInfo['last_name'],
                'username'        => trim(parse_url($userInfo['link'], PHP_URL_PATH), '/'),
                'email'           => $userInfo['email'],
                'email_validated' => $userInfo['verified']
            ),
            'Oauth' => array(
                'provider'        => 'facebook',
                'provider_uid'    => $userInfo['id']
            )
        );
    
        $this->oauthLogin($user);
    }
    

    This gives me an array with all the user details I could grab from Facebook and invokes ::oauthLogin, which either logs the user in with the given information or asks the user to fill in missing details and/or creates a new user record in the database. The most important part you get from the Facebook API is the $userInfo['id'] and/or email address, either of which you can use to identify the user in your database. If you’re using the AuthComponent, you can “manually” log in the user using $this->Auth->login($user_id), where $user_id is the id of the user in your own database.


    private function oauthLogin($data) {
        $this->User->create();
    
        // do we already know about these credentials?
        $oauth = $this->User->Oauth->find('first', array('conditions' => $data['Oauth']));
    
        if ($oauth) {
            // yes we do, let's try to log this user in
            if (empty($oauth['User']['id']) || !$this->Auth->login($oauth['User']['id'])) {
                $this->Session->setFlash('Login failed');
            }
            $this->redirect('/');
        }
    
        // no we don't, let's see if we know this email address already
        if (!empty($data['User']['email'])) {
            $user = $this->User->find('first', array('conditions' => array('email' => $data['User']['email'])));
            if ($user) {
                // yes we do! let's store all data in the session
                // and ask the user to associate his accounts
    
                $data['User'] = array_merge($data['User'], $user['User']);
                $data['Oauth']['user_id'] = $user['User']['id'];
    
                $this->Session->write('Oauth.associate_accounts', $data);
                $this->redirect(array('action' => 'oauth_associate_accounts'));
            }
        }
    
        // no, this is a new user, let's ask him to register        
        $this->Session->write('Oauth.register', $data);
        $this->redirect(array('action' => 'oauth_register'));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to implement the following behavior on an iPad. I have a map-centric application
Im trying to implement fade in effect to my mp3 player. I´m using FloatControl
I'm trying to implement a bookmarklet where the user will click one <img/> and
Im trying to implement a single aspx page with several externals dll's. Following Zimmergren's
Im trying to implement multi-language support in my system, the other systems at work
I'm trying to implement a B-Tree according to the chapter B-Trees in Introduction to
I am trying to implement a histogram equalization method (HE) for a UIImage in
I am trying to create smaller tabs in android -- but I can't seem
This post is an continuation of this post I have DlUser Class each object
Goal I want to create a web app with a horizontal GUI bar that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.