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

feat(cli): add @coveo/search-token-server package #33

Merged
merged 13 commits into from
Feb 17, 2021
5 changes: 0 additions & 5 deletions packages/cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions packages/search-token-server/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Coveo related configuration
COVEO_PLATFORM_HOSTNAME=<PLATFORM_HOSTNAME dev,qa,prod,hippa>
# for example https://platform.cloud.coveo.com
Copy link
Member

@olamothe olamothe Feb 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just me, but I would put the comment above the line it explains ;)

And a comment that says to look at README.

In general, don't be afraid to put quite a bit of explanation about what everything is with a lot of detail.

Think from the point of view from a total newbie that just started to play with Coveo interacting through the CLI.

They need explanation about what are the valid platform endpoint, what is an API key/where to see them in your organization, the privileges required, what is a search hub etc..

All of these are well explained in our documentation, so try to always link to an article that would help a total newbie to roughly understand what's going on.

Without that, it is all very cryptic. This module/package can be seen as a good way to teach.

COVEO_API_KEY=<YOUR_COVEO_API_KEY_HERE>
USER_EMAIL=<YOUR_EMAIL>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion:
The name of the security identity to impersonate.
Example: "[email protected]"
See https://docs.coveo.com/en/56/#name-string-required.

(If I understand correctly)


# Optional variables
# SEARCH_HUB=<YOUR_SEARCH_HUB>
1 change: 1 addition & 0 deletions packages/search-token-server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
7 changes: 7 additions & 0 deletions packages/search-token-server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Simple search token generation server

## Setup environment

Create the `.env` file at the root of this project using `.env.example` as starting point and make sure to replace all placeholder variables `<...>` by the proper information for your organization.

For more info, https://docs.coveo.com/en/56/build-a-search-ui/search-token-authentication
23 changes: 23 additions & 0 deletions packages/search-token-server/middlewares/searchToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {NextFunction} from 'express';
import {getSearchToken} from '../utils/cloudPlatformAPI';

export function ensureTokenGenerated(req: any, res: any, next: NextFunction) {
const userIds = [process.env.USER_EMAIL!].map((user) => ({
name: user,
provider: 'Email Security Provider',
}));

getSearchToken({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use an async await to 'flatten' the code personnaly

hostname: process.env.COVEO_PLATFORM_HOSTNAME!,
apiKey: process.env.COVEO_API_KEY!,
searchHub: process.env.SEARCH_HUB,
userIds: userIds,
})
.then((data: any) => {
req.token = data.token;
next();
})
.catch((err: any) => {
next(err);
});
}
Loading