Skip to content

Commit

Permalink
Merge pull request #4 from aminduca/master
Browse files Browse the repository at this point in the history
*Better comments
  • Loading branch information
aminduca authored Nov 23, 2018
2 parents bfcccc8 + a98b752 commit b6ac74b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
Node.js module that serves Coveo search tokens for a Dynamics portal.

```javascript
// Decodes the authentication token from your portal to extract the payload related to the authenticated user.
// Decodes the authentication token from the portal and extracts from it the e-mail address of the current user (i.e. the one that made the call).
const portalAuth: IDecodedPortalAuthTokenPayload = await portal.decodeAuthToken(req.headers.authorization);

// Fetches a search token from Coveo for the user passed as argument.
// Fetches a search token from Coveo Cloud providing the current user e-mail (or empty for anonymous users), which then returns the search token.
const coveoSearchToken: string = await coveo.fetchSearchToken(portalAuth.email);
```

Expand Down
4 changes: 2 additions & 2 deletions lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
Node.js module that generates Coveo search tokens for a Dynamics portal.

```javascript
// Decodes the authentication token from your portal to extract the payload related to the authenticated user.
// Decodes the authentication token from the portal and extracts from it the e-mail address of the current user (i.e. the one that made the call).
const portalAuth: IDecodedPortalAuthTokenPayload = await portal.decodeAuthToken(req.headers.authorization);

// Fetches a search token from Coveo for the user passed as argument.
// Fetches a search token from Coveo Cloud providing the current user e-mail (or empty for anonymous users), which then returns the search token.
const coveoSearchToken: string = await coveo.fetchSearchToken(portalAuth.email);
```

Expand Down
2 changes: 1 addition & 1 deletion lib/src/CoveoSearchTokenGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface ISearchTokenResponse {
}

/**
* Generates search tokens to query Coveo.
* Generates search tokens to query Coveo Cloud.
*/
export class CoveoSearchTokenGenerator {
constructor(private readonly _apiKey: string, private readonly _platformUrl: string) { }
Expand Down
6 changes: 4 additions & 2 deletions samples/node-token-server/Index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ const coveo = new CoveoSearchTokenGenerator(config.coveoApiKey, config.coveoPlat
const getCoveoToken: express.RequestHandler = async (req: express.Request, res: express.Response): Promise<void> => {
try {
let userEmail: string;
// Checks in the request object for the existence of an optional authentication token from the portal.
// A token should be present only if the user is authenticated on your portal. If a token is not present, the user will be considered anonymous.
if (req.headers.authorization) {
// Decodes the authentication token from your portal to extract the payload related to the authenticated user.
// Decodes the authentication token from the portal and extracts from it the e-mail address of the current user (i.e. the one that made the call).
const portalAuth: IDecodedPortalAuthTokenPayload = await portal.decodeAuthToken(req.headers.authorization);
userEmail = portalAuth.email;
}

// Fetches a search token from Coveo for the user passed as argument.
// Fetches a search token from Coveo Cloud providing the current user e-mail (or empty for anonymous users), which then returns the search token.
const coveoSearchToken: string = await coveo.fetchSearchToken(userEmail);

// Returns the search token to the client.
Expand Down

0 comments on commit b6ac74b

Please sign in to comment.