Skip to content

Commit

Permalink
feat: accepts oktaAuthConfig when creating authClient - OKTA-385237
Browse files Browse the repository at this point in the history
doc: update changelog
lint
use tsd
remove dtslint
update 8ac0n yml

OKTA-385237
<<<Jenkins Check-In of Tested SHA: 3637d52 for [email protected]>>>
Artifact: okta-react-native
Files changed count: 10
PR Link: "#147"
  • Loading branch information
shuowu authored and eng-prod-CI-bot-okta committed Jun 22, 2021
1 parent ac1953e commit 6aae113
Show file tree
Hide file tree
Showing 10 changed files with 391 additions and 566 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ jobs:
- sudo apt-get update
- sudo apt-get install -y libappindicator1
script:
- yarn eslint
- yarn dtslint
- yarn lint
- yarn test
- bash ./scripts/snyk.sh
- language: objective-c
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 1.12.0

### Feature

- [#147](https://github.com/okta/okta-react-native/pull/147) Accepts `oktaAuthConfig` in `createConfig` method to pass configuration for generating the `authClient`(OktaAuth instance).

# 1.11.1

### Bug Fix
Expand Down
12 changes: 10 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const createConfig = async({
httpConnectionTimeout,
httpReadTimeout,
browserMatchAll = false,
oktaAuthConfig = {}
}) => {

assertIssuer(discoveryUri);
Expand All @@ -57,12 +58,19 @@ export const createConfig = async({

const userAgentTemplate = `@okta/okta-react-native/${version} $UPSTREAM_SDK react-native/${version} ${Platform.OS}/${Platform.Version}`;
const { origin } = new Url(discoveryUri);
authClient = new OktaAuth({

oktaAuthConfig = {
...oktaAuthConfig,
issuer: issuer || origin,
clientId,
redirectUri,
scopes,
userAgent: {
template: userAgentTemplate.replace('$UPSTREAM_SDK', '$OKTA_AUTH_JS')
}
});
};

authClient = new OktaAuth(oktaAuthConfig);

if (Platform.OS === 'ios') {
scopes = scopes.join(' ');
Expand Down
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "@okta/okta-react-native",
"title": "React Native Okta Sdk Bridge",
"version": "1.12.0",
"types": "dist/types/index.d.ts",
"types": "types/index.d.ts",
"description": "Okta OIDC for React Native",
"main": "dist/index.js",
"podname": "OktaSdkBridgeReactNative",
Expand All @@ -13,8 +13,8 @@
"lint": "eslint .",
"lint:report": "eslint -f checkstyle -o ./test-reports/lint/eslint-checkstyle-result.xml .",
"prepare": "yarn build",
"test": "jest",
"dtslint": "dtslint ./types",
"test": "jest && tsd",
"tsd": "tsd",
"test:debug": "node --inspect-brk node_modules/jest/bin/jest.js --runInBand"
},
"repository": {
Expand Down Expand Up @@ -60,7 +60,6 @@
"@typescript-eslint/parser": "^4.14.2",
"babel-jest": "^25.1.0",
"chalk": "^4.1.0",
"dtslint": "^4.0.6",
"eslint": "^7.19.0",
"eslint-plugin-jest": "^24.1.3",
"eslint-plugin-node": "^11.1.0",
Expand All @@ -70,6 +69,7 @@
"react": "^16.13.0",
"react-native": "^0.63.0",
"shelljs": "^0.8.4",
"tsd": "^0.17.0",
"typescript": "^4.1.3"
},
"dependencies": {
Expand Down Expand Up @@ -102,5 +102,8 @@
"jest-junit": {
"outputDirectory": "./test-reports/unit/",
"outputName": "junit-result.xml"
},
"tsd": {
"directory": "./dist/types"
}
}
}
5 changes: 0 additions & 5 deletions scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ if ! yarn lint:report; then
exit ${TEST_FAILURE}
fi

if ! yarn dtslint; then
echo "DTS lint failed! Exiting..."
exit 1
fi

echo ${TEST_SUITE_TYPE} > ${TEST_SUITE_TYPE_FILE}
echo ${TEST_RESULT_FILE_DIR} > ${TEST_RESULT_FILE_DIR_FILE}
exit ${PUBLISH_TYPE_AND_RESULT_DIR_BUT_SUCCEED_IF_NO_RESULTS}
42 changes: 33 additions & 9 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,17 @@ describe('OktaReactNative', () => {

describe('createConfigTest', () => {
let mockCreateConfig;

const config = {
clientId: 'dummy_client_id',
redirectUri: 'dummy://redirect',
endSessionRedirectUri: 'dummy://endSessionRedirect',
discoveryUri: 'https://dummy_issuer',
scopes: ['scope1'],
requireHardwareBackedKeyStore: true
};
let config;

beforeEach(() => {
config = {
clientId: 'dummy_client_id',
redirectUri: 'dummy://redirect',
endSessionRedirectUri: 'dummy://endSessionRedirect',
discoveryUri: 'https://dummy_issuer',
scopes: ['scope1'],
requireHardwareBackedKeyStore: true
};
mockCreateConfig = require('react-native').NativeModules.OktaSdkBridge.createConfig;
mockCreateConfig.mockReset();
OktaAuth.mockClear();
Expand All @@ -105,6 +105,30 @@ describe('OktaReactNative', () => {
message: 'OktaOidc client isn\'t configured, check if you have created a configuration with createConfig'
});
});

it('applies oktaAuthConfig when initialize authClient', async () => {
Platform.OS = 'ios';
Platform.Version = '1.0.0';
config = {
...config,
oktaAuthConfig: {
mockConfig1: 'mock config 1',
mockConfig2: 'mock config 2'
}
};
await createConfig(config);
expect(OktaAuth).toHaveBeenCalledWith({
issuer: 'https://dummy_issuer',
clientId: 'dummy_client_id',
redirectUri: 'dummy://redirect',
scopes: ['scope1'],
userAgent: {
template: `@okta/okta-react-native/${version} $OKTA_AUTH_JS react-native/${version} ios/1.0.0`,
},
mockConfig1: 'mock config 1',
mockConfig2: 'mock config 2'
});
});

it('passes in correct parameters on ios device', () => {
Platform.OS = 'ios';
Expand Down
93 changes: 0 additions & 93 deletions types/index-test.ts

This file was deleted.

2 changes: 2 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable camelcase */
import { OktaAuthOptions } from '@okta/okta-auth-js';

export function createConfig(config: Okta.ConfigParameters): Promise<boolean>;

Expand Down Expand Up @@ -67,6 +68,7 @@ export namespace Okta {
httpConnectionTimeout?: number;
httpReadTimeout?: number;
browserMatchAll?: boolean;
oktaAuthConfig?: OktaAuthOptions;
}

interface AuthenticationResponse {
Expand Down
73 changes: 73 additions & 0 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (c) 2021-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.
*/


/* eslint-disable node/no-missing-import, camelcase */
import OktaSDK, { Okta } from './index';
import { expectType } from 'tsd';

expectType<Promise<boolean>>(OktaSDK.createConfig({
issuer: '{issuer}',
clientId: '{clientID}',
redirectUri: '{redirectUri}',
endSessionRedirectUri: '{endSessionRedirectUri}',
discoveryUri: '{discoveryUri}',
scopes: ['scope1', 'scope2'],
requireHardwareBackedKeyStore: false,
androidChromeTabColor: '#00000',
httpConnectionTimeout: 15,
httpReadTimeout: 10,
browserMatchAll: false,
oktaAuthConfig: {}
}));

expectType<Okta.StringAnyMap>(OktaSDK.getAuthClient());

expectType<Promise<Okta.AuthenticationResponse>>(OktaSDK.signIn());

expectType<Promise<Okta.AuthenticationResponse>>(OktaSDK.signIn({ username: '{username}', password: '{password}' }));

expectType<Promise<Okta.AuthenticationResponse>>(OktaSDK.signInWithBrowser());

expectType<Promise<Okta.AuthenticationResponse>>(OktaSDK.signInWithBrowser({ idp: '{idp}' }));

expectType<Promise<Okta.AuthenticationResponse>>(OktaSDK.signInWithBrowser({ noSSO: true }));

expectType<Promise<Okta.AuthenticationResponse>>(OktaSDK.authenticate('{sessionToken}'));

expectType<Promise<{ resolve_type: string; }>>(OktaSDK.signOut());

expectType<Promise<{ id_token: string; }>>(OktaSDK.getIdToken());

expectType<Promise<{ access_token: string; }>>(OktaSDK.getAccessToken());

expectType<Promise<Okta.StringAnyMap>>(OktaSDK.getUser());

expectType<Promise<Okta.StringAnyMap>>(OktaSDK.getUserFromIdToken());

expectType<Promise<{ authenticated: boolean; }>>(OktaSDK.isAuthenticated());

expectType<Promise<boolean>>(OktaSDK.revokeAccessToken());

expectType<Promise<boolean>>(OktaSDK.revokeIdToken());

expectType<Promise<boolean>>(OktaSDK.revokeRefreshToken());

expectType<Promise<Okta.StringAnyMap>>(OktaSDK.introspectAccessToken());

expectType<Promise<Okta.StringAnyMap>>(OktaSDK.introspectIdToken());

expectType<Promise<Okta.StringAnyMap>>(OktaSDK.introspectRefreshToken());

expectType<Promise<Okta.RefreshResponse>>(OktaSDK.refreshTokens());

expectType<Promise<boolean>>(OktaSDK.clearTokens());
Loading

0 comments on commit 6aae113

Please sign in to comment.