Skip to content

Commit

Permalink
*PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
aminduca committed Nov 22, 2018
1 parent fc8a60e commit b0b75c1
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 Coveo
Copyright (c) 2005-2018 Coveo Solutions Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Coveo Search Token Generator

Node.js module that serves Coveo search tokens for Dynamics portal.
Node.js module that serves Coveo search tokens for a Dynamics portal.

```javascript
// Decodes the authentication token from portal to extract the payload related to the authenticated user.
// Decodes the authentication token from your portal to extract the payload related to the authenticated user.
const portalAuth: IDecodedPortalAuthTokenPayload = await portal.decodeAuthToken(req.headers.authorization);

// Gets a search token from Coveo for the user specified in the token.
// Fetches a search token from Coveo for the user passed as argument.
const coveoSearchToken: string = await coveo.fetchSearchToken(portalAuth.email);
```

Expand Down
2 changes: 1 addition & 1 deletion lib/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 Coveo
Copyright (c) 2005-2018 Coveo Solutions Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 3 additions & 3 deletions lib/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Coveo Search Token Generator

Node.js module that serves Coveo search tokens for Dynamics portal.
Node.js module that generates Coveo search tokens for a Dynamics portal.

```javascript
// Decodes the authentication token from portal to extract the payload related to the authenticated user.
// Decodes the authentication token from your portal to extract the payload related to the authenticated user.
const portalAuth: IDecodedPortalAuthTokenPayload = await portal.decodeAuthToken(req.headers.authorization);

// Gets a search token from Coveo for the user specified in the token.
// Fetches a search token from Coveo for the user passed as argument.
const coveoSearchToken: string = await coveo.fetchSearchToken(portalAuth.email);
```

Expand Down
2 changes: 1 addition & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "coveo-search-token-generator",
"description": "Serves Coveo search tokens for Dynamics portal.",
"description": "Generates Coveo search tokens for a Dynamics portal.",
"author": "Coveo",
"license": "MIT",
"version": "0.0.2",
Expand Down
4 changes: 2 additions & 2 deletions lib/src/CoveoSearchTokenGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ interface ISearchTokenResponse {
}

/**
* Gets or create a search token.
* Generates search tokens to query Coveo.
*/
export class CoveoSearchTokenGenerator {
constructor(private readonly _apiKey: string, private readonly _platformUrl: string) { }

/**
* Gets or create a search token for the given user.
* Fetches a search token for the given user.
* If no e-mail is provided, the token returned will
* correspond to the anonymous profile.
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/src/DynamicsPortalAuthTokenDecoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface IDecodedPortalAuthTokenPayload {
}

/**
* Decodes a portal authentication token.
* Decodes an authentication token from a portal.
*/
export class DynamicsPortalAuthTokenDecoder {
private _lastPublicKey: string;
Expand Down
10 changes: 6 additions & 4 deletions samples/node-token-server/Index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,27 @@ import * as express from "express";
// -----------------------------------------------------------------------------
// Change this configuration accordingly to represent your environment.
const config = {
portalUrl: "<your_portal_url>", // Example: https://yourportalurl.microsoftcrmportals.com (without slash at the end)
portalUrl: "https://yourportalurl.microsoftcrmportals.com/", // Example: https://yourportalurl.microsoftcrmportals.com
coveoApiKey: "<your_API_key>", // The API key used to query Coveo and create a search token. It must have at least the privilege "Impersonate" enabled.
coveoPlatformUrl: "platform.cloud.coveo.com" // The URL of the Coveo Cloud V2 platform.
coveoPlatformUrl: "platform.cloud.coveo.com" // The Coveo Cloud URL.
};
// -----------------------------------------------------------------------------

config.portalUrl = config.portalUrl.replace(/\/$/, ""); // Remove from the address an eventual trailing slash.

const portal = new DynamicsPortalAuthTokenDecoder(config.portalUrl);
const coveo = new CoveoSearchTokenGenerator(config.coveoApiKey, config.coveoPlatformUrl);

const getCoveoToken: express.RequestHandler = async (req: express.Request, res: express.Response): Promise<void> => {
try {
let userEmail: string;
if (req.headers.authorization) {
// Decodes the authentication token from portal to extract the payload related to the authenticated user.
// Decodes the authentication token from your portal to extract the payload related to the authenticated user.
const portalAuth: IDecodedPortalAuthTokenPayload = await portal.decodeAuthToken(req.headers.authorization);
userEmail = portalAuth.email;
}

// Gets a search token from Coveo for the user specified in the token.
// Fetches a search token from Coveo for the user passed as argument.
const coveoSearchToken: string = await coveo.fetchSearchToken(userEmail);

// Returns the search token to the client.
Expand Down
2 changes: 1 addition & 1 deletion samples/node-token-server/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 Coveo
Copyright (c) 2005-2018 Coveo Solutions Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion samples/node-token-server/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Node.js Express Server Sample

Express server that generates Coveo search tokens for Dynamics portal.
Express server that generates Coveo search tokens for a Dynamics portal.

## Configuration

Expand Down
6 changes: 3 additions & 3 deletions samples/node-token-server/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "sample-token-server",
"description": "Express server that generates Coveo search tokens for Dynamics portal.",
"description": "Express server that generates Coveo search tokens for a Dynamics portal.",
"author": "Coveo",
"license": "MIT",
"version": "0.0.1",
"private": true,
"keywords": [
"coveo",
"typescript",
Expand All @@ -17,7 +17,7 @@
"homepage": "https://github.com/coveo/coveo-search-token-generator",
"dependencies": {
"express": "^4.16.0",
"coveo-search-token-generator": "file:../../lib"
"coveo-search-token-generator": "0.0.2"
},
"scripts": {
"setup": "npm install",
Expand Down

0 comments on commit b0b75c1

Please sign in to comment.