Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import * as serviceWorker from './serviceWorker';
import App from './App';
import connectUsingSecret from './redux/actions/connectUsingSecret';
import connectUsingTokenServer from './redux/actions/connectUsingTokenServer';
import enableSpeechUsingSecret from './redux/actions/enableSpeechUsingSecret';
import enableSpeechUsingTokenServer from './redux/actions/enableSpeechUsingTokenServer';
import createStore from './redux/createStore';
const store = createStore();
// TODO: Move it somewhere
const { directLineSecret, speechServicesSubscriptionKey } = store.getState();
if (directLineSecret) {
store.dispatch(connectUsingSecret(directLineSecret, random().toString(36).substr(2, 10)));
} else {
store.dispatch(connectUsingTokenServer());
}
if (speechServicesSubscriptionKey) {
store.dispatch(enableSpeechUsingSecret(speechServicesSubscriptionKey));
} else {
store.dispatch(enableSpeechUsingTokenServer());
}
ReactDOM.render(
,
document.getElementById('root')
);
server.post('/api/directline/token', async (_, res) => {
// TODO: We should rate-limit to prevent abuse
try {
const userID = `dl_${ random().toString(36).substr(2, 10) }`;
const tokenRes = await fetch('https://directline.botframework.com/v3/directline/tokens/generate', {
body: JSON.stringify({
User: { Id: userID }
}),
headers: {
authorization: `Bearer ${ directLineSecret }`,
'content-type': 'application/json'
},
method: 'POST'
});
if (!tokenRes.ok) {
return res.send(503, { message: 'failed to exchange Direct Line secret', innerStatus: tokenRes.status });
}
const { expires_in: expiresIn, token } = JSON.parse(await tokenRes.text());
export default function (secret, userID = `dl_${ random().toString(36).substr(2, 10) }`) {
return async dispatch => {
dispatch({ type: CONNECT_PENDING });
try {
const tokenRes = await fetch('https://directline.botframework.com/v3/directline/tokens/generate', {
body: JSON.stringify({
User: { Id: userID }
}),
headers: {
authorization: `Bearer ${ secret }`,
'content-type': 'application/json'
},
method: 'POST'
});
if (!tokenRes.ok) {
export default function uniqueID() {
return (
Date.now() +
random()
.toString(36)
.substr(2)
);
}