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

Remove deprecated @okta/configuration-validation and integrate essential functions #439

Merged
merged 2 commits into from
Dec 16, 2024
Merged
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
24 changes: 12 additions & 12 deletions .github/workflows/okta-react-native.yml
Original file line number Diff line number Diff line change
@@ -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
@@ -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
@@ -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
@@ -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 \
@@ -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') }}

@@ -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
97 changes: 75 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
@@ -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';
@@ -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.');
}
}

Comment on lines +56 to +109
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy and convert javascript based configuration-validation

/* eslint-disable max-params */
export function createConfigWithCallbacks(
issuer,
clientId,
redirectUri,
endSessionRedirectUri,
redirectUri,
endSessionRedirectUri,
discoveryUri,
scopes,
requireHardwareBackedKeyStore,
@@ -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 ', ''));
}
@@ -123,7 +176,7 @@ export function createConfigWithCallbacks(
httpConnectionTimeout,
httpReadTimeout,
};

NativeModules.OktaSdkBridge.createConfig(
clientId,
redirectUri,
@@ -145,8 +198,8 @@ export function createConfigWithCallbacks(
export const createConfig = async({
issuer,
clientId,
redirectUri,
endSessionRedirectUri,
redirectUri,
endSessionRedirectUri,
discoveryUri,
scopes,
requireHardwareBackedKeyStore,
@@ -160,8 +213,8 @@ export const createConfig = async({
createConfigWithCallbacks(
issuer,
clientId,
redirectUri,
endSessionRedirectUri,
redirectUri,
endSessionRedirectUri,
discoveryUri,
scopes,
requireHardwareBackedKeyStore,
@@ -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'
);
}
@@ -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 });
})
@@ -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);
@@ -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
@@ -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"
@@ -115,4 +114,4 @@
"tsd": {
"directory": "./dist/types"
}
}
}
Loading