insomnia/app/ui/components/editors/auth/auth-wrapper.js
Gregory Schier 2cdd4761c8 Remaining V5 Features (#122)
* Add digest auth and response timeline

* Some css fixes

* Fixed Button

* More auth methods, fixed URL regex, and fix gzip

* Get rid of negotiate auth

* Fix proxy

* Fixed GA tracking

* Some very small changes and fixes

* Fix content type names

* Even better auth switching and timeline syntax

* Some auth tweaks

* CSS tweaks

* Reworked toasts

* Fixed timer rounding quirk

* Request settings and render errors

* Fixed tests

* Vertical dragging and stuff

* Remove beta
2017-03-28 15:45:23 -07:00

112 lines
3.4 KiB
JavaScript

import React, {PropTypes, PureComponent} from 'react';
import {AUTH_BASIC, AUTH_DIGEST, AUTH_NTLM, AUTH_OAUTH_1, AUTH_OAUTH_2} from '../../../../common/constants';
import BasicAuth from './basic-auth';
import DigestAuth from './digest-auth';
import NTLMAuth from './ntlm-auth';
import OAuth2 from './o-auth-2';
import autobind from 'autobind-decorator';
@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 (
<OAuth2
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">
<p className="pad super-faint text-sm text-center">
<i className="fa fa-commenting" style={{fontSize: '8rem', opacity: 0.3}}/>
<br/><br/>
Don't worry, OAuth 1.0 is coming soon!
</p>
</div>
);
} else if (authentication.type === AUTH_DIGEST) {
return (
<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}
/>
);
} 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 (
<div className="tall">{this.renderEditor()}</div>
);
}
}
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;