Skip to content

Commit

Permalink
Merge pull request #439 from ffddw/master
Browse files Browse the repository at this point in the history
Remove deprecated @okta/configuration-validation and integrate essential functions
  • Loading branch information
rajdeepnanua-okta authored Dec 16, 2024
2 parents a68453c + 2ffafc0 commit 7cea49c
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 121 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/okta-react-native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Execute snyk.sh
run: bash ./scripts/snyk.sh
iOSUnitTests:
runs-on: macos-12
runs-on: macos-13
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -43,7 +43,7 @@ jobs:
uses: actions/cache@v3
with:
path: ./ios/Pods
key: pods-${{ hashFiles('./ios/Podfile.lock') }}
key: pods-${{ hashFiles('./ios/Podfile.lock') }}
- name: Preparation before iOS Build
run: |
pod install --project-directory=ios --repo-update
Expand All @@ -56,19 +56,19 @@ jobs:
-destination "platform=iOS Simulator,OS=latest,name=iPhone 14" \
clean test | xcpretty
# iOSUITests:
# runs-on: macos-12
# runs-on: macos-13
# steps:
# - uses: actions/checkout@v3
# - name: Cache ./node_modules
# - name: Cache ./node_modules
# uses: ./.github/workflows/composite/configure-node
# with:
# with:
# node-path: ./node_modules
# lock-hash: ${{ hashFiles('yarn.lock') }}
# - name: Build okta-react-native package
# run: yarn build
# run: yarn build
# - name: Cache e2e/node_modules
# uses: ./.github/workflows/composite/configure-node
# with:
# with:
# node-path: ./e2e/node_modules
# lock-hash: ${{ hashFiles('./e2e/yarn.lock') }}
# install-path: ./e2e
Expand All @@ -88,11 +88,11 @@ jobs:
# cd ../..
# echo -e "CLIENT_ID=${{ secrets.CLIENT_ID }}\nISSUER=${{ secrets.ISSUER }}\nREDIRECT_URI=${{ secrets.REDIRECT_URI }}\nLOGOUT_REDIRECT_URI=${{secrets.LOGOUT_REDIRECT_URI}}" > e2e/.env
# - name: iOS
# env:
# env:
# OKTA_USERNAME: ${{ secrets.OKTA_USERNAME }}
# OKTA_PASSWORD: ${{ secrets.OKTA_PASSWORD }}
# run: |
# set -o pipefail
# run: |
# set -o pipefail
# xcodebuild \
# -workspace e2e/ios/E2EOktaReactNative.xcworkspace \
# -scheme E2EOktaReactNative \
Expand All @@ -116,7 +116,7 @@ jobs:

# - name: Configure node_modules
# uses: ./.github/workflows/composite/configure-node
# with:
# with:
# node-path: ./node_modules
# lock-hash: ${{ hashFiles('yarn.lock') }}

Expand All @@ -125,7 +125,7 @@ jobs:

# - name: Configure e2e/node_modules
# uses: ./.github/workflows/composite/configure-node
# with:
# with:
# node-path: ./e2e/node_modules
# lock-hash: ${{ hashFiles('./e2e/yarn.lock') }}
# install-path: ./e2e
Expand Down
97 changes: 75 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
*/

import { NativeModules, Platform, NativeEventEmitter } from 'react-native';
import { assertIssuer, assertClientId, assertRedirectUri } from '@okta/configuration-validation';
import { OktaAuth } from '@okta/okta-auth-js';
import Url from 'url-parse';
import { version, peerDependencies } from './package.json';
Expand Down Expand Up @@ -54,12 +53,66 @@ class OktaStatusError extends Error {
}
}

class ConfigurationValidationError extends Error {}
const findDomainURL = 'https://bit.ly/finding-okta-domain';
const findAppCredentialsURL = 'https://bit.ly/finding-okta-app-credentials';
const copyCredentialsMessage = 'You can copy it from the Okta Developer Console ' +
'in the details for the Application you created. ' +
`Follow these instructions to find it: ${findAppCredentialsURL}`;

const isHttps = new RegExp('^https://');
const hasDomainAdmin = /-admin.(okta|oktapreview|okta-emea).com/;

function assertIssuer(issuer, testing = {}){
const copyMessage = 'You can copy your domain from the Okta Developer ' +
'Console. Follow these instructions to find it: ' + findDomainURL;

if (testing.disableHttpsCheck) {
const httpsWarning = 'Warning: HTTPS check is disabled. ' +
'This allows for insecure configurations and is NOT recommended for production use.';
/* eslint-disable-next-line no-console */
console.warn(httpsWarning);
}

if (!issuer) {
throw new ConfigurationValidationError('Your Okta URL is missing. ' + copyMessage);
} else if (!testing.disableHttpsCheck && !issuer.match(isHttps)) {
throw new ConfigurationValidationError(
'Your Okta URL must start with https. ' +
`Current value: ${issuer}. ${copyMessage}`
);
} else if (issuer.match(/{yourOktaDomain}/)) {
throw new ConfigurationValidationError('Replace {yourOktaDomain} with your Okta domain. ' + copyMessage);
} else if (issuer.match(hasDomainAdmin)) {
throw new ConfigurationValidationError(
'Your Okta domain should not contain -admin. ' +
`Current value: ${issuer}. ${copyMessage}`
);
}
}

