Skip to content
This repository has been archived by the owner on Nov 9, 2018. It is now read-only.

Commit

Permalink
Merge pull request #28 from rchavik/sks-migrations
Browse files Browse the repository at this point in the history
Add migrations

Reroll of #5, closes #5
  • Loading branch information
Thom Seddon committed Jul 10, 2013
2 parents edec84e + 8f20b9d commit cfdd1bc
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 3 deletions.
100 changes: 100 additions & 0 deletions Config/Migration/1339124026_firstmigrationoauth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php

class FirstMigrationOAuth extends CakeMigration {

/**
* Migration description
*
* @var string
* @access public
*/
public $description = '';

/**
* Actions to be performed
*
* @var array $migration
* @access public
*/
public $migration = array(
'up' => array(
'create_table' => array(
'access_tokens' => array(
'oauth_token' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 40, 'key' => 'primary', 'collate' => 'utf8_general_ci', 'charset' => 'utf8'),
'client_id' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 36, 'collate' => 'utf8_general_ci', 'charset' => 'utf8', 'after' => 'oauth_token'),
'user_id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'after' => 'client_id'),
'expires' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'after' => 'user_id'),
'scope' => array('type' => 'string', 'null' => true, 'default' => NULL, 'collate' => 'utf8_general_ci', 'charset' => 'utf8', 'after' => 'expires'),
'indexes' => array(
'PRIMARY' => array('column' => 'oauth_token', 'unique' => 1),
),
'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'MyISAM'),
),

'auth_codes' => array(
'code' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 40, 'key' => 'primary', 'collate' => 'utf8_general_ci', 'charset' => 'utf8'),
'client_id' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 36, 'collate' => 'utf8_general_ci', 'charset' => 'utf8', 'after' => 'code'),
'user_id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'after' => 'client_id'),
'redirect_uri' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 200, 'collate' => 'utf8_general_ci', 'charset' => 'utf8', 'after' => 'user_id'),
'expires' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'after' => 'redirect_uri'),
'scope' => array('type' => 'string', 'null' => true, 'default' => NULL, 'collate' => 'utf8_general_ci', 'charset' => 'utf8', 'after' => 'expires'),
'indexes' => array(
'PRIMARY' => array('column' => 'code', 'unique' => 1),
),
'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'MyISAM'),
),

'clients' => array(
'client_id' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 20, 'key' => 'primary', 'collate' => 'utf8_general_ci', 'charset' => 'utf8'),
'client_secret' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 40, 'collate' => 'utf8_general_ci', 'charset' => 'utf8', 'after' => 'client_id'),
'redirect_uri' => array('type' => 'string', 'null' => false, 'default' => NULL, 'collate' => 'utf8_general_ci', 'charset' => 'utf8', 'after' => 'client_secret'),
'user_id' => array('type' => 'integer', 'null' => true, 'default' => NULL, 'after' => 'redirect_uri'),
'indexes' => array(
'PRIMARY' => array('column' => 'client_id', 'unique' => 1),
),
'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'MyISAM'),
),

'refresh_tokens' => array(
'refresh_token' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 40, 'key' => 'primary', 'collate' => 'utf8_general_ci', 'charset' => 'utf8'),
'client_id' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 36, 'collate' => 'utf8_general_ci', 'charset' => 'utf8', 'after' => 'refresh_token'),
'user_id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'after' => 'client_id'),
'expires' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'after' => 'user_id'),
'scope' => array('type' => 'string', 'null' => true, 'default' => NULL, 'collate' => 'utf8_general_ci', 'charset' => 'utf8', 'after' => 'expires'),
'indexes' => array(
'PRIMARY' => array('column' => 'refresh_token', 'unique' => 1),
),
'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'MyISAM'),
),
),
),
'down' => array(
'drop_table' => array(
'access_tokens', 'auth_codes', 'clients', 'refresh_tokens'
),
),
);

/**
* Before migration callback
*
* @param string $direction, up or down direction of migration process
* @return boolean Should process continue
* @access public
*/
public function before($direction) {
return true;
}

/**
* After migration callback
*
* @param string $direction, up or down direction of migration process
* @return boolean Should process continue
* @access public
*/
public function after($direction) {
return true;
}

}
File renamed without changes.
31 changes: 28 additions & 3 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,34 @@ This is a plugin for implementing an OAuth Server/Provider in CakePHP, built on
## Requirements
[CakePHP 2.x](http://cakephp.org/)


A clone of [oauth2-php][1] in your Vendors folder
### Cloning oauth2-php
```
$ git clone git://github.com/quizlet/oauth2-php.git Vendor/oauth2-php
```
Or via submodule:

```
$ git submodule add git://github.com/quizlet/oauth2-php.git Vendor/oauth2-php
```

## Installation
First grab the tables.sql and get your tables going.

### Populate database
First we need to populate the database with the right tables.

Two ways: use schema.sql or Migrations using [Migrations Plugin from CakeDC][2]

Go to Config/Schema/schema.sql to grab the tables

**OR**

```
$ cake Migrations.migration all --plugin OAuth
```

### Cloning
Then clone this repo into a "OAuth" folder in your Plugins folder:

```
Expand All @@ -28,14 +51,15 @@ Or via submodule:
$ git submodule add git://github.com/seddonmedia/cakephp-oauth-server.git Plugin/OAuth
```


### Loading the Plugin
Load the plugin

```PHP
CakePlugin::loadAll(); // Loads all plugins at once
CakePlugin::load('OAuth'); //Just load OAuth
```

### Include component in controller
And include the component in your controller:

```PHP
Expand Down Expand Up @@ -124,4 +148,5 @@ As an example, once you have registered a client, you could then use the Authori
There is quite a bit of documentation through the code, so dive in, get your hands dirty and submit any issues here!


[1]: https://github.com/quizlet/oauth2-php
[1]: https://github.com/quizlet/oauth2-php
[2]: https://github.com/CakeDC/migrations

0 comments on commit cfdd1bc

Please sign in to comment.