React
by Andrew Dunai
HTML
<div id="app"></div>
CSS
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
#app {
background: #fff;
border-radius: 4px;
padding: 20px;
transition: all 0.2s;
}
li {
margin: 8px 0;
}
h2 {
font-weight: bold;
margin-bottom: 15px;
}
.done {
color: rgba(0, 0, 0, 0.3);
text-decoration: line-through;
}
input {
margin-right: 5px;
}
textarea {
width: 100%;
height: 20em;
}
React
const OAuthGen = props => {
const [scopes, setScopes] = React.useState('');
const [clientId, setClientId ] = React.useState('');
const [token, setToken] = React.useState('');
React.useEffect(() => {
const now = parseInt(new Date().getTime());
const header = btoa(JSON.stringify({
kid: 'test',
alg: 'RS256',
}));
const payload = btoa(JSON.stringify({
ver: 1,
iss: 'http://localhost',
aud: 'wscc.dev.wellsky.io',
iat: now,
exp: now + 86400,
cid: `api.wellsky.payer.wscc.${clientId}`,
sub: `api.wellsky.payer.wscc.${clientId}`,
scp: scopes.split(',').map(scope => `api.wellsky.payer.wscc.payerhub.${scope}`),
}));
setToken(`${header}.${payload}.e30K`);
}, [scopes, clientId]);
return (
<div>
<label htmlFor="scopes">Scopes (comma-separated):</label>
<div>
<input id="scopes" type="text" placeholder="discharge" onInput={e => setScopes(e.target.value)} />
</div>
<label htmlFor="scopes">Client ID:</label>
<div>
<input id="scopes" type="text" placeholder="fooclient" onInput={e => setClientId(e.target.value)} />
</div>
<div>
Token:
</div>
<textarea value={(scopes && clientId) ? token : 'Enter scope & client ID'} readOnly={true} />
</div>
);
};
ReactDOM.render(<OAuthGen />, document.querySelector('#app'));