forked from readmeio/api-explorer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move security input types into separate files
- Loading branch information
Dom Harrington
committed
Oct 24, 2017
1 parent
7bb6090
commit ff5708b
Showing
5 changed files
with
180 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/api-explorer-ui/src/security-input-types/ApiKey.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const React = require('react'); | ||
const PropTypes = require('prop-types'); | ||
const Cookie = require('js-cookie'); | ||
|
||
function ApiKey({ scheme, inputRef, change }) { | ||
const apiKeyCookie = Cookie.get('api_key'); | ||
// apiKeyCookie = apiKeyCookie || {e => apiKey.change(e.currentTarget.value)}; | ||
return ( | ||
<div className="row"> | ||
<div className="col-xs-5"> | ||
<label htmlFor="apiKey">{scheme.name}</label> | ||
</div> | ||
<div className="col-xs-7"> | ||
<input | ||
ref={inputRef} | ||
type="text" | ||
onChange={e => change(e.currentTarget.value)} | ||
value={apiKeyCookie} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
ApiKey.propTypes = { | ||
scheme: PropTypes.shape({ | ||
name: PropTypes.string.isRequired, | ||
}).isRequired, | ||
inputRef: PropTypes.func, | ||
change: PropTypes.func.isRequired, | ||
}; | ||
|
||
ApiKey.defaultProps = { | ||
inputRef: () => {}, | ||
}; | ||
|
||
module.exports = ApiKey; |
56 changes: 56 additions & 0 deletions
56
packages/api-explorer-ui/src/security-input-types/Basic.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const React = require('react'); | ||
const PropTypes = require('prop-types'); | ||
|
||
class Basic extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { user: '', password: '' }; | ||
this.inputChange = this.inputChange.bind(this); | ||
} | ||
|
||
inputChange(name, value) { | ||
this.setState( | ||
previousState => { | ||
return Object.assign({}, previousState, { [name]: value }); | ||
}, | ||
() => { | ||
this.props.change(this.state); | ||
}, | ||
); | ||
} | ||
render() { | ||
const { inputRef } = this.props; | ||
return ( | ||
<div className="row"> | ||
<div className="col-xs-6"> | ||
<label htmlFor="user">username</label> | ||
<input | ||
ref={inputRef} | ||
type="text" | ||
onChange={e => this.inputChange(e.currentTarget.name, e.currentTarget.value)} | ||
name="user" | ||
/> | ||
</div> | ||
<div className="col-xs-6"> | ||
<label htmlFor="password">password</label> | ||
<input | ||
type="text" | ||
onChange={e => this.inputChange(e.currentTarget.name, e.currentTarget.value)} | ||
name="password" | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
Basic.propTypes = { | ||
change: PropTypes.func.isRequired, | ||
inputRef: PropTypes.func, | ||
}; | ||
|
||
Basic.defaultProps = { | ||
inputRef: () => {}, | ||
}; | ||
|
||
module.exports = Basic; |
66 changes: 66 additions & 0 deletions
66
packages/api-explorer-ui/src/security-input-types/Oauth2.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
const React = require('react'); | ||
const PropTypes = require('prop-types'); | ||
|
||
function Oauth2({ apiKey, inputRef, oauthUrl, change }) { | ||
if (!apiKey && oauthUrl) { | ||
return ( | ||
<section> | ||
<div className="text-center"> | ||
<a className="btn btn-primary" href={oauthUrl} target="_self"> | ||
Authenticate via OAuth2 | ||
</a> | ||
</div> | ||
</section> | ||
); | ||
} | ||
|
||
return ( | ||
<section> | ||
{ | ||
// TODO | ||
// if security.description | ||
// != marked(security.description) | ||
} | ||
<div className="row"> | ||
<div className="col-xs-4"> | ||
<label htmlFor="apiKey">Authorization</label> | ||
</div> | ||
<div className="col-xs-2"> | ||
<div | ||
style={{ | ||
display: 'inline-block', | ||
marginRight: '10px', | ||
marginTop: '5px', | ||
fontSize: '13px', | ||
}} | ||
> | ||
Bearer | ||
</div> | ||
</div> | ||
<div className="col-xs-6"> | ||
<input | ||
ref={inputRef} | ||
type="text" | ||
onChange={e => change(e.currentTarget.value)} | ||
name="apiKey" | ||
/> | ||
</div> | ||
</div> | ||
</section> | ||
); | ||
} | ||
|
||
Oauth2.propTypes = { | ||
apiKey: PropTypes.string, | ||
oauthUrl: PropTypes.string, | ||
change: PropTypes.func.isRequired, | ||
inputRef: PropTypes.func, | ||
}; | ||
|
||
Oauth2.defaultProps = { | ||
apiKey: '', | ||
oauthUrl: '', | ||
inputRef: () => {}, | ||
}; | ||
|
||
module.exports = Oauth2; |