oauth_common.install 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <?php
  2. /**
  3. * @file
  4. * Installation and schema related functions for the OAuth module
  5. */
  6. /**
  7. * Implements hook_schema().
  8. */
  9. function oauth_common_schema() {
  10. $schema = array();
  11. //TODO: Schemas shouldn't be translated
  12. $schema['oauth_common_context'] = array(
  13. 'description' => 'Stores contexts for OAuth common',
  14. 'export' => array(
  15. 'identifier' => 'context',
  16. 'export callback' => 'oauth_common_context_export',
  17. 'list callback' => 'oauth_common_context_list',
  18. 'key' => 'name',
  19. 'api' => array(
  20. 'owner' => 'oauth_common',
  21. 'api' => 'oauth',
  22. 'minimum_version' => 1,
  23. 'current_version' => 1,
  24. ),
  25. ),
  26. 'fields' => array(
  27. 'cid' => array(
  28. 'type' => 'serial',
  29. 'description' => 'Primary ID field for the table. Not used for anything except internal lookups.',
  30. 'not null' => TRUE,
  31. 'no export' => TRUE,
  32. ),
  33. 'name' => array(
  34. 'description' => 'The computer-readable name of the context.',
  35. 'type' => 'varchar',
  36. 'length' => 32,
  37. 'not null' => TRUE,
  38. ),
  39. 'title' => array(
  40. 'description' => 'The localizable title of the authorization context.',
  41. 'type' => 'varchar',
  42. 'length' => 100,
  43. 'not null' => TRUE,
  44. ),
  45. 'authorization_options' => array(
  46. 'description' => 'Authorization options.',
  47. 'type' => 'text',
  48. 'size' => 'big',
  49. 'not null' => TRUE,
  50. 'serialize' => TRUE,
  51. 'object default' => array(),
  52. ),
  53. 'authorization_levels' => array(
  54. 'description' => 'Authorization levels for the context.',
  55. 'type' => 'text',
  56. 'size' => 'big',
  57. 'not null' => TRUE,
  58. 'serialize' => TRUE,
  59. 'object default' => array(),
  60. ),
  61. ),
  62. 'primary key' => array('cid'),
  63. 'unique keys' => array(
  64. 'context' => array('name'),
  65. ),
  66. );
  67. $schema['oauth_common_consumer'] = _oauth_common_consumer_schema();
  68. $schema['oauth_common_provider_consumer'] = _oauth_common_provider_consumer_schema();
  69. $schema['oauth_common_token'] = _oauth_common_token_schema();
  70. $schema['oauth_common_provider_token'] = _oauth_common_provider_token_schema();
  71. $schema['oauth_common_nonce'] = array(
  72. 'description' => 'Stores timestamp against nonce for repeat attacks.',
  73. 'fields' => array(
  74. 'nonce' => array(
  75. 'description' => 'The random string used on each request.',
  76. 'type' => 'varchar',
  77. 'length' => 255,
  78. 'not null' => TRUE
  79. ),
  80. 'timestamp' => array(
  81. 'description' => 'The timestamp of the request.',
  82. 'type' => 'int',
  83. 'not null' => TRUE
  84. ),
  85. 'token_key' => array(
  86. 'description' => 'Token key.',
  87. // This is our own internal key - it's 0 or 32 characters long
  88. 'type' => 'varchar',
  89. 'length' => 32,
  90. 'not null' => TRUE,
  91. ),
  92. ),
  93. 'primary key' => array('nonce'),
  94. 'indexes' => array(
  95. 'timekey' => array('timestamp', 'token_key'),
  96. ),
  97. );
  98. return $schema;
  99. }
  100. /**
  101. * Contains the consumer schema - used by oauth_common_schema() as well as latest related update function
  102. */
  103. function _oauth_common_consumer_schema() {
  104. return array(
  105. 'description' => 'Keys and secrets for OAuth consumers, both those provided by this site and other sites.',
  106. 'fields' => array(
  107. 'csid' => array(
  108. 'type' => 'serial',
  109. 'description' => 'Primary ID field for the table. Not used for anything except internal lookups.',
  110. 'not null' => TRUE,
  111. ),
  112. 'key_hash' => array(
  113. 'description' => 'SHA1-hash of consumer_key.',
  114. 'type' => 'char',
  115. 'length' => 40,
  116. 'not null' => TRUE,
  117. ),
  118. // Key is a reserved word in MySQL so lets avoid that
  119. 'consumer_key' => array(
  120. 'description' => 'Consumer key.',
  121. 'type' => 'text',
  122. 'not null' => TRUE,
  123. ),
  124. 'secret' => array(
  125. 'description' => 'Consumer secret.',
  126. 'type' => 'text',
  127. 'not null' => TRUE,
  128. ),
  129. 'configuration' => array(
  130. 'description' => 'Consumer configuration',
  131. 'type' => 'text',
  132. 'serialized' => TRUE,
  133. 'size' => 'big',
  134. 'not null' => TRUE,
  135. 'object default' => array(),
  136. ),
  137. ),
  138. 'primary key' => array('csid'),
  139. 'indexes' => array(
  140. 'key_hash' => array('key_hash'),
  141. ),
  142. );
  143. }
  144. /**
  145. * Contains the provider consumer schema - used by oauth_common_schema() as well as latest related update function
  146. */
  147. function _oauth_common_provider_consumer_schema() {
  148. return array(
  149. 'description' => 'Additional data for OAuth consumers provided by this site.',
  150. 'fields' => array(
  151. 'csid' => array(
  152. 'description' => 'The {oauth_common_consumer}.csid this data is related to.',
  153. 'type' => 'int',
  154. 'unsigned' => TRUE,
  155. 'default' => 0
  156. ),
  157. 'consumer_key' => array(
  158. 'description' => 'Consumer key.',
  159. // This is our own internal key - it's always 32 characters long
  160. 'type' => 'char',
  161. 'length' => 32,
  162. 'not null' => TRUE,
  163. ),
  164. 'created' => array(
  165. 'type' => 'int',
  166. 'not null' => TRUE,
  167. 'default' => 0,
  168. 'description' => 'The time that the consumer was created, as a Unix timestamp.',
  169. ),
  170. 'changed' => array(
  171. 'type' => 'int',
  172. 'not null' => TRUE,
  173. 'default' => 0,
  174. 'description' => 'The last time the consumer was edited, as a Unix timestamp.',
  175. ),
  176. 'uid' => array(
  177. 'description' => 'The application owner.',
  178. 'type' => 'int',
  179. 'unsigned' => TRUE,
  180. 'not null' => TRUE,
  181. ),
  182. 'name' => array(
  183. 'description' => 'The application name.',
  184. 'type' => 'varchar',
  185. 'length' => 128,
  186. 'not null' => TRUE,
  187. ),
  188. 'context' => array(
  189. 'description' => 'The application context.',
  190. 'type' => 'varchar',
  191. 'length' => 32,
  192. 'not null' => TRUE,
  193. 'default' => '',
  194. ),
  195. 'callback_url' => array(
  196. 'description' => 'Callback url.',
  197. 'type' => 'varchar',
  198. 'length' => 255,
  199. 'not null' => TRUE,
  200. ),
  201. ),
  202. 'primary key' => array('consumer_key'),
  203. 'unique keys' => array(
  204. 'csid' => array('csid'),
  205. ),
  206. 'indexes' => array(
  207. 'uid' => array('uid'),
  208. ),
  209. 'foreign keys' => array(
  210. 'oauth_common_consumer' => array(
  211. 'table' => 'oauth_common_consumer',
  212. 'columns' => array('csid' => 'csid')
  213. ),
  214. 'users' => array(
  215. 'table' => 'users',
  216. 'columns' => array('uid' => 'uid'),
  217. ),
  218. ),
  219. );
  220. }
  221. /**
  222. * Contains the token schema - used by oauth_common_schema() as well as latest related update function
  223. */
  224. function _oauth_common_token_schema() {
  225. return array(
  226. 'description' => 'Tokens stored on behalf of providers or consumers for request and services accesses.',
  227. 'fields' => array(
  228. 'tid' => array(
  229. 'type' => 'serial',
  230. 'description' => 'Primary ID field for the table. Not used for anything except internal lookups.',
  231. 'not null' => TRUE,
  232. ),
  233. 'csid' => array(
  234. 'description' => 'The {oauth_common_consumer}.csid this token is related to.',
  235. 'type' => 'int',
  236. 'unsigned' => TRUE,
  237. 'not null' => TRUE,
  238. 'default' => 0
  239. ),
  240. 'key_hash' => array(
  241. 'description' => 'SHA1-hash of token_key.',
  242. 'type' => 'char',
  243. 'length' => 40,
  244. 'not null' => TRUE,
  245. ),
  246. // Key is a reserved word in MySQL so lets avoid that
  247. 'token_key' => array(
  248. 'description' => 'Token key.',
  249. 'type' => 'text',
  250. 'not null' => TRUE,
  251. ),
  252. 'secret' => array(
  253. 'description' => 'Token secret.',
  254. 'type' => 'text',
  255. 'not null' => TRUE,
  256. ),
  257. 'expires' => array(
  258. 'type' => 'int',
  259. 'not null' => TRUE,
  260. 'default' => 0,
  261. 'description' => 'The expiry time for the token, as a Unix timestamp.',
  262. ),
  263. 'type' => array(
  264. 'description' => 'Token type: request or access.',
  265. 'type' => 'int',
  266. 'size' => 'tiny',
  267. 'not null' => TRUE,
  268. 'default' => 1, //OAUTH_COMMON_TOKEN_TYPE_ACCESS
  269. ),
  270. 'uid' => array(
  271. 'description' => 'User ID from {user}.uid.',
  272. 'type' => 'int',
  273. 'unsigned' => TRUE,
  274. 'not null' => TRUE,
  275. 'default' => 0,
  276. ),
  277. ),
  278. 'primary key' => array('tid'),
  279. 'indexes' => array(
  280. 'key_hash' => array('key_hash'),
  281. ),
  282. 'foreign keys' => array(
  283. 'oauth_common_consumer' => array(
  284. 'table' => 'oauth_common_consumer',
  285. 'columns' => array('csid' => 'csid')
  286. ),
  287. 'users' => array(
  288. 'table' => 'users',
  289. 'columns' => array('uid' => 'uid'),
  290. ),
  291. ),
  292. );
  293. }
  294. /**
  295. * Contains the provider token schema - used by oauth_common_schema() as well as latest related update function
  296. */
  297. function _oauth_common_provider_token_schema() {
  298. return array(
  299. 'description' => 'Additional data for OAuth tokens provided by this site.',
  300. 'fields' => array(
  301. 'tid' => array(
  302. 'description' => 'The {oauth_common_token}.tid this data is related to.',
  303. 'type' => 'int',
  304. 'unsigned' => TRUE,
  305. 'default' => 0
  306. ),
  307. 'token_key' => array(
  308. 'description' => 'Token key.',
  309. // This is our own internal key - it's always 32 characters long
  310. 'type' => 'char',
  311. 'length' => 32,
  312. 'not null' => TRUE,
  313. ),
  314. 'created' => array(
  315. 'type' => 'int',
  316. 'not null' => TRUE,
  317. 'default' => 0,
  318. 'description' => 'The time that the token was created, as a Unix timestamp.',
  319. ),
  320. 'changed' => array(
  321. 'type' => 'int',
  322. 'not null' => TRUE,
  323. 'default' => 0,
  324. 'description' => 'The last time the token was edited, as a Unix timestamp.',
  325. ),
  326. 'services' => array(
  327. 'description' => 'An array of services that the user allowed the consumer to access.',
  328. 'type' => 'text',
  329. ),
  330. 'authorized' => array(
  331. 'description' => 'In case its a request token, it checks if the user already authorized the consumer to get an access token.',
  332. 'type' => 'int',
  333. 'size' => 'tiny',
  334. 'not null' => TRUE,
  335. 'default' => 0,
  336. ),
  337. ),
  338. 'primary key' => array('token_key'),
  339. 'unique keys' => array(
  340. 'tid' => array('tid'),
  341. ),
  342. 'foreign keys' => array(
  343. 'oauth_common_token' => array(
  344. 'table' => 'oauth_common_token',
  345. 'columns' => array('tid' => 'tid')
  346. ),
  347. ),
  348. );
  349. }