OAuth2.0 认证服务

安装

你可以在github上下载OAuth Server PHP,也可以用下列命令下载,不过内容都是一样的

mkdir my-oauth2-walkthrough
cd my-oauth2-walkthrough
git clone https://github.com/bshaffer/oauth2-server-php.git -b master

下载后放在根目录,因为这只是个测试!

在这之后配置数据库

Database: `oauth2db`

  1 --
  2 -- Database: `oauth2db`
  3 --
  4 
  5 -- --------------------------------------------------------
  6 
  7 --
  8 -- 表的结构 `oauth_access_tokens`
  9 --
 10 
 11 CREATE TABLE IF NOT EXISTS `oauth_access_tokens` (
 12   `access_token` varchar(40) NOT NULL,
 13   `client_id` varchar(80) NOT NULL,
 14   `user_id` varchar(255) DEFAULT NULL,
 15   `expires` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
 16   `scope` varchar(2000) DEFAULT NULL
 17 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 18 
 19 -- --------------------------------------------------------
 20 
 21 --
 22 -- 表的结构 `oauth_authorization_codes`
 23 --
 24 
 25 CREATE TABLE IF NOT EXISTS `oauth_authorization_codes` (
 26   `authorization_code` varchar(40) NOT NULL,
 27   `client_id` varchar(80) NOT NULL,
 28   `user_id` varchar(255) DEFAULT NULL,
 29   `redirect_uri` varchar(2000) DEFAULT NULL,
 30   `expires` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
 31   `scope` varchar(2000) DEFAULT NULL
 32 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 33 
 34 -- --------------------------------------------------------
 35 
 36 --
 37 -- 表的结构 `oauth_clients`
 38 --
 39 
 40 CREATE TABLE IF NOT EXISTS `oauth_clients` (
 41   `client_id` varchar(80) NOT NULL,
 42   `client_secret` varchar(80) NOT NULL,
 43   `redirect_uri` varchar(2000) NOT NULL,
 44   `grant_types` varchar(80) DEFAULT NULL,
 45   `scope` varchar(100) DEFAULT NULL,
 46   `user_id` varchar(80) DEFAULT NULL
 47 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 48 
 49 --
 50 -- 转存表中的数据 `oauth_clients`
 51 --
 52 
 53 INSERT INTO `oauth_clients` (`client_id`, `client_secret`, `redirect_uri`, `grant_types`, `scope`, `user_id`) VALUES
 54 ('testclient', 'testpass', 'https://user.endv.cn/', 'authorization_code', '', '');
 55 
 56 -- --------------------------------------------------------
 57 
 58 --
 59 -- 表的结构 `oauth_jwt`
 60 --
 61 
 62 CREATE TABLE IF NOT EXISTS `oauth_jwt` (
 63   `client_id` varchar(80) NOT NULL,
 64   `subject` varchar(80) DEFAULT NULL,
 65   `public_key` varchar(2000) DEFAULT NULL
 66 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 67 
 68 -- --------------------------------------------------------
 69 
 70 --
 71 -- 表的结构 `oauth_refresh_tokens`
 72 --
 73 
 74 CREATE TABLE IF NOT EXISTS `oauth_refresh_tokens` (
 75   `refresh_token` varchar(40) NOT NULL,
 76   `client_id` varchar(80) NOT NULL,
 77   `user_id` varchar(255) DEFAULT NULL,
 78   `expires` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
 79   `scope` varchar(2000) DEFAULT NULL
 80 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 81 
 82 -- --------------------------------------------------------
 83 
 84 --
 85 -- 表的结构 `oauth_scopes`
 86 --
 87 
 88 CREATE TABLE IF NOT EXISTS `oauth_scopes` (
 89   `scope` text,
 90   `is_default` tinyint(1) DEFAULT NULL
 91 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 92 
 93 -- --------------------------------------------------------
 94 
 95 --
 96 -- 表的结构 `oauth_users`
 97 --
 98 
 99 CREATE TABLE IF NOT EXISTS `oauth_users` (
100   `username` varchar(255) NOT NULL,
101   `password` varchar(2000) DEFAULT NULL,
102   `first_name` varchar(255) DEFAULT NULL,
103   `last_name` varchar(255) DEFAULT NULL
104 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
View Code

相关文章: