Book Image

CakePHP 2 Application Cookbook

By : James Watts, Cake Software Foundation, Inc.
Book Image

CakePHP 2 Application Cookbook

By: James Watts, Cake Software Foundation, Inc.

Overview of this book

Table of Contents (20 chapters)
CakePHP 2 Application Cookbook
Credits
Foreword
About the Authors
About the Reviewer
www.PacktPub.com
Preface
Index

Facebook authentication


These days, you don't always need to worry about creating user accounts; you can simply use an external service instead, and let the user connect their third-party or social account with your application.

Popular services such as Facebook, Google, and Twitter all provide an API to define and connect a new application. Focusing on Facebook, their services rely on OAuth for a token-based authorization system. OAuth is an open protocol for authentication and authorization; it allows you to use a third-party service to identify a user without directly accessing their credentials (password).

In this recipe, we'll be using Opauth to connect our CakePHP application with Facebook.

Getting ready

For this recipe, we'll need a table for our users, so create one with the following SQL statement:

CREATE TABLE users (
  id VARCHAR(36) NOT NULL,
  username VARCHAR(255) NOT NULL,
  password VARCHAR(128) DEFAULT NULL,
  email VARCHAR(255) DEFAULT NULL,
  active TINYINT(1) DEFAULT '1',...