Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: lock sdk with installed auth-js major version #122

Closed
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
- Removed `isPending` from `AuthState`
- Default value for `originalUri` is null

# 5.1.2

### Bug Fixes

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

# 5.1.1

Expand Down
3 changes: 3 additions & 0 deletions env.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
const path = require('path');
const dotenv = require('dotenv');
const fs = require('fs');
const semver = require('semver');

// Read information from package.json and expose as environment variables
const PACKAGE = require('./package.json');
process.env.PACKAGE_NAME = PACKAGE.name;
process.env.PACKAGE_VERSION = PACKAGE.version;
const authJsVersion = PACKAGE.dependencies['@okta/okta-auth-js'];
process.env.AUTH_JS_MAJOR_VERSION = semver.minVersion(authJsVersion).major;

// Read environment variables from "testenv". Override environment vars if they are already set.
const TESTENV = path.resolve(__dirname, 'testenv');
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"rollup-plugin-cleanup": "^3.2.1",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.29.0",
"semver": "^7.3.5",
"shelljs": "^0.8.4",
"ts-jest": "^26.4.4",
"typescript": "^4.0.5"
Expand All @@ -104,4 +105,4 @@
"./",
"test/e2e/harness"
]
}
}
3 changes: 2 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const commonPlugins = [
}),
replace({
'process.env.PACKAGE_NAME': JSON.stringify(process.env.PACKAGE_NAME),
'process.env.PACKAGE_VERSION': JSON.stringify(process.env.PACKAGE_VERSION)
'process.env.PACKAGE_VERSION': JSON.stringify(process.env.PACKAGE_VERSION),
'process.env.AUTH_JS_MAJOR_VERSION': JSON.stringify(process.env.AUTH_JS_MAJOR_VERSION)
}),
cleanup({
extensions,
Expand Down
15 changes: 15 additions & 0 deletions src/Security.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ const Security: React.FC<{
}
return oktaAuth.authStateManager.getAuthState();
});
const [oktaAuthMajorVersion] = React.useState(() => {
const majorVersion = oktaAuth?.userAgent?.split('/')[1]?.split('.')[0];
return majorVersion;
});

React.useEffect(() => {
if (!oktaAuth || !restoreOriginalUri) {
Expand Down Expand Up @@ -77,6 +81,17 @@ const Security: React.FC<{
return <OktaError error={err} />;
}


if (oktaAuthMajorVersion !== process.env.AUTH_JS_MAJOR_VERSION
// skip in test as version and userAgent are dynamic
&& process.env.NODE_ENV !== 'test') {
const err = 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.
`);
return <OktaError error={err} />;
}

return (
<OktaContext.Provider value={{
oktaAuth,
Expand Down
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12329,6 +12329,13 @@ semver@7.x, semver@^7.2.1, semver@^7.3.2:
dependencies:
lru-cache "^6.0.0"

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"

send@0.17.1:
version "0.17.1"
resolved "https://registry.yarnpkg.com/send/-/send-0.17.1.tgz#c1d8b059f7900f7466dd4938bdc44e11ddb376c8"
Expand Down