diff --git a/CHANGELOG.md b/CHANGELOG.md index ea7b6ec9df..8a6ff076e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - [#1003](https://github.com/okta/okta-auth-js/pull/1003) Supports generic UserClaims type. Custom claims should be extended by typescript generics, like `UserClaims<{ groups: string[]; }>` - [#1049](https://github.com/okta/okta-auth-js/pull/1049) Bump minimum supported node version to 12.20 +- [#1050](https://github.com/okta/okta-auth-js/pull/1050) Removes `userAgent` field from oktaAuth instance ## 5.10.1 diff --git a/lib/OktaAuth.ts b/lib/OktaAuth.ts index 9d842c43d2..1652756284 100644 --- a/lib/OktaAuth.ts +++ b/lib/OktaAuth.ts @@ -11,8 +11,7 @@ * * See the License for the specific language governing permissions and limitations under the License. */ -/* SDK_VERSION is defined in webpack config */ -/* global window, SDK_VERSION */ +/* global window */ import { DEFAULT_MAX_CLOCK_SKEW, @@ -92,7 +91,6 @@ import { EmailVerifyCallbackResponse, parseEmailVerifyCallback } from './util'; -import { getUserAgent } from './builderUtil'; import { TokenManager } from './TokenManager'; import { get, setRequestHeader } from './http'; import PromiseQueue from './PromiseQueue'; @@ -126,10 +124,6 @@ class OktaAuth implements SDKInterface, SigninAPI, SignoutAPI { transactionManager: TransactionManager; tx: TransactionAPI; idx: IdxAPI; - // keep this field to compatible with released downstream SDK versions - // TODO: remove in version 6 - // JIRA: https://oktainc.atlassian.net/browse/OKTA-419417 - userAgent: string; session: SessionAPI; pkce: PkceAPI; static features: FeaturesAPI; @@ -181,9 +175,6 @@ class OktaAuth implements SDKInterface, SigninAPI, SignoutAPI { this.options = Object.assign(this.options, { redirectUri: toAbsoluteUrl(args.redirectUri, window.location.origin), // allow relative URIs }); - this.userAgent = getUserAgent(args, `okta-auth-js/${SDK_VERSION}`); - } else { - this.userAgent = getUserAgent(args, `okta-auth-js-server/${SDK_VERSION}`); } // Digital clocks will drift over time, so the server diff --git a/lib/builderUtil.ts b/lib/builderUtil.ts index c427ce1a05..7a3876cef6 100644 --- a/lib/builderUtil.ts +++ b/lib/builderUtil.ts @@ -42,21 +42,6 @@ function assertValidConfig(args: OktaAuthOptions) { } } -function getUserAgent(args: OktaAuthOptions, sdkValue: string): string { - var userAgent = args.userAgent || {}; - - if (userAgent.value) { - return userAgent.value; - } - - if (userAgent.template) { - return userAgent.template.replace('$OKTA_AUTH_JS', sdkValue); - } - - return sdkValue; -} - export { - assertValidConfig, - getUserAgent + assertValidConfig }; diff --git a/lib/types/OktaAuthOptions.ts b/lib/types/OktaAuthOptions.ts index 339f2242e9..0eb3f3d01a 100644 --- a/lib/types/OktaAuthOptions.ts +++ b/lib/types/OktaAuthOptions.ts @@ -29,10 +29,7 @@ export interface TokenManagerOptions { syncStorage?: boolean; _storageEventDelay?: number; } -export interface CustomUserAgent { - template?: string; - value?: string; -} + export interface CustomUrls { issuer?: string; authorizeUrl?: string; @@ -57,7 +54,6 @@ export interface OktaAuthOptions extends CustomUrls { storageUtil?: StorageUtil; ajaxRequest?: object; httpRequestClient?: HttpRequestClient; - userAgent?: CustomUserAgent; cookies?: CookieOptions; transformErrorXHR?: (xhr: object) => any; headers?: object; diff --git a/lib/types/api.ts b/lib/types/api.ts index 3eaf7af056..3053516400 100644 --- a/lib/types/api.ts +++ b/lib/types/api.ts @@ -35,7 +35,6 @@ import { IntrospectOptions } from '../idx/introspect'; import { IdxResponse } from '../idx/types/idx-js'; export interface OktaAuth { options: OktaAuthOptions; - userAgent: string; getIssuerOrigin(): string; getOriginalUri(): string; diff --git a/test/spec/OktaAuth/browser.ts b/test/spec/OktaAuth/browser.ts index 0d3afc1b99..c0dbfb560b 100644 --- a/test/spec/OktaAuth/browser.ts +++ b/test/spec/OktaAuth/browser.ts @@ -55,18 +55,6 @@ describe('OktaAuth (browser)', function() { auth = new OktaAuth({ issuer, pkce: false }); }); - // TODO: remove in 6.0 - describe('userAgent', () => { - let sdkVersion; - beforeEach(async () => { - sdkVersion = (await import('../../../package.json')).version; - }); - - it('initials userAgent field', () => { - expect(auth.userAgent).toBe(`okta-auth-js/${sdkVersion}`); - }); - }); - describe('options', function() { describe('cookies', () => { diff --git a/test/spec/OktaAuth/constructor.ts b/test/spec/OktaAuth/constructor.ts index 6e23fe7881..ffcb42d6bb 100644 --- a/test/spec/OktaAuth/constructor.ts +++ b/test/spec/OktaAuth/constructor.ts @@ -24,10 +24,6 @@ jest.mock('../../../lib/features', () => { }; }); -const mocked = { - features: require('../../../lib/features') -}; - describe('OktaAuth (constructor)', () => { const apiUrlOptions = [ 'issuer', @@ -153,20 +149,4 @@ describe('OktaAuth (constructor)', () => { }); }); - // TODO: remove in 6.0 - describe('userAgent', () => { - let sdkVersion; - beforeEach(async () => { - sdkVersion = (await import('../../../package.json')).version; - }); - - // browser env is tested in "./browser.ts" - it('initials userAgent field for node env', () => { - jest.spyOn(mocked.features, 'isBrowser').mockReturnValue(false); - const config = { issuer: 'http://fake' }; - const oa = new OktaAuth(config); - expect(oa.userAgent).toBe(`okta-auth-js-server/${sdkVersion}`); - }); - }); - }); diff --git a/test/spec/builderUtil.js b/test/spec/builderUtil.js deleted file mode 100644 index 2ad1df78b5..0000000000 --- a/test/spec/builderUtil.js +++ /dev/null @@ -1,66 +0,0 @@ -/*! - * Copyright (c) 2015-present, Okta, Inc. and/or its affiliates. All rights reserved. - * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") - * - * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * - * See the License for the specific language governing permissions and limitations under the License. - */ - - -const builderUtil = require('../../lib/builderUtil'); - -describe('builderUtil', () => { - - describe('getUserAgent', () => { - it('should return userAgent if "userAgent.value" is provided in args', () => { - const args = { - userAgent: { - value: 'fake userAgent' - } - }; - const userAgent = builderUtil.getUserAgent(args); - expect(userAgent).toEqual('fake userAgent'); - }); - it('replaces "$OKTA_AUTH_JS" with current authJs user agent if userAgentTemplate in args', () => { - const args = { - userAgent: { - template: 'fake userAgent $OKTA_AUTH_JS' - } - }; - const sdkUserAgentValue = 'okta-auth-js/0.0.0'; - const userAgent = builderUtil.getUserAgent(args, sdkUserAgentValue); - expect(userAgent).toEqual(`fake userAgent okta-auth-js/0.0.0`); - }); - it('should return undefined if no userAgent object is in args', () => { - const args = {}; - const userAgent = builderUtil.getUserAgent(args); - expect(userAgent).toEqual(undefined); - }); - it('should return undefined if neither with userAgent.value nor userAgent.template in args', () => { - const args = { - userAgent: {} - }; - const userAgent = builderUtil.getUserAgent(args); - expect(userAgent).toEqual(undefined); - }); - it('should return sdk defined user agent if no userAgent object is in args', () => { - const args = {}; - const sdkUserAgentValue = 'okta-auth-js-fake/0.0.0'; - const userAgent = builderUtil.getUserAgent(args, sdkUserAgentValue); - expect(userAgent).toEqual('okta-auth-js-fake/0.0.0'); - }); - it('should return sdk defined user agent if neither with userAgent.value nor userAgent.template in args', () => { - const args = { - userAgent: {} - }; - const sdkUserAgentValue = 'okta-auth-js-fake/0.0.0'; - const userAgent = builderUtil.getUserAgent(args, sdkUserAgentValue); - expect(userAgent).toEqual('okta-auth-js-fake/0.0.0'); - }); - }); - -});