Skip to content

Commit

Permalink
https://oktainc.atlassian.net/browse/OKTA-395383
Browse files Browse the repository at this point in the history
OKTA-395383
<<<Jenkins Check-In of Tested SHA: eab84ba for [email protected]>>>
Artifact: okta-vue
Files changed count: 8
PR Link: "#61"
  • Loading branch information
oleksandrpravosudko-okta authored and eng-prod-CI-bot-okta committed May 13, 2021
1 parent fc6246a commit 4f719e3
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 3 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
[authState]: https://github.com/okta/okta-auth-js#authstatemanager
# 4.0.1

### Bug Fixes

- [#60](https://github.com/okta/okta-vue/pull/60) Locks the SDK with installed okta-auth-js major version

# 4.0.0

Expand Down
2 changes: 2 additions & 0 deletions MIGRATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ const oktaAuth = new OktaAuth({
Vue.use(OktaVue, { oktaAuth })
```

> Note: Major version of supplied `@okta/okta-auth-js` SDK insntance should match the major version of `@okta/okta-auth-js` peerDependency of `@okta/okta-vue` SDK.
### Full `@okta/okta-auth-js` API is available

`@okta/okta-vue` version 2.x and earlier provided a wrapper around [@okta/okta-auth-js][] but many methods were hidden. Version 3.x replaces `Auth` service with instance of [@okta/okta-auth-js][] for `$auth`, so the full [api](https://github.com/okta/okta-auth-js#api-reference) and all [options](https://github.com/okta/okta-auth-js#configuration-options) are now supported by this SDK. To provide a better experience, several methods which existed on the wrapper have been removed or replaced.
Expand Down
4 changes: 4 additions & 0 deletions env.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const PACKAGE = require('./package.json')
const path = require('path')
const dotenv = require('dotenv')
const fs = require('fs')
const semver = require('semver')

// Read environment variables from "testenv". Override environment vars if they are already set.
const TESTENV = path.resolve(__dirname, 'testenv')
Expand All @@ -16,6 +17,9 @@ if (fs.existsSync(TESTENV)) {
}
process.env.CLIENT_ID = process.env.CLIENT_ID || process.env.SPA_CLIENT_ID

const authJsVersion = PACKAGE.peerDependencies['@okta/okta-auth-js'];
process.env.AUTH_JS_MAJOR_VERSION = semver.minVersion(authJsVersion).major;

module.exports = (overrides = {}) => {
const PORT = overrides.port || process.env.PORT || 3000
const BASE_URI = process.env.BASE_URI || `http://localhost:${PORT}`
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.29.0",
"rollup-plugin-vue": "^6.0.0-beta.11",
"semver": "^7.3.5",
"shelljs": "0.8.3",
"ts-jest": "^26.4.4",
"typescript": "^4.1.2",
Expand Down
3 changes: 2 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const input = 'src/index.ts'

const commonPlugins = [
replace({
PACKAGE: JSON.stringify(ENV.packageInfo)
PACKAGE: JSON.stringify(ENV.packageInfo),
'process.env.AUTH_JS_MAJOR_VERSION': JSON.stringify(process.env.AUTH_JS_MAJOR_VERSION)
}),
cleanup()
]
Expand Down
8 changes: 8 additions & 0 deletions src/okta-vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ function install (app: App, {
throw new AuthSdkError('No oktaAuth instance passed to OktaVue.')
}

const oktaAuthMajorVersion = oktaAuth.userAgent?.split('/')[1]?.split('.')[0];
if (oktaAuthMajorVersion && oktaAuthMajorVersion !== process.env.AUTH_JS_MAJOR_VERSION) {
throw new AuthSdkError(`
Passed in oktaAuth is not compatible with the SDK,
okta-auth-js version ${process.env.AUTH_JS_MAJOR_VERSION}.x is the current supported version.
`);
}

_oktaAuth = oktaAuth
_onAuthRequired = onAuthRequired

Expand Down
9 changes: 8 additions & 1 deletion test/specs/OktaVue.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import { mount } from '@vue/test-utils'
import waitForExpect from 'wait-for-expect'
import { OktaAuth } from '@okta/okta-auth-js'
import { AuthSdkError, OktaAuth } from '@okta/okta-auth-js'
import OktaVue from '../../src/okta-vue'
import { App } from '../components'

Expand Down Expand Up @@ -57,6 +57,11 @@ describe('OktaVue', () => {
expect(wrapper.vm.$auth.userAgent).toBe(`${pkg.name}/${pkg.version} foo`)
})

it('throws when provided OktaAuth instance of unsupported version', () => {
oktaAuth.userAgent = 'okta-auth-js/99.0.42';
expect(() => bootstrap()).toThrow(AuthSdkError);
})

describe('restoreOriginalUri', () => {
const mockOriginalUri = 'http://localhost/fakepath'
it('should call restoreOriginalUri callback if provided when calls restoreOriginalUri', () => {
Expand Down Expand Up @@ -118,6 +123,8 @@ describe('OktaVue', () => {
bootstrap()
expect(wrapper.find('#state').text()).toBe('not authenticated')

// reset modified auth-js' userAgent
setupOktaAuth()
oktaAuth.authStateManager.getAuthState = jest.fn().mockReturnValue({
isPending: false,
isAuthenticated: true
Expand Down
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9869,6 +9869,13 @@ semver@^6.0.0, semver@^6.1.0, semver@^6.3.0:
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==

semver@^7.3.5:
version "7.3.5"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.5.tgz#0b621c879348d8998e4b0e4be94b3f12e6018ef7"
integrity sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==
dependencies:
lru-cache "^6.0.0"

[email protected]:
version "0.17.1"
resolved "https://registry.yarnpkg.com/send/-/send-0.17.1.tgz#c1d8b059f7900f7466dd4938bdc44e11ddb376c8"
Expand Down

0 comments on commit 4f719e3

Please sign in to comment.