API Docs for: 0.0.8
Show:

File: client/FxaRelierClient.js

  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. /**
  5. * The Firefox Accounts Relier Client.
  6. *
  7. * @module FxaRelierClient
  8. */
  9. define([
  10. 'client/auth/api',
  11. 'client/token/api',
  12. 'client/profile/api'
  13. ], function (AuthAPI, TokenAPI, ProfileAPI) {
  14. 'use strict';
  15. /**
  16. * The entry point. Create and use an instance of the FxaRelierClient.
  17. *
  18. * @class FxaRelierClient (start here)
  19. * @constructor
  20. * @param {string} clientId - the OAuth client ID for the relier
  21. * @param {Object} [options={}] - configuration
  22. * @param {String} [options.clientSecret]
  23. * Client secret. Required to use the {{#crossLink "TokenAPI"}}Token{{/crossLink}} API.
  24. * @param {String} [options.contentHost]
  25. * Firefox Accounts Content Server host
  26. * @param {String} [options.oauthHost]
  27. * Firefox Accounts OAuth Server host
  28. * @param {String} [options.profileHost]
  29. * Firefox Accounts Profile Server host
  30. * @param {Object} [options.window]
  31. * window override, used for unit tests
  32. * @param {Object} [options.lightbox]
  33. * lightbox override, used for unit tests
  34. * @param {Object} [options.channel]
  35. * channel override, used for unit tests
  36. * @example
  37. * var fxaRelierClient = new FxaRelierClient(<client_id>);
  38. */
  39. function FxaRelierClient(clientId, options) {
  40. if (! clientId) {
  41. throw new Error('clientId is required');
  42. }
  43. /**
  44. * Authenticate users in the browser. Implements {{#crossLink "AuthAPI"}}{{/crossLink}}.
  45. * @property auth
  46. * @type {Object}
  47. *
  48. * @example
  49. * var fxaRelierClient = new FxaRelierClient('<client_id>');
  50. * fxaRelierClient.auth.signIn({
  51. * state: <state>,
  52. * redirectUri: <redirect_uri>,
  53. * scope: 'profile'
  54. * });
  55. */
  56. this.auth = new AuthAPI(clientId, options);
  57. /**
  58. * Manage tokens on the server. Implements {{#crossLink "TokenAPI"}}{{/crossLink}}.
  59. * @property token
  60. * @type {Object}
  61. *
  62. * @example
  63. * var fxaRelierClient = new FxaRelierClient('<client_id>', {
  64. * clientSecret: <client_secret>
  65. * });
  66. * fxaRelierClient.token.tradeCode(<code>)
  67. * .then(function (token) {
  68. * // do something awesome with the token like get
  69. * // profile information. See profile.
  70. * });
  71. */
  72. this.token = new TokenAPI(clientId, options);
  73. /**
  74. * Fetch profile information on the server. Implements {{#crossLink "ProfileAPI"}}{{/crossLink}}.
  75. * @property profile
  76. * @type {Object}
  77. *
  78. * @example
  79. * var fxaRelierClient = new FxaRelierClient('<client_id>', {
  80. * clientSecret: <client_secret>
  81. * });
  82. * fxaRelierClient.token.tradeCode(<code>)
  83. * .then(function (token) {
  84. * return fxaRelierClient.fetch(token);
  85. * })
  86. * .then(function (profile) {
  87. * // display some profile info.
  88. * });
  89. */
  90. this.profile = new ProfileAPI(clientId, options);
  91. }
  92. FxaRelierClient.prototype = {
  93. /**
  94. * FxaRelierClient version
  95. *
  96. * @property version
  97. * @type {String}
  98. */
  99. version: '0.0.0',
  100. auth: null
  101. };
  102. return FxaRelierClient;
  103. });