Skip to content
This repository has been archived by the owner on Jan 26, 2025. It is now read-only.

Commit

Permalink
[WIP] Setting custom error agents
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Damphousse committed Mar 13, 2018
1 parent a7db9f6 commit 51e62e9
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ package-lock.json
.envrc
*.code-workspace
lerna-debug.log

# Ignore TCK-related files in all folders
okta-oidc-tck*
target
packages/okta-vue/test/e2e/harness/config/dev.env.js

# package info files are generated during build and included in final artifacts
packageInfo.js
packageInfo.ts
2 changes: 2 additions & 0 deletions packages/okta-angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
"dist"
],
"scripts": {
"build:package-info": "node ../../util/write-package-info.js . src/okta/packageInfo.ts",
"pretest": "npm run build:dependencies",
"prestart": "npm run build:dependencies",
"prepublish": "npm run ngc",
"prengc": "npm run build:package-info",
"ngc": "./node_modules/.bin/ngc -p tsconfig.json",
"test": "npm run --prefix test/e2e/harness/ e2e",
"start": "npm run --prefix test/e2e/harness/ start",
Expand Down
6 changes: 5 additions & 1 deletion packages/okta-angular/src/okta/okta.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { Router } from '@angular/router';

import { OKTA_CONFIG } from './okta.config';

import packageInfo from './packageInfo';

/**
* Import the okta-auth-js library
*/
Expand Down Expand Up @@ -49,6 +51,8 @@ export class OktaAuthService {
redirectUri: auth.redirectUri
});

this.oktaAuth.userAgent = `${packageInfo.name}/${packageInfo.version} ${this.oktaAuth.userAgent}`;

/**
* Scrub scopes to ensure 'openid' is included
*/
Expand Down Expand Up @@ -109,7 +113,7 @@ export class OktaAuthService {

/**
* Stores the intended path to redirect after successful login.
* @param uri
* @param uri
*/
setFromUri(uri) {
localStorage.setItem('referrerPath', uri);
Expand Down
7 changes: 5 additions & 2 deletions packages/okta-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
"scripts": {
"build": "rimraf dist/ && babel src -d dist",
"build:harness": "npm --prefix test/e2e/harness install",
"build:package-info": "node ../../util/write-package-info.js . src/packageInfo.js",
"jest": "jest test/jest/",
"lint": "eslint src/**; exit 0",
"lint:watch": "esw -w lib/**",
"prepublish": "npm run build",
"prepublish": "npm run build:package-info && npm run build",
"prestart": "npm run build && npm run build:harness",
"start": "npm run --prefix test/e2e/harness start",
"pretest": "npm run build && npm run build:harness",
"test": "npm run --prefix test/e2e/harness test"
"test": "npm run jest && npm run --prefix test/e2e/harness test"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -56,6 +58,7 @@
"eslint-watch": "^3.1.2",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"jest": "^22.4.2",
"polished": "^1.7.0",
"protractor": "^5.1.2",
"react-dom": "^15.6.1",
Expand Down
3 changes: 3 additions & 0 deletions packages/okta-react/src/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import OktaAuth from '@okta/okta-auth-js';

import packageInfo from './packageInfo';

const containsAuthTokens = /id_token|access_token|code/;

export default class Auth {
Expand All @@ -22,6 +24,7 @@ export default class Auth {
issuer: config.issuer,
redirectUri: config.redirect_uri
});
this._oktaAuth.userAgent = `${packageInfo.name}/${packageInfo.version} ${this._oktaAuth.userAgent}`;
this._config = config;
this._history = config.history;

Expand Down
11 changes: 11 additions & 0 deletions packages/okta-react/test/jest/auth.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Auth from '../../src/Auth';

const pkg = require('../../package.json');

test('Auth component sets the right user agent on AuthJS', () => {
const auth = new Auth({
issuer: 'https://foo/oauth2/default'
});
const expectedUserAgent = `${pkg.name}/${pkg.version} okta-auth-js-`;
expect(auth._oktaAuth.userAgent).toMatch(expectedUserAgent);
});
17 changes: 17 additions & 0 deletions util/write-package-info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const fs = require('fs');
const path = require('path');

const workingDirectory = process.argv[2];
const destinationFile = process.argv[3];
const packageJsonPath = path.join(process.cwd(), workingDirectory, 'package.json')
const configDest = path.join(process.cwd(), workingDirectory, destinationFile);
const packageJson = require(packageJsonPath);
const packageInfo = {
name: packageJson.name,
version: packageJson.version
};
const output = 'export default ' + JSON.stringify(packageInfo, null, 2) + ';'

console.log('Writing config to', configDest);

fs.writeFileSync(configDest, output);

0 comments on commit 51e62e9

Please sign in to comment.