Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sample for user ID and more validation logics #1447

Merged
merged 4 commits into from
Dec 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Code is instrumented using [`istanbul`](https://npmjs.com/package/istanbul)
- Test report is hosted on [Coveralls](https://coveralls.io/github/compulim/BotFramework-WebChat)
- Add French localization, by [@tao1](https://github.com/tao1) in PR [#1327](https://github.com/Microsoft/BotFramework-WebChat/pull/1327)
- Fix [#1344](https://github.com/Microsoft/BotFramework-WebChat/issues/1344), by updating `README.md` and adding validation logic for `userID` props, in [#1447](https://github.com/Microsoft/BotFramework-WebChat/pull/1447)
- If `userID` props present and also embedded in Direct Line token, will use the one from Direct Line token
- If `userID` props present, they must be string and not prefixed with `dl_`, to avoid confusion between `userID` props and Direct Line embedded user ID (which is forgery-proof)
- If `userID` props does not pass the validation test or not specified, Web Chat will use `default-user` instead

### Changed
- Core: Saga will run after custom middleware, in [#1331](https://github.com/Microsoft/BotFramework-WebChat/pull/1331)
Expand Down
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ Here is how how you can add Web Chat control to you website:
<script src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
<script>
window.WebChat.renderWebChat({
directLine: window.WebChat.createDirectLine({ secret: 'YOUR_BOT_SECRET_FROM_AZURE_PORTAL' })
directLine: window.WebChat.createDirectLine({ secret: 'YOUR_BOT_SECRET_FROM_AZURE_PORTAL' }),
userID: 'YOUR_USER_ID'
}, document.getElementById('webchat'));
</script>
</body>
</html>
```

> If `userID` is not specified, it will be default to `default-user`. Multiple users sharing the same user ID is not recommended, their user state will be shared.

![Screenshot of Web Chat](https://raw.githubusercontent.com/Microsoft/BotFramework-WebChat/master/doc/webchat-screenshot.png)

## Integrate with JavaScript
Expand All @@ -54,7 +57,8 @@ You can use the full, typical webchat package that contains the most typically u
<script src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
<script>
window.WebChat.renderWebChat({
directLine: window.WebChat.createDirectLine({ token: 'YOUR_BOT_SECREET' })
directLine: window.WebChat.createDirectLine({ token: 'YOUR_BOT_SECRET' }),
userID: 'YOUR_USER_ID'
}, document.getElementById('webchat'));
</script>
</body>
Expand Down Expand Up @@ -82,7 +86,8 @@ See a working sample with minimal Web Chat bundle [here](https://github.com/Micr
<script src="https://cdn.botframework.com/botframework-webchat/latest/webchat-minimal.js"></script>
<script>
window.WebChat.renderWebChat({
directLine: window.WebChat.createDirectLine({ token: 'YOUR_BOT_SECRET' })
directLine: window.WebChat.createDirectLine({ token: 'YOUR_BOT_SECRET' }),
userID: 'YOUR_USER_ID'
}, document.getElementById('webchat'));
</script>
</body>
Expand All @@ -109,7 +114,7 @@ export default class extends React.Component {

render() {
return (
<ReactWebChat directLine={ this.directLine } />
<ReactWebChat directLine={ this.directLine } userID="YOUR_USER_ID" />
element
);
}
Expand Down
10 changes: 9 additions & 1 deletion packages/core/src/sagas/connectSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,15 @@ export default function* () {
}

userID = userIDFromToken;
} else if (!userID) {
} else if (userID) {
if (typeof userID !== 'string') {
console.warn('Web Chat: user ID must be a string.');
userID = DEFAULT_USER_ID;
} else if (/^dl_/.test(userID)) {
console.warn('Web Chat: user ID prefixed with "dl_" is reserved and must be embedded into the Direct Line token to prevent forgery.');
userID = DEFAULT_USER_ID;
}
} else {
// Only specify "default-user" if not found from token and not passed in
userID = DEFAULT_USER_ID;
}
Expand Down