2017-08-10 01:56:27 +00:00
|
|
|
import React, {PureComponent} from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2017-07-31 17:29:36 +00:00
|
|
|
import {AUTH_BASIC, AUTH_DIGEST, AUTH_BEARER, AUTH_NTLM, AUTH_OAUTH_1, AUTH_OAUTH_2, AUTH_AWS_IAM, AUTH_NETRC} from '../../../../common/constants';
|
2017-03-23 22:10:42 +00:00
|
|
|
import BasicAuth from './basic-auth';
|
2017-03-28 22:45:23 +00:00
|
|
|
import DigestAuth from './digest-auth';
|
2017-06-01 13:18:42 +00:00
|
|
|
import BearerAuth from './bearer-auth';
|
2017-03-28 22:45:23 +00:00
|
|
|
import NTLMAuth from './ntlm-auth';
|
2017-07-31 17:29:36 +00:00
|
|
|
import OAuth2Auth from './o-auth-2-auth';
|
2017-07-12 21:01:14 +00:00
|
|
|
import AWSAuth from './aws-auth';
|
2017-07-31 17:29:36 +00:00
|
|
|
import NetrcAuth from './netrc-auth';
|
2017-03-23 22:10:42 +00:00
|
|
|
import autobind from 'autobind-decorator';
|
2017-07-03 18:45:16 +00:00
|
|
|
import Link from '../../base/link';
|
2017-03-23 22:10:42 +00:00
|
|
|
|
|
|
|
@autobind
|
|
|
|
class AuthWrapper extends PureComponent {
|
|
|
|
renderEditor () {
|
|
|
|
const {
|
|
|
|
oAuth2Token,
|
|
|
|
request,
|
|
|
|
handleRender,
|
|
|
|
handleGetRenderContext,
|
|
|
|
handleUpdateSettingsShowPasswords,
|
|
|
|
onChange,
|
|
|
|
showPasswords
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
const {authentication} = request;
|
|
|
|
|
|
|
|
if (authentication.type === AUTH_BASIC) {
|
|
|
|
return (
|
|
|
|
<BasicAuth
|
|
|
|
authentication={authentication}
|
|
|
|
handleRender={handleRender}
|
|
|
|
handleGetRenderContext={handleGetRenderContext}
|
|
|
|
handleUpdateSettingsShowPasswords={handleUpdateSettingsShowPasswords}
|
|
|
|
onChange={onChange}
|
|
|
|
showPasswords={showPasswords}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
} else if (authentication.type === AUTH_OAUTH_2) {
|
|
|
|
return (
|
2017-07-31 17:29:36 +00:00
|
|
|
<OAuth2Auth
|
2017-03-23 22:10:42 +00:00
|
|
|
oAuth2Token={oAuth2Token}
|
|
|
|
request={request}
|
|
|
|
handleRender={handleRender}
|
|
|
|
handleGetRenderContext={handleGetRenderContext}
|
|
|
|
handleUpdateSettingsShowPasswords={handleUpdateSettingsShowPasswords}
|
|
|
|
onChange={onChange}
|
|
|
|
showPasswords={showPasswords}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
} else if (authentication.type === AUTH_OAUTH_1) {
|
|
|
|
return (
|
|
|
|
<div className="vertically-center text-center">
|
2017-07-03 20:51:55 +00:00
|
|
|
<div className="pad text-sm text-center">
|
2017-07-03 18:45:16 +00:00
|
|
|
<i className="fa fa-commenting super-faint" style={{fontSize: '8rem', opacity: 0.3}}/>
|
2017-07-03 20:51:55 +00:00
|
|
|
<p className="faint pad-top">
|
|
|
|
Want OAuth 1.0? Please upvote
|
|
|
|
the <Link href="https://github.com/getinsomnia/insomnia/issues/197">
|
|
|
|
Issue on GitHub
|
|
|
|
</Link>
|
|
|
|
</p>
|
|
|
|
</div>
|
2017-03-23 22:10:42 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} else if (authentication.type === AUTH_DIGEST) {
|
|
|
|
return (
|
2017-03-28 22:45:23 +00:00
|
|
|
<DigestAuth
|
|
|
|
authentication={authentication}
|
|
|
|
handleRender={handleRender}
|
|
|
|
handleGetRenderContext={handleGetRenderContext}
|
|
|
|
handleUpdateSettingsShowPasswords={handleUpdateSettingsShowPasswords}
|
|
|
|
onChange={onChange}
|
|
|
|
showPasswords={showPasswords}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
} else if (authentication.type === AUTH_NTLM) {
|
|
|
|
return (
|
|
|
|
<NTLMAuth
|
|
|
|
authentication={authentication}
|
|
|
|
handleRender={handleRender}
|
|
|
|
handleGetRenderContext={handleGetRenderContext}
|
|
|
|
handleUpdateSettingsShowPasswords={handleUpdateSettingsShowPasswords}
|
|
|
|
onChange={onChange}
|
|
|
|
showPasswords={showPasswords}
|
|
|
|
/>
|
2017-03-23 22:10:42 +00:00
|
|
|
);
|
2017-06-01 13:18:42 +00:00
|
|
|
} else if (authentication.type === AUTH_BEARER) {
|
|
|
|
return (
|
|
|
|
<BearerAuth
|
|
|
|
authentication={authentication}
|
|
|
|
request={request}
|
|
|
|
handleRender={handleRender}
|
|
|
|
handleGetRenderContext={handleGetRenderContext}
|
|
|
|
onChange={onChange}
|
|
|
|
/>
|
|
|
|
);
|
2017-07-12 21:01:14 +00:00
|
|
|
} else if (authentication.type === AUTH_AWS_IAM) {
|
|
|
|
return (
|
|
|
|
<AWSAuth
|
|
|
|
authentication={authentication}
|
|
|
|
handleRender={handleRender}
|
|
|
|
handleGetRenderContext={handleGetRenderContext}
|
|
|
|
handleUpdateSettingsShowPasswords={handleUpdateSettingsShowPasswords}
|
|
|
|
onChange={onChange}
|
|
|
|
showPasswords={showPasswords}
|
|
|
|
/>
|
|
|
|
);
|
2017-07-31 17:29:36 +00:00
|
|
|
} else if (authentication.type === AUTH_NETRC) {
|
|
|
|
return (
|
|
|
|
<NetrcAuth />
|
|
|
|
);
|
2017-03-23 22:10:42 +00:00
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<div className="vertically-center text-center">
|
|
|
|
<p className="pad super-faint text-sm text-center">
|
|
|
|
<i className="fa fa-unlock-alt" style={{fontSize: '8rem', opacity: 0.3}}/>
|
|
|
|
<br/><br/>
|
|
|
|
Select an auth type from above
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
return (
|
2017-03-28 22:45:23 +00:00
|
|
|
<div className="tall">{this.renderEditor()}</div>
|
2017-03-23 22:10:42 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AuthWrapper.propTypes = {
|
|
|
|
handleRender: PropTypes.func.isRequired,
|
|
|
|
handleGetRenderContext: PropTypes.func.isRequired,
|
|
|
|
handleUpdateSettingsShowPasswords: PropTypes.func.isRequired,
|
|
|
|
onChange: PropTypes.func.isRequired,
|
|
|
|
request: PropTypes.object.isRequired,
|
|
|
|
showPasswords: PropTypes.bool.isRequired,
|
|
|
|
|
|
|
|
// Optional
|
|
|
|
oAuth2Token: PropTypes.object
|
|
|
|
};
|
|
|
|
|
|
|
|
export default AuthWrapper;
|