Source: web-auth/redirect.js

  1. import CrossOriginAuthentication from './cross-origin-authentication';
  2. import Warn from '../helper/warn';
  3. /**
  4. * @class
  5. * @classdesc This class cannot be instantiated directly. Instead, use WebAuth.redirect
  6. * @hideconstructor
  7. */
  8. function Redirect(auth0, options) {
  9. this.webAuth = auth0;
  10. this.baseOptions = options;
  11. this.crossOriginAuthentication = new CrossOriginAuthentication(
  12. auth0,
  13. this.baseOptions
  14. );
  15. this.warn = new Warn({
  16. disableWarnings: !!options._disableDeprecationWarnings
  17. });
  18. }
  19. /**
  20. * Logs in the user with username and password using the cross origin authentication (/co/authenticate) flow. You can use either `username` or `email` to identify the user, but `username` will take precedence over `email`.
  21. * Some browsers might not be able to successfully authenticate if 3rd party cookies are disabled in your browser. [See here for more information.]{@link https://auth0.com/docs/cross-origin-authentication}.
  22. * After the /co/authenticate call, you'll have to use the {@link parseHash} function at the `redirectUri` specified in the constructor.
  23. *
  24. * @method loginWithCredentials
  25. * @deprecated This method will be released in the next major version. Use `webAuth.login` instead.
  26. * @param {Object} options options used in the {@link authorize} call after the login_ticket is acquired
  27. * @param {String} [options.username] Username (mutually exclusive with email)
  28. * @param {String} [options.email] Email (mutually exclusive with username)
  29. * @param {String} options.password Password
  30. * @param {String} [options.connection] Connection used to authenticate the user, it can be a realm name or a database connection name
  31. * @param {crossOriginLoginCallback} cb Callback function called only when an authentication error, like invalid username or password, occurs. For other types of errors, there will be a redirect to the `redirectUri`.
  32. * @memberof Redirect.prototype
  33. * @memberof Redirect.prototype
  34. */
  35. Redirect.prototype.loginWithCredentials = function (options, cb) {
  36. options.realm = options.realm || options.connection;
  37. delete options.connection;
  38. this.crossOriginAuthentication.login(options, cb);
  39. };
  40. /**
  41. * Signs up a new user and automatically logs the user in after the signup.
  42. *
  43. * @method signupAndLogin
  44. * @param {Object} options
  45. * @param {String} options.email user email address
  46. * @param {String} options.password user password
  47. * @param {String} options.connection name of the connection where the user will be created
  48. * @param {String} [options.captcha] the attempted solution for the captcha, if one was presented
  49. * @param {crossOriginLoginCallback} cb
  50. * @memberof Redirect.prototype
  51. */
  52. Redirect.prototype.signupAndLogin = function (options, cb) {
  53. var _this = this;
  54. return this.webAuth.client.dbConnection.signup(options, function (err) {
  55. if (err) {
  56. return cb(err);
  57. }
  58. options.realm = options.realm || options.connection;
  59. delete options.connection;
  60. return _this.webAuth.login(options, cb);
  61. });
  62. };
  63. export default Redirect;