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

fixes type declarations #1184

Closed
wants to merge 3 commits into from
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixes

- [#1182](https://github.com/okta/okta-auth-js/pull/1182) Fixes security question verification to accept `credentials.answer`
- [#1184](https://github.com/okta/okta-auth-js/pull/1184) Fixes type declarations: `ApiError`, `responseType`, `responseMode`

## 6.4.2

Expand Down
3 changes: 2 additions & 1 deletion lib/OktaAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
GetWithRedirectFunction,
RequestOptions,
IsAuthenticatedOptions,
OAuthResponseType,
} from './types';
import {
transactionStatus,
Expand Down Expand Up @@ -729,7 +730,7 @@ class OktaAuth implements OktaAuthInterface, SigninAPI, SignoutAPI {
return !!this.options.pkce;
}

hasResponseType(responseType: string): boolean {
hasResponseType(responseType: OAuthResponseType): boolean {
let hasResponseType = false;
if (Array.isArray(this.options.responseType) && this.options.responseType.length) {
hasResponseType = this.options.responseType.indexOf(responseType) >= 0;
Expand Down
4 changes: 2 additions & 2 deletions lib/errors/AuthApiError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
*/

import CustomError from './CustomError';
import { APIError, HttpResponse } from '../types';
import { APIError, FieldError, HttpResponse } from '../types';

export default class AuthApiError extends CustomError implements APIError {
errorSummary: string;
errorCode?: string;
errorLink?: string;
errorId?: string;
errorCauses?: string[];
errorCauses?: Array<FieldError>;
xhr?: HttpResponse;

constructor(err: APIError, xhr?: HttpResponse) {
Expand Down
4 changes: 2 additions & 2 deletions lib/errors/AuthSdkError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
*/

import CustomError from './CustomError';
import { APIError } from '../types';
import { APIError, FieldError } from '../types';

export default class AuthSdkError extends CustomError implements APIError {
errorSummary: string;
errorCode: string;
errorLink: string;
errorId: string;
errorCauses: string[];
errorCauses: Array<FieldError>;
xhr?: XMLHttpRequest;

constructor(msg: string, xhr?: XMLHttpRequest) {
Expand Down
22 changes: 2 additions & 20 deletions lib/idx/authenticate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,11 @@

import {
OktaAuthInterface,
IdxOptions,
IdxTransaction,
AuthenticatorKey
AuthenticatorKey,
AuthenticationOptions
} from '../types';
import { run } from './run';
import {
IdentifyValues,
SelectAuthenticatorAuthenticateValues,
ChallengeAuthenticatorValues,
ReEnrollAuthenticatorValues,
AuthenticatorEnrollmentDataValues,
SelectAuthenticatorEnrollValues,
EnrollAuthenticatorValues,
} from './remediators';

export type AuthenticationOptions = IdxOptions
& IdentifyValues
& SelectAuthenticatorAuthenticateValues
& SelectAuthenticatorEnrollValues
& ChallengeAuthenticatorValues
& ReEnrollAuthenticatorValues
& AuthenticatorEnrollmentDataValues
& EnrollAuthenticatorValues;

export async function authenticate(
authClient: OktaAuthInterface, options: AuthenticationOptions = {}
Expand Down
4 changes: 1 addition & 3 deletions lib/idx/cancel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@
* See the License for the specific language governing permissions and limitations under the License.
*/

import { OktaAuthInterface, IdxOptions, IdxTransactionMeta } from '../types';
import { OktaAuthInterface, CancelOptions, IdxTransactionMeta } from '../types';
import { run } from './run';
import { getFlowSpecification } from './flow';

export type CancelOptions = IdxOptions;

export async function cancel (authClient: OktaAuthInterface, options?: CancelOptions) {
const meta = authClient.transactionManager.load() as IdxTransactionMeta;
const flowSpec = getFlowSpecification(authClient, meta.flow);
Expand Down
20 changes: 2 additions & 18 deletions lib/idx/interact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,13 @@
* See the License for the specific language governing permissions and limitations under the License.
*/
/* eslint complexity:[0,8] */
import { OktaAuthInterface, IdxTransactionMeta } from '../types';
import { OktaAuthInterface, IdxTransactionMeta, InteractOptions, InteractResponse } from '../types';
import { getSavedTransactionMeta, saveTransactionMeta } from './transactionMeta';
import { getOAuthBaseUrl } from '../oidc';
import { createTransactionMeta } from '.';
import { removeNils } from '../util';
import { httpRequest } from '../http';

export interface InteractOptions {
withCredentials?: boolean;
state?: string;
scopes?: string[];
codeChallenge?: string;
codeChallengeMethod?: string;
activationToken?: string;
recoveryToken?: string;
clientSecret?: string;
}

export interface InteractResponse {
state?: string;
interactionHandle: string;
meta: IdxTransactionMeta;
}

/* eslint-disable camelcase */
export interface InteractParams {
Expand Down Expand Up @@ -92,7 +76,7 @@ export async function interact (
const url = `${baseUrl}/v1/interact`;
const params = {
client_id: clientId,
scope: scopes.join(' '),
scope: scopes!.join(' '),
redirect_uri: redirectUri,
code_challenge: codeChallenge,
code_challenge_method: codeChallengeMethod,
Expand Down
9 changes: 1 addition & 8 deletions lib/idx/introspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,13 @@
*/

import { makeIdxState, validateVersionConfig } from './idxState';
import { OktaAuthInterface } from '../types';
import { IntrospectOptions, OktaAuthInterface } from '../types';
import { IdxResponse, isRawIdxResponse } from './types/idx-js';
import { getOAuthDomain } from '../oidc';
import { IDX_API_VERSION } from '../constants';
import { httpRequest } from '../http';
import { isAuthApiError } from '../errors';

export interface IntrospectOptions {
withCredentials?: boolean;
interactionHandle?: string;
stateHandle?: string;
version?: string;
}

export async function introspect (
authClient: OktaAuthInterface,
options: IntrospectOptions = {}
Expand Down
17 changes: 1 addition & 16 deletions lib/idx/proceed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,12 @@
import {
OktaAuthInterface,
IdxTransaction,
ProceedOptions,
} from '../types';
import { run } from './run';
import { AuthenticationOptions } from './authenticate';
import {
EnrollPollValues as EnrollPollOptions,
SelectEnrollmentChannelValues as SelectEnrollmentChannelOptions
} from './remediators';
import { RegistrationOptions } from './register';
import { PasswordRecoveryOptions } from './recoverPassword';
import { AccountUnlockOptions } from './unlockAccount';
import { getSavedTransactionMeta } from './transactionMeta';
import { AuthSdkError } from '../errors';

export type ProceedOptions = AuthenticationOptions
& RegistrationOptions
& PasswordRecoveryOptions
& AccountUnlockOptions
& EnrollPollOptions
& SelectEnrollmentChannelOptions
& { step?: string };

export function canProceed(authClient: OktaAuthInterface, options: ProceedOptions = {}): boolean {
const meta = getSavedTransactionMeta(authClient, options);
return !!(meta || options.stateHandle);
Expand Down
18 changes: 1 addition & 17 deletions lib/idx/recoverPassword.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,13 @@


import { run } from './run';
import {
IdentifyValues,
SelectAuthenticatorAuthenticateValues,
ChallengeAuthenticatorValues,
AuthenticatorVerificationDataValues,
ResetAuthenticatorValues,
ReEnrollAuthenticatorValues,
} from './remediators';
import { getFlowSpecification } from './flow';
import {
OktaAuthInterface,
IdxOptions,
PasswordRecoveryOptions,
IdxTransaction,
} from '../types';

export type PasswordRecoveryOptions = IdxOptions
& IdentifyValues
& SelectAuthenticatorAuthenticateValues
& ChallengeAuthenticatorValues
& ResetAuthenticatorValues
& AuthenticatorVerificationDataValues
& ReEnrollAuthenticatorValues;

export async function recoverPassword(
authClient: OktaAuthInterface, options: PasswordRecoveryOptions = {}
): Promise<IdxTransaction> {
Expand Down
16 changes: 1 addition & 15 deletions lib/idx/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,14 @@
import { run } from './run';
import { hasSavedInteractionHandle } from './transactionMeta';
import { startTransaction } from './startTransaction';
import {
EnrollProfileValues,
SelectAuthenticatorEnrollValues,
EnrollAuthenticatorValues,
AuthenticatorEnrollmentDataValues,
SkipValues,
} from './remediators';
import { AuthSdkError } from '../errors';
import {
IdxOptions,
RegistrationOptions,
IdxTransaction,
OktaAuthInterface,
IdxFeature,
} from '../types';

export type RegistrationOptions = IdxOptions
& EnrollProfileValues
& SelectAuthenticatorEnrollValues
& EnrollAuthenticatorValues
& AuthenticatorEnrollmentDataValues
& SkipValues;

export async function register(
authClient: OktaAuthInterface, options: RegistrationOptions = {}
): Promise<IdxTransaction> {
Expand Down
10 changes: 1 addition & 9 deletions lib/idx/remediate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
/* eslint-disable max-statements, max-depth, complexity */
import { AuthSdkError } from '../errors';
import { RemediationValues } from './remediators';
import { FlowIdentifier, RemediationResponse } from './types';
import { RemediationFlow } from './flow';
import { RemediateOptions, RemediationResponse } from './types';
import {
IdxResponse,
IdxActionParams,
Expand All @@ -35,13 +34,6 @@ export interface RemediateActionWithOptionalParams {
}

export type RemediateAction = string | RemediateActionWithOptionalParams;
export interface RemediateOptions {
remediators?: RemediationFlow;
actions?: RemediateAction[];
flow?: FlowIdentifier;
step?: string;
shouldProceedWithEmailAuthenticator?: boolean; // will be removed in next major version
}


function getActionFromValues(values: RemediationValues, idxResponse: IdxResponse): string | undefined {
Expand Down
3 changes: 1 addition & 2 deletions lib/idx/remediators/AuthenticatorVerificationData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

import { AuthSdkError } from '../../errors';
import { AuthenticatorData, AuthenticatorDataValues } from './Base/AuthenticatorData';
import { IdxRemediation } from '../types/idx-js';
import { RemediateOptions } from '../remediate';
import { IdxRemediation, RemediateOptions } from '../types';

export type AuthenticatorVerificationDataValues = AuthenticatorDataValues;

Expand Down
4 changes: 2 additions & 2 deletions lib/idx/remediators/Base/Remediator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@


/* eslint-disable complexity */
import { NextStep, IdxMessage, Authenticator, Input, IdxOptions, RemediateOptions } from '../../types';
import { NextStep, IdxMessage, Authenticator, Input, RemediateOptions } from '../../types';
import { IdxAuthenticator, IdxRemediation, IdxContext } from '../../types/idx-js';
import { getAllValues, getRequiredValues, titleCase, getAuthenticatorFromRemediation } from '../util';
import { formatAuthenticator, compareAuthenticators } from '../../authenticator/util';

// A map from IDX data values (server spec) to RemediationValues (client spec)
export type IdxToRemediationValueMap = Record<string, string[]>;

export interface RemediationValues extends IdxOptions {
export interface RemediationValues {
stateHandle?: string;
authenticators?: (Authenticator | string)[];
authenticator?: string | Authenticator;
Expand Down
2 changes: 1 addition & 1 deletion lib/idx/remediators/EnrollmentChannelData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class EnrollmentChannelData extends Remediator<EnrollmentChannelDataValue
};
}

getValuesAfterProceed() {
getValuesAfterProceed(): EnrollmentChannelDataValues {
let trimmedValues = Object.keys(this.values).filter(valueKey => !['email', 'phoneNumber'].includes(valueKey));
return trimmedValues.reduce((values, valueKey) => ({...values, [valueKey]: this.values[valueKey]}), {});
}
Expand Down
2 changes: 1 addition & 1 deletion lib/idx/remediators/SelectEnrollmentChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class SelectEnrollmentChannel extends Remediator<SelectEnrollmentChannelV
};
}

getValuesAfterProceed() {
getValuesAfterProceed(): SelectEnrollmentChannelValues {
let trimmedValues = Object.keys(this.values).filter(valueKey => valueKey !== 'channel');
return trimmedValues.reduce((values, valueKey) => ({...values, [valueKey]: this.values[valueKey]}), {});
}
Expand Down
15 changes: 3 additions & 12 deletions lib/idx/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,23 @@
/* eslint-disable max-statements, complexity, max-depth */
import { interact } from './interact';
import { introspect } from './introspect';
import { remediate, RemediateOptions } from './remediate';
import { getFlowSpecification, RemediationFlow } from './flow';
import { remediate } from './remediate';
import { getFlowSpecification } from './flow';
import * as remediators from './remediators';
import {
OktaAuthInterface,
IdxStatus,
IdxTransaction,
IdxFeature,
NextStep,
FlowIdentifier,
RunOptions,
IdxTransactionMeta,
Tokens,
APIError,
} from '../types';
import { IdxMessage, IdxResponse, isIdxResponse } from './types/idx-js';
import { getSavedTransactionMeta, saveTransactionMeta } from './transactionMeta';
import { ProceedOptions } from './proceed';
import { getAvailableSteps, getEnabledFeatures, getMessagesFromResponse, isTerminalResponse } from './util';

export type RunOptions = ProceedOptions & RemediateOptions & {
flow?: FlowIdentifier;
remediators?: RemediationFlow;
actions?: string[];
withCredentials?: boolean;
}

declare interface RunData {
options: RunOptions;
values: remediators.RemediationValues;
Expand Down
6 changes: 3 additions & 3 deletions lib/idx/startTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
*/


import { run, RunOptions } from './run';
import { OktaAuthInterface, IdxTransaction } from '../types';
import { run } from './run';
import { OktaAuthInterface, IdxTransaction, StartOptions } from '../types';

export async function startTransaction(
authClient: OktaAuthInterface,
options: RunOptions = {}
options: StartOptions = {}
): Promise<IdxTransaction> {
// Clear IDX response cache and saved transaction meta (if any)
authClient.transactionManager.clear();
Expand Down
Loading