Skip to content

Commit

Permalink
[mysql] Add OAuth2 framework tables (OpenAPITools#5807)
Browse files Browse the repository at this point in the history
* Add OAuth table schemas

* Refresh samples

* Expand password column length

* Add copyright notice of OAuth2 schema author

* Refresh samples
  • Loading branch information
ybelenko authored and michaelpro1 committed May 7, 2020
1 parent cac882a commit a58a296
Show file tree
Hide file tree
Showing 2 changed files with 218 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,113 @@ CREATE TABLE IF NOT EXISTS {{#defaultDatabaseName}}`{{{defaultDatabaseName}}}`.{
{{/x-mysqlSchema}}
{{/vendorExtensions}}

{{/isArrayModel}}{{/hasVars}}{{/model}}{{/models}}
{{/isArrayModel}}{{/hasVars}}{{/model}}{{/models}}
{{#hasOAuthMethods}}
--
-- OAuth2 framework tables
-- Thanks to https://github.com/dsquier/oauth2-server-php-mysql repo
--

--
-- Table structure for table `oauth_clients`
--
CREATE TABLE IF NOT EXISTS `oauth_clients` (
`client_id` VARCHAR(80) NOT NULL,
`client_secret` VARCHAR(80) DEFAULT NULL,
`redirect_uri` VARCHAR(2000) DEFAULT NULL,
`grant_types` VARCHAR(80) DEFAULT NULL,
`scope` VARCHAR(4000) DEFAULT NULL,
`user_id` VARCHAR(80) DEFAULT NULL,
PRIMARY KEY (`client_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Table structure for table `oauth_access_tokens`
--
CREATE TABLE IF NOT EXISTS `oauth_access_tokens` (
`access_token` VARCHAR(40) NOT NULL,
`client_id` VARCHAR(80) DEFAULT NULL,
`user_id` VARCHAR(80) DEFAULT NULL,
`expires` TIMESTAMP NOT NULL,
`scope` VARCHAR(4000) DEFAULT NULL,
PRIMARY KEY (`access_token`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Table structure for table `oauth_authorization_codes`
--
CREATE TABLE IF NOT EXISTS `oauth_authorization_codes` (
`authorization_code` VARCHAR(40) NOT NULL,
`client_id` VARCHAR(80) DEFAULT NULL,
`user_id` VARCHAR(80) DEFAULT NULL,
`redirect_uri` VARCHAR(2000) NOT NULL,
`expires` TIMESTAMP NOT NULL,
`scope` VARCHAR(4000) DEFAULT NULL,
`id_token` VARCHAR(1000) DEFAULT NULL,
PRIMARY KEY (`authorization_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Table structure for table `oauth_refresh_tokens`
--
CREATE TABLE IF NOT EXISTS `oauth_refresh_tokens` (
`refresh_token` VARCHAR(40) NOT NULL,
`client_id` VARCHAR(80) DEFAULT NULL,
`user_id` VARCHAR(80) DEFAULT NULL,
`expires` TIMESTAMP on update CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`scope` VARCHAR(4000) DEFAULT NULL,
PRIMARY KEY (`refresh_token`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Table structure for table `oauth_users`
--
CREATE TABLE IF NOT EXISTS `oauth_users` (
`username` VARCHAR(80) DEFAULT NULL,
`password` VARCHAR(255) DEFAULT NULL,
`first_name` VARCHAR(80) DEFAULT NULL,
`last_name` VARCHAR(80) DEFAULT NULL,
`email` VARCHAR(2000) DEFAULT NULL,
`email_verified` TINYINT(1) DEFAULT NULL,
`scope` VARCHAR(4000) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Table structure for table `oauth_scopes`
--
CREATE TABLE IF NOT EXISTS `oauth_scopes` (
`scope` VARCHAR(80) NOT NULL,
`is_default` TINYINT(1) DEFAULT NULL,
PRIMARY KEY (`scope`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Table structure for table `oauth_jwt`
--
CREATE TABLE IF NOT EXISTS `oauth_jwt` (
`client_id` VARCHAR(80) NOT NULL,
`subject` VARCHAR(80) DEFAULT NULL,
`public_key` VARCHAR(2000) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Table structure for table `oauth_jti`
--
CREATE TABLE IF NOT EXISTS `oauth_jti` (
`issuer` VARCHAR(80) NOT NULL,
`subject` VARCHAR(80) DEFAULT NULL,
`audiance` VARCHAR(80) DEFAULT NULL,
`expires` TIMESTAMP NOT NULL,
`jti` VARCHAR(2000) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Table structure for table `oauth_public_keys`
--
CREATE TABLE IF NOT EXISTS `oauth_public_keys` (
`client_id` VARCHAR(80) DEFAULT NULL,
`public_key` VARCHAR(2000) DEFAULT NULL,
`private_key` VARCHAR(2000) DEFAULT NULL,
`encryption_algorithm` VARCHAR(100) DEFAULT 'RS256'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
{{/hasOAuthMethods}}
108 changes: 108 additions & 0 deletions samples/schema/petstore/mysql/mysql_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -493,3 +493,111 @@ CREATE TABLE IF NOT EXISTS `XmlItem` (
`prefix_ns_wrapped_array` JSON DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


--
-- OAuth2 framework tables
-- Thanks to https://github.com/dsquier/oauth2-server-php-mysql repo
--

--
-- Table structure for table `oauth_clients`
--
CREATE TABLE IF NOT EXISTS `oauth_clients` (
`client_id` VARCHAR(80) NOT NULL,
`client_secret` VARCHAR(80) DEFAULT NULL,
`redirect_uri` VARCHAR(2000) DEFAULT NULL,
`grant_types` VARCHAR(80) DEFAULT NULL,
`scope` VARCHAR(4000) DEFAULT NULL,
`user_id` VARCHAR(80) DEFAULT NULL,
PRIMARY KEY (`client_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Table structure for table `oauth_access_tokens`
--
CREATE TABLE IF NOT EXISTS `oauth_access_tokens` (
`access_token` VARCHAR(40) NOT NULL,
`client_id` VARCHAR(80) DEFAULT NULL,
`user_id` VARCHAR(80) DEFAULT NULL,
`expires` TIMESTAMP NOT NULL,
`scope` VARCHAR(4000) DEFAULT NULL,
PRIMARY KEY (`access_token`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Table structure for table `oauth_authorization_codes`
--
CREATE TABLE IF NOT EXISTS `oauth_authorization_codes` (
`authorization_code` VARCHAR(40) NOT NULL,
`client_id` VARCHAR(80) DEFAULT NULL,
`user_id` VARCHAR(80) DEFAULT NULL,
`redirect_uri` VARCHAR(2000) NOT NULL,
`expires` TIMESTAMP NOT NULL,
`scope` VARCHAR(4000) DEFAULT NULL,
`id_token` VARCHAR(1000) DEFAULT NULL,
PRIMARY KEY (`authorization_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Table structure for table `oauth_refresh_tokens`
--
CREATE TABLE IF NOT EXISTS `oauth_refresh_tokens` (
`refresh_token` VARCHAR(40) NOT NULL,
`client_id` VARCHAR(80) DEFAULT NULL,
`user_id` VARCHAR(80) DEFAULT NULL,
`expires` TIMESTAMP on update CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`scope` VARCHAR(4000) DEFAULT NULL,
PRIMARY KEY (`refresh_token`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Table structure for table `oauth_users`
--
CREATE TABLE IF NOT EXISTS `oauth_users` (
`username` VARCHAR(80) DEFAULT NULL,
`password` VARCHAR(255) DEFAULT NULL,
`first_name` VARCHAR(80) DEFAULT NULL,
`last_name` VARCHAR(80) DEFAULT NULL,
`email` VARCHAR(2000) DEFAULT NULL,
`email_verified` TINYINT(1) DEFAULT NULL,
`scope` VARCHAR(4000) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Table structure for table `oauth_scopes`
--
CREATE TABLE IF NOT EXISTS `oauth_scopes` (
`scope` VARCHAR(80) NOT NULL,
`is_default` TINYINT(1) DEFAULT NULL,
PRIMARY KEY (`scope`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Table structure for table `oauth_jwt`
--
CREATE TABLE IF NOT EXISTS `oauth_jwt` (
`client_id` VARCHAR(80) NOT NULL,
`subject` VARCHAR(80) DEFAULT NULL,
`public_key` VARCHAR(2000) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Table structure for table `oauth_jti`
--
CREATE TABLE IF NOT EXISTS `oauth_jti` (
`issuer` VARCHAR(80) NOT NULL,
`subject` VARCHAR(80) DEFAULT NULL,
`audiance` VARCHAR(80) DEFAULT NULL,
`expires` TIMESTAMP NOT NULL,
`jti` VARCHAR(2000) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Table structure for table `oauth_public_keys`
--
CREATE TABLE IF NOT EXISTS `oauth_public_keys` (
`client_id` VARCHAR(80) DEFAULT NULL,
`public_key` VARCHAR(2000) DEFAULT NULL,
`private_key` VARCHAR(2000) DEFAULT NULL,
`encryption_algorithm` VARCHAR(100) DEFAULT 'RS256'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

0 comments on commit a58a296

Please sign in to comment.