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

[WIP DON'T MERGE] Setting custom error agents #146

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 3 additions & 1 deletion 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 All @@ -30,7 +32,7 @@
],
"license": "Apache-2.0",
"dependencies": {
"@okta/okta-auth-js": "^1.8.0"
"@okta/okta-auth-js": "^1.14.0"
},
"devDependencies": {
"@angular/common": "^4.4.3",
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 @@ -127,7 +131,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
9 changes: 6 additions & 3 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 All @@ -32,7 +34,7 @@
},
"homepage": "https://github.com/okta/okta-oidc-js#readme",
"dependencies": {
"@okta/okta-auth-js": "^1.8.0",
"@okta/okta-auth-js": "^1.14.0",
"babel-runtime": "^6.26.0",
"prop-types": "^15.5.10"
},
Expand All @@ -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-`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this pickup the okta-auth-js version too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To assert that, you need to know which version is currently depended on. Ideas I had that I didn't love:

  • Lock package.json down to a specific patch version
  • Fish into node modules to see what's currently installed.
  • Use a regex in the matcher, to at least assert the whole thing looks like what we expect

expect(auth._oktaAuth.userAgent).toMatch(expectedUserAgent);
});
4 changes: 3 additions & 1 deletion packages/okta-vue/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"plugins": ["transform-runtime"],
"env": {
"test": {
"presets": ["env", "stage-2", "es2015"]
"presets": [
["env", { "targets": { "node": "current" }}]
]
}
}
}
4 changes: 3 additions & 1 deletion packages/okta-vue/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ module.exports = {
},
env: {
browser: true,
"jest/globals": true
},
// https://github.com/standard/standard/blob/master/docs/RULES-en.md
extends: 'standard',
// required to lint *.vue files
plugins: [
'html'
'html',
'jest'
],
// add your custom rules here
rules: {
Expand Down
27 changes: 25 additions & 2 deletions packages/okta-vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,33 @@
"src"
],
"scripts": {
"prebuild": "npm run build:package-info",
"prestart": "npm run build",
"pretest": "npm run build && npm run build:harness",
"prepublish": "npm run build",
"test": "npm run --prefix test/e2e/harness/ test",
"jest": "jest src/",
"test": "npm run jest && npm run --prefix test/e2e/harness/ test",
"start": "npm run --prefix test/e2e/harness/ start",
"build": "rimraf dist/ && cross-env NODE_ENV=production webpack --config webpack.config.js --output-library-target=umd -p",
"build:harness": "npm --prefix test/e2e/harness install",
"build:package-info": "node ../../util/write-package-info.js . src/packageInfo.js",
"lint": "eslint --ext .js,.vue src"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"vue"
],
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
".*\\.(vue)$": "<rootDir>/node_modules/vue-jest"
},
"moduleNameMapper": {
"^@/(.*)$": "<rootDir>/src/$1"
},
"mapCoverage": true
},
"repository": {
"type": "git",
"url": "git+https://github.com/okta/okta-oidc-js.git"
Expand All @@ -31,15 +49,17 @@
},
"homepage": "https://github.com/okta/okta-oidc-js#readme",
"dependencies": {
"@okta/okta-auth-js": "^1.11.0",
"@okta/okta-auth-js": "^1.14.0",
"cross-env": "^5.1.1",
"vue": "^2.5.9",
"vue-router": "^3.0.1"
},
"devDependencies": {
"@vue/test-utils": "^1.0.0-beta.12",
"autoprefixer": "^7.1.2",
"babel-core": "^6.22.1",
"babel-eslint": "^7.1.1",
"babel-jest": "^23.0.0-alpha.0",
"babel-loader": "^7.1.1",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-preset-env": "^1.3.2",
Expand All @@ -52,13 +72,16 @@
"eslint-loader": "^1.7.1",
"eslint-plugin-html": "^3.0.0",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-jest": "^21.15.0",
"eslint-plugin-node": "^5.2.0",
"eslint-plugin-promise": "^3.4.0",
"eslint-plugin-standard": "^3.0.1",
"jest": "^22.4.2",
"nightwatch": "^0.9.12",
"rimraf": "^2.6.2",
"uglifyjs-webpack-plugin": "^1.1.1",
"url-loader": "^0.5.8",
"vue-jest": "^2.1.1",
"vue-loader": "13.0.2",
"vue-style-loader": "^3.0.1",
"vue-template-compiler": "^2.5.2",
Expand Down
4 changes: 3 additions & 1 deletion packages/okta-vue/src/Auth.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as AuthJS from '@okta/okta-auth-js'
import AuthJS from '@okta/okta-auth-js'
import packageInfo from './packageInfo'
import ImplicitCallback from './components/ImplicitCallback'

function install (Vue, options) {
Expand All @@ -9,6 +10,7 @@ function install (Vue, options) {
redirectUri: authConfig.redirect_uri,
url: authConfig.issuer.split('/oauth2/')[0]
})
oktaAuth.userAgent = `${packageInfo.name}/${packageInfo.version} ${oktaAuth.userAgent}`

Vue.prototype.$auth = {
loginRedirect (additionalParams) {
Expand Down
28 changes: 28 additions & 0 deletions packages/okta-vue/src/Auth.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import AuthJS from '@okta/okta-auth-js'
import { createLocalVue } from '@vue/test-utils'
import { default as Auth } from './Auth'

jest.mock('@okta/okta-auth-js')

const mockAuthJsInstance = {userAgent: 'foo'}

AuthJS.mockImplementation(() => {
return mockAuthJsInstance
})

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

describe('Auth', () => {
test('is a Vue plugin', () => {
expect(Auth.install).toBeTruthy()
})
test('sets the right user agent on AuthJS', () => {
const expectedUserAgent = `${pkg.name}/${pkg.version} foo`
createLocalVue().use(Auth, {
issuer: '1',
client_id: '2',
redirect_uri: '3'
})
expect(mockAuthJsInstance.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);