Skip to content

Commit

Permalink
Changes to use default config from javascript config file
Browse files Browse the repository at this point in the history
  • Loading branch information
vijetmahabaleshwar-okta committed May 13, 2019
1 parent b1a01b7 commit 2452c19
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ dist
npm-debug.log
.DS_Store
.vscode
.samples.config.json
.samples.config.js
testenv
okta-oidc-tck
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,4 @@ npm test
node scripts/setup-env.js
```

> **NOTE:** If you want to test a different org or client app, you need to delete the configuration file `.samples.config.json`, and start from [first step](#running-e2e-tests-locally)
> **NOTE:** If you want to test a different org or client app, you need to delete the configuration file `.samples.config.js`, and start from [first step](#running-e2e-tests-locally)
3 changes: 2 additions & 1 deletion common/sample-web-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ module.exports = function SampleWebServer(sampleConfig, extraOidcOptions, homePa
client_id: sampleConfig.oidc.clientId,
client_secret: sampleConfig.oidc.clientSecret,
appBaseUrl: sampleConfig.oidc.appBaseUrl,
scope: sampleConfig.oidc.scope
scope: sampleConfig.oidc.scope,
testing: sampleConfig.oidc.testing
}, extraOidcOptions || {}));

const app = express();
Expand Down
6 changes: 3 additions & 3 deletions custom-login/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ Now you need to gather the following information from the Okta Developer Console

- **Issuer** - This is the URL of the authorization server that will perform authentication. All Developer Accounts have a "default" authorization server. The issuer is a combination of your Org URL (found in the upper right of the console home page) and `/oauth2/default`. For example, `https://dev-1234.okta.com/oauth2/default`.

Now place these values into the file `.samples.config.json` that was created for you in the root of this project:
Now place these values into the file `.samples.config.js` that was created for you in the root of this project:

```json
{
```javascript
module.exports = {
"webServer": {
"port": 8080,
"oidc": {
Expand Down
2 changes: 1 addition & 1 deletion custom-login/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

const url = require('url');
const sampleConfig = require('../.samples.config.json');
const sampleConfig = require('../.samples.config.js');
const SampleWebServer = require('../common/sample-web-server');

const oidcMiddlewareConfig = {
Expand Down
2 changes: 1 addition & 1 deletion default-config.ts → default-config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default {
module.exports = {
webServer: {
port: 8080,
oidc: {
Expand Down
6 changes: 3 additions & 3 deletions okta-hosted-login/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ Now you need to gather the following information from the Okta Developer Console

- **Issuer** - This is the URL of the authorization server that will perform authentication. All Developer Accounts have a "default" authorization server. The issuer is a combination of your Org URL (found in the upper right of the console home page) and `/oauth2/default`. For example, `https://dev-1234.okta.com/oauth2/default`.

Now place these values into the file `.samples.config.json` that was created for you in the root of this project:
Now place these values into the file `.samples.config.js` that was created for you in the root of this project:

```json
{
```javascript
module.exports = {
"webServer": {
"port": 8080,
"oidc": {
Expand Down
2 changes: 1 addition & 1 deletion okta-hosted-login/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* See the License for the specific language governing permissions and limitations under the License.
*/

const sampleConfig = require('../.samples.config.json');
const sampleConfig = require('../.samples.config.js');
const SampleWebServer = require('../common/sample-web-server');

/**
Expand Down
6 changes: 3 additions & 3 deletions resource-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ Now you need to gather the following information from the Okta Developer Console
- **Client Id** - The client ID of the SPA application that you created earlier. This can be found on the "General" tab of an application, or the list of applications. The resource server will validate that tokens have been minted for this application.
- **Issuer** - This is the URL of the authorization server that minted the tokens. All Developer Accounts have a "default" authorization server. The issuer is a combination of your Org URL (found in the upper right of the console home page) and `/oauth2/default`. For example, `https://dev-1234.oktapreview.com/oauth2/default`.

Now place these values into the file `.samples.config.json` that was created for you in the root of this project:
Now place these values into the file `.samples.config.js` that was created for you in the root of this project:

```json
{
```javascript
module.exports = {
"resourceServer": {
"port": 8000,
"oidc": {
Expand Down
5 changes: 3 additions & 2 deletions resource-server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ const express = require('express');
const OktaJwtVerifier = require('@okta/jwt-verifier');
var cors = require('cors');

const sampleConfig = require('../.samples.config.json');
const sampleConfig = require('../.samples.config.js');

const oktaJwtVerifier = new OktaJwtVerifier({
clientId: sampleConfig.resourceServer.oidc.clientId,
issuer: sampleConfig.resourceServer.oidc.issuer,
assertClaims: sampleConfig.resourceServer.assertClaims
assertClaims: sampleConfig.resourceServer.assertClaims,
testing: sampleConfig.resourceServer.oidc.testing
});

/**
Expand Down
25 changes: 20 additions & 5 deletions scripts/setup-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,27 @@ function updateConfig() {
process.exit(1);
}

const file = path.join(__dirname, '..', '.samples.config.json');
const file = path.join(__dirname, '..', '.samples.config.js');
const data = fs.readFileSync(file, 'utf8');
let result = data.replace(/"cid": "{spaClientId}"/g, `"cid": "${process.env.SPA_CLIENT_ID}"`)
result = result.replace(/{clientId}/g, process.env.CLIENT_ID);
result = result.replace(/{clientSecret}/g, process.env.CLIENT_SECRET);
result = result.replace(/https:\/\/{yourOktaDomain}.com\/oauth2\/default/g, process.env.ISSUER);
let result = data.replace(/https:\/\/{yourOktaDomain}.com\/oauth2\/default/g, process.env.ISSUER);

if(data.indexOf('{clientId}') >= 0){
result = result.replace(/{clientId}/g, process.env.CLIENT_ID);
}

if(data.indexOf('{clientSecret}') >= 0){
result = result.replace(/{clientSecret}/g, process.env.CLIENT_SECRET);
}

if(data.indexOf('{spaClientId}') >= 0){
result = result.replace(/{spaClientId}/g, process.env.SPA_CLIENT_ID);
}

// Only used for testing to support non-https orgs
if (process.env.OKTA_TESTING_DISABLEHTTPSCHECK) {
result = result.replace(/disableHttpsCheck: false/g, 'disableHttpsCheck: true');
}

fs.writeFileSync(file, result, 'utf8');
}

Expand Down
4 changes: 2 additions & 2 deletions tools/create-config-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ const fs = require('fs');
const colorsPath = path.join(process.cwd(), 'node_modules', 'colors');
const colors = require(colorsPath);

const defaultFilePath = path.join(process.cwd(), 'default-config.ts');
const defaultFilePath = path.join(process.cwd(), 'default-config.js');
const defaultFile = fs.readFileSync(defaultFilePath);
const newFilePath = path.join(process.cwd(), '.samples.config.json');
const newFilePath = path.join(process.cwd(), '.samples.config.js');

/* eslint-disable no-console */

Expand Down

0 comments on commit 2452c19

Please sign in to comment.