Skip to content

Commit

Permalink
babel es5
Browse files Browse the repository at this point in the history
  • Loading branch information
salvoravida committed May 10, 2018
1 parent 1f64daf commit 4962a0a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"presets": ["react-app"]
"presets": ["env", "react-app"]
}
2 changes: 2 additions & 0 deletions lib/adal.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

//----------------------------------------------------------------------
Expand Down
42 changes: 30 additions & 12 deletions lib/react-adal.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.withAdalLogin = exports.AuthenticationContext = undefined;

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

exports.adalGetToken = adalGetToken;
exports.runWithAdal = runWithAdal;
exports.adalFetch = adalFetch;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _adal = require('./adal');

var _adal2 = _interopRequireDefault(_adal);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // eslint-disable-next-line

// eslint-disable-next-line
import React from 'react';
import AuthenticationContext_ from './adal';

export var AuthenticationContext = AuthenticationContext_;
var AuthenticationContext = exports.AuthenticationContext = _adal2.default;

export function adalGetToken(authContext, resourceGuiId) {
function adalGetToken(authContext, resourceGuiId) {
return new Promise(function (resolve, reject) {
authContext.acquireToken(resourceGuiId, function (message, token, msg) {
if (!msg) resolve(token);
Expand All @@ -22,7 +40,7 @@ export function adalGetToken(authContext, resourceGuiId) {
});
}

export function runWithAdal(authContext, app, doNotLogin) {
function runWithAdal(authContext, app, doNotLogin) {
//it must run in iframe to for refreshToken (parsing hash and get token)
authContext.handleWindowCallback();

Expand All @@ -42,17 +60,17 @@ export function runWithAdal(authContext, app, doNotLogin) {
}
}

export function adalFetch(authContext, resourceGuiId, fetch, url, options) {
function adalFetch(authContext, resourceGuiId, fetch, url, options) {
return adalGetToken(authContext, resourceGuiId).then(function (token) {
var o = options || {};
if (!o.headers) o.headers = {};
o.headers.Authorization = 'Bearer ' + token;
return fetch(url, options);
return fetch(url, o);
});
}

// eslint-disable-next-line
export var withAdalLogin = function withAdalLogin(authContext, resourceId) {
var withAdalLogin = exports.withAdalLogin = function withAdalLogin(authContext, resourceId) {
// eslint-disable-next-line
return function (WrappedComponent, renderLoading, renderError) {
return function (_React$Component) {
Expand Down Expand Up @@ -88,13 +106,13 @@ export var withAdalLogin = function withAdalLogin(authContext, resourceId) {
_createClass(_class2, [{
key: 'render',
value: function render() {
if (this.state.logged) return React.createElement(WrappedComponent, this.props);
if (this.state.logged) return _react2.default.createElement(WrappedComponent, this.props);
if (this.state.error) return typeof renderError === 'function' ? renderError(this.state.error) : null;
return typeof renderLoading === 'function' ? renderLoading() : null;
}
}]);

return _class2;
}(React.Component);
}(_react2.default.Component);
};
};

0 comments on commit 4962a0a

Please sign in to comment.