/mod/oauth_api/vendors/oauth/library/store/mysql/mysql.sql

https://github.com/wangaiying/elgg4ysu · SQL · 219 lines · 180 code · 39 blank · 0 comment · 10 complexity · f668360f6bfc64ef221b4c4fbbbbd272 MD5 · raw file

  1. # Datamodel for OAuthStoreMySQL
  2. #
  3. # You need to add the foreign key constraints for the user ids your are using.
  4. # I have commented the constraints out, just look for 'usa_id_ref' to enable them.
  5. #
  6. # The --SPLIT-- markers are used by the install.php script
  7. #
  8. # @version $Id: mysql.sql 51 2008-10-15 15:15:47Z marcw@pobox.com $
  9. # @author Marc Worrell
  10. #
  11. # Changes:
  12. #
  13. # 2008-10-15 (on r48) Added ttl to consumer and server tokens, added named server tokens
  14. #
  15. # ALTER TABLE oauth_server_token
  16. # ADD ost_token_ttl datetime not null default '9999-12-31',
  17. # ADD KEY (ost_token_ttl);
  18. #
  19. # ALTER TABLE oauth_consumer_token
  20. # ADD oct_name varchar(64) binary not null default '',
  21. # ADD oct_token_ttl datetime not null default '9999-12-31',
  22. # DROP KEY oct_usa_id_ref,
  23. # ADD UNIQUE KEY (oct_usa_id_ref, oct_ocr_id_ref, oct_token_type, oct_name),
  24. # ADD KEY (oct_token_ttl);
  25. #
  26. # 2008-09-09 (on r5) Added referrer host to server access token
  27. #
  28. # ALTER TABLE oauth_server_token ADD ost_referrer_host VARCHAR(128) NOT NULL;
  29. #
  30. #
  31. # Log table to hold all OAuth request when you enabled logging
  32. #
  33. CREATE TABLE IF NOT EXISTS oauth_log (
  34. olg_id int(11) not null auto_increment,
  35. olg_osr_consumer_key varchar(64) binary,
  36. olg_ost_token varchar(64) binary,
  37. olg_ocr_consumer_key varchar(64) binary,
  38. olg_oct_token varchar(64) binary,
  39. olg_usa_id_ref int(11),
  40. olg_received text not null,
  41. olg_sent text not null,
  42. olg_base_string text not null,
  43. olg_notes text not null,
  44. olg_timestamp timestamp not null default current_timestamp,
  45. olg_remote_ip bigint not null,
  46. primary key (olg_id),
  47. key (olg_osr_consumer_key, olg_id),
  48. key (olg_ost_token, olg_id),
  49. key (olg_ocr_consumer_key, olg_id),
  50. key (olg_oct_token, olg_id),
  51. key (olg_usa_id_ref, olg_id)
  52. # , foreign key (olg_usa_id_ref) references any_user_auth (usa_id_ref)
  53. # on update cascade
  54. # on delete cascade
  55. ) engine=InnoDB default charset=utf8;
  56. #--SPLIT--
  57. #
  58. # /////////////////// CONSUMER SIDE ///////////////////
  59. #
  60. # This is a registry of all consumer codes we got from other servers
  61. # The consumer_key/secret is obtained from the server
  62. # We also register the server uri, so that we can find the consumer key and secret
  63. # for a certain server. From that server we can check if we have a token for a
  64. # particular user.
  65. CREATE TABLE IF NOT EXISTS oauth_consumer_registry (
  66. ocr_id int(11) not null auto_increment,
  67. ocr_usa_id_ref int(11),
  68. ocr_consumer_key varchar(64) binary not null,
  69. ocr_consumer_secret varchar(64) binary not null,
  70. ocr_signature_methods varchar(255) not null default 'HMAC-SHA1,PLAINTEXT',
  71. ocr_server_uri varchar(255) not null,
  72. ocr_server_uri_host varchar(128) not null,
  73. ocr_server_uri_path varchar(128) binary not null,
  74. ocr_request_token_uri varchar(255) not null,
  75. ocr_authorize_uri varchar(255) not null,
  76. ocr_access_token_uri varchar(255) not null,
  77. ocr_timestamp timestamp not null default current_timestamp,
  78. primary key (ocr_id),
  79. unique key (ocr_consumer_key, ocr_usa_id_ref),
  80. key (ocr_server_uri),
  81. key (ocr_server_uri_host, ocr_server_uri_path),
  82. key (ocr_usa_id_ref)
  83. # , foreign key (ocr_usa_id_ref) references any_user_auth(usa_id_ref)
  84. # on update cascade
  85. # on delete set null
  86. ) engine=InnoDB default charset=utf8;
  87. #--SPLIT--
  88. # Table used to sign requests for sending to a server by the consumer
  89. # The key is defined for a particular user. Only one single named
  90. # key is allowed per user/server combination
  91. CREATE TABLE IF NOT EXISTS oauth_consumer_token (
  92. oct_id int(11) not null auto_increment,
  93. oct_ocr_id_ref int(11) not null,
  94. oct_usa_id_ref int(11) not null,
  95. oct_name varchar(64) binary not null default '',
  96. oct_token varchar(64) binary not null,
  97. oct_token_secret varchar(64) binary not null,
  98. oct_token_type enum('request','authorized','access'),
  99. oct_token_ttl datetime not null default '9999-12-31',
  100. oct_timestamp timestamp not null default current_timestamp,
  101. primary key (oct_id),
  102. unique key (oct_ocr_id_ref, oct_token),
  103. unique key (oct_usa_id_ref, oct_ocr_id_ref, oct_token_type, oct_name),
  104. key (oct_token_ttl),
  105. foreign key (oct_ocr_id_ref) references oauth_consumer_registry (ocr_id)
  106. on update cascade
  107. on delete cascade
  108. # , foreign key (oct_usa_id_ref) references any_user_auth (usa_id_ref)
  109. # on update cascade
  110. # on delete cascade
  111. ) engine=InnoDB default charset=utf8;
  112. #--SPLIT--
  113. #
  114. # ////////////////// SERVER SIDE /////////////////
  115. #
  116. # Table holding consumer key/secret combos an user issued to consumers.
  117. # Used for verification of incoming requests.
  118. CREATE TABLE IF NOT EXISTS oauth_server_registry (
  119. osr_id int(11) not null auto_increment,
  120. osr_usa_id_ref int(11),
  121. osr_consumer_key varchar(64) binary not null,
  122. osr_consumer_secret varchar(64) binary not null,
  123. osr_enabled tinyint(1) not null default '1',
  124. osr_status varchar(16) not null,
  125. osr_requester_name varchar(64) not null,
  126. osr_requester_email varchar(64) not null,
  127. osr_callback_uri varchar(255) not null,
  128. osr_application_uri varchar(255) not null,
  129. osr_application_title varchar(80) not null,
  130. osr_application_descr text not null,
  131. osr_application_notes text not null,
  132. osr_application_type varchar(20) not null,
  133. osr_application_commercial tinyint(1) not null default '0',
  134. osr_issue_date datetime not null,
  135. osr_timestamp timestamp not null default current_timestamp,
  136. primary key (osr_id),
  137. unique key (osr_consumer_key),
  138. key (osr_usa_id_ref)
  139. # , foreign key (osr_usa_id_ref) references any_user_auth(usa_id_ref)
  140. # on update cascade
  141. # on delete set null
  142. ) engine=InnoDB default charset=utf8;
  143. #--SPLIT--
  144. # Nonce used by a certain consumer, every used nonce should be unique, this prevents
  145. # replaying attacks. We need to store all timestamp/nonce combinations for the
  146. # maximum timestamp received.
  147. CREATE TABLE IF NOT EXISTS oauth_server_nonce (
  148. osn_id int(11) not null auto_increment,
  149. osn_consumer_key varchar(64) binary not null,
  150. osn_token varchar(64) binary not null,
  151. osn_timestamp bigint not null,
  152. osn_nonce varchar(80) binary not null,
  153. primary key (osn_id),
  154. unique key (osn_consumer_key, osn_token, osn_timestamp, osn_nonce)
  155. ) engine=InnoDB default charset=utf8;
  156. #--SPLIT--
  157. # Table used to verify signed requests sent to a server by the consumer
  158. # When the verification is succesful then the associated user id is returned.
  159. CREATE TABLE IF NOT EXISTS oauth_server_token (
  160. ost_id int(11) not null auto_increment,
  161. ost_osr_id_ref int(11) not null,
  162. ost_usa_id_ref int(11) not null,
  163. ost_token varchar(64) binary not null,
  164. ost_token_secret varchar(64) binary not null,
  165. ost_token_type enum('request','access'),
  166. ost_authorized tinyint(1) not null default '0',
  167. ost_referrer_host varchar(128) not null,
  168. ost_token_ttl datetime not null default '9999-12-31',
  169. ost_timestamp timestamp not null default current_timestamp,
  170. primary key (ost_id),
  171. unique key (ost_token),
  172. key (ost_osr_id_ref),
  173. key (ost_token_ttl),
  174. foreign key (ost_osr_id_ref) references oauth_server_registry (osr_id)
  175. on update cascade
  176. on delete cascade
  177. # , foreign key (ost_usa_id_ref) references any_user_auth (usa_id_ref)
  178. # on update cascade
  179. # on delete cascade
  180. ) engine=InnoDB default charset=utf8;