function assertClientId(clientId){
if (!clientId) {
throw new ConfigurationValidationError('Your client ID is missing. ' + copyCredentialsMessage);
} else if (clientId.match(/{clientId}/)) {
throw new ConfigurationValidationError('Replace {clientId} with the client ID of your Application. ' + copyCredentialsMessage);
}
}

function assertRedirectUri(redirectUri){
if (!redirectUri) {
throw new ConfigurationValidationError('Your redirect URI is missing.');
} else if (redirectUri.match(/{redirectUri}/)) {
throw new ConfigurationValidationError('Replace {redirectUri} with the redirect URI of your Application.');
}
}

/* eslint-disable max-params */
export function createConfigWithCallbacks(
issuer,
clientId,
redirectUri,
endSessionRedirectUri,
redirectUri,
endSessionRedirectUri,
discoveryUri,
scopes,
requireHardwareBackedKeyStore,
Expand All @@ -84,18 +137,18 @@ export function createConfigWithCallbacks(
token: {
storageProvider: storageProvider
}
},
},
issuer: issuer || origin,
clientId,
redirectUri,
scopes
};

authClient = new OktaAuth(oktaAuthConfig);

const reactNativeVersion = peerDependencies['react-native'];
const userAgentTemplate = `okta-react-native/${version} $UPSTREAM_SDK react-native/${reactNativeVersion} ${Platform.OS}/${Platform.Version}`;

if (authClient._oktaUserAgent) {
authClient._oktaUserAgent.addEnvironment(userAgentTemplate.replace('$UPSTREAM_SDK ', ''));
}
Expand Down Expand Up @@ -123,7 +176,7 @@ export function createConfigWithCallbacks(
httpConnectionTimeout,
httpReadTimeout,
};

NativeModules.OktaSdkBridge.createConfig(
clientId,
redirectUri,
Expand All @@ -145,8 +198,8 @@ export function createConfigWithCallbacks(
export const createConfig = async({
issuer,
clientId,
redirectUri,
endSessionRedirectUri,
redirectUri,
endSessionRedirectUri,
discoveryUri,
scopes,
requireHardwareBackedKeyStore,
Expand All @@ -160,8 +213,8 @@ export const createConfig = async({
createConfigWithCallbacks(
issuer,
clientId,
redirectUri,
endSessionRedirectUri,
redirectUri,
endSessionRedirectUri,
discoveryUri,
scopes,
requireHardwareBackedKeyStore,
Expand All @@ -178,12 +231,12 @@ export const createConfig = async({
}
);
});
};
};

export const getAuthClient = () => {
if (!authClient) {
throw new OktaAuthError(
'-100',
'-100',
'OktaOidc client isn\'t configured, check if you have created a configuration with createConfig'
);
}
Expand All @@ -198,10 +251,10 @@ export const signIn = async(options) => {
const { status, sessionToken } = transaction;
if (status !== 'SUCCESS') {
throw new OktaStatusError(
'Transaction status other than "SUCCESS" has been returned. Check transaction.status and handle accordingly.',
'Transaction status other than "SUCCESS" has been returned. Check transaction.status and handle accordingly.',
status
);
}
}

return authenticate({ sessionToken });
})
Expand All @@ -222,8 +275,8 @@ export const signIn = async(options) => {
};

export const signInWithBrowser = async(options = {}) => {
if (typeof options.noSSO === 'boolean') {
options.noSSO = options.noSSO.toString();
if (typeof options.noSSO === 'boolean') {
options.noSSO = options.noSSO.toString();
}

return NativeModules.OktaSdkBridge.signIn(options);
Expand Down Expand Up @@ -282,23 +335,23 @@ export const revokeRefreshToken = async() => {
};

export const introspectAccessToken = async() => {
return NativeModules.OktaSdkBridge.introspectAccessToken();
return NativeModules.OktaSdkBridge.introspectAccessToken();
};

export const introspectIdToken = async() => {
return NativeModules.OktaSdkBridge.introspectIdToken();
return NativeModules.OktaSdkBridge.introspectIdToken();
};

export const introspectRefreshToken = async() => {
return NativeModules.OktaSdkBridge.introspectRefreshToken();
return NativeModules.OktaSdkBridge.introspectRefreshToken();
};

export const refreshTokens = async() => {
return NativeModules.OktaSdkBridge.refreshTokens();
return NativeModules.OktaSdkBridge.refreshTokens();
};

export const clearTokens = async() => {
return NativeModules.OktaSdkBridge.clearTokens();
return NativeModules.OktaSdkBridge.clearTokens();
};

export const EventEmitter = new NativeEventEmitter(NativeModules.OktaSdkBridge);
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@
},
"dependencies": {
"@babel/plugin-transform-async-to-generator": "^7.24.7",
"@okta/configuration-validation": "^1.1.0",
"@okta/okta-auth-js": "7.7.0",
"@okta/okta-auth-js": "7.8.1",
"jscodeshift": "^0.15.2",
"jwt-decode": "^4.0.0",
"url-parse": "^1.5.10"
Expand Down Expand Up @@ -115,4 +114,4 @@
"tsd": {
"directory": "./dist/types"
}
}
}
Loading

0 comments on commit 7cea49c

Please sign in to comment.