-
Notifications
You must be signed in to change notification settings - Fork 265
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
Minimal idx factory for SIW gen3 (v2) #1476
Changes from 10 commits
93197b0
5f396c5
4319cbf
172ad3e
a13df24
f86a098
8c7f091
2154c2e
c3046fd
b0af858
f182ecf
e1d48d5
5104946
b4489f4
b94d556
06d6f4c
a22be58
947c968
c628c6f
dd75243
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { OktaAuth } from '../idx-minimal'; | ||
|
||
// Export only a single object | ||
export default OktaAuth; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import type { | ||
OktaAuthOptionsConstructor, | ||
} from '../base/types'; | ||
|
||
import { | ||
IdxStorageManagerConstructor, | ||
IdxTransactionManagerConstructor, | ||
OktaAuthIdxOptions, | ||
} from '../idx/types'; | ||
import { createIdxTransactionManager } from '../idx/IdxTransactionManager'; | ||
import { createMinimalOktaAuthIdx } from '../idx/factory/MinimalOktaAuthIdx'; | ||
import { createIdxStorageManager } from '../idx/storage'; | ||
import { createIdxOptionsConstructor } from '../idx/options'; | ||
|
||
const OptionsConstructor: OktaAuthOptionsConstructor<OktaAuthIdxOptions> = createIdxOptionsConstructor(); | ||
const StorageManager: IdxStorageManagerConstructor = createIdxStorageManager(); | ||
const TransactionManager: IdxTransactionManagerConstructor = createIdxTransactionManager(); | ||
|
||
const OktaAuthIdx = createMinimalOktaAuthIdx(StorageManager, OptionsConstructor, TransactionManager); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface OktaAuthOptions extends OktaAuthIdxOptions {} | ||
|
||
class OktaAuth extends OktaAuthIdx { | ||
constructor(options: OktaAuthOptions) { | ||
super(options); | ||
} | ||
} | ||
|
||
export default OktaAuth; | ||
export { OktaAuth }; | ||
|
||
export * from '../base/types'; | ||
export * from '../constants'; | ||
export * from '../core/types'; | ||
export * from '../errors'; | ||
export * from '../http/types'; | ||
export * from '../oidc/types'; | ||
export * from '../session/types'; | ||
export * from '../storage/types'; | ||
export * from '../util/types'; | ||
|
||
export * from '../idx/types'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { OktaAuthOptionsConstructor } from '../../base/types'; | ||
import { StorageManagerConstructor } from '../../storage/types'; | ||
import { IdxTransactionManagerInterface, MinimalOktaAuthIdxInterface, OktaAuthIdxConstructor } from '../types/api'; | ||
import { IdxTransactionMeta } from '../types/meta'; | ||
import { IdxStorageManagerInterface } from '../types/storage'; | ||
import { OktaAuthIdxOptions } from '../types/options'; | ||
import { TransactionManagerConstructor, OktaAuthBaseOAuthInterface } from '../../oidc/types'; | ||
import { mixinMinimalIdx } from '../mixinMinimal'; | ||
import { createOktaAuthBase } from '../../base/factory'; | ||
import { mixinStorage } from '../../storage/mixin'; | ||
import { mixinHttp } from '../../http/mixin'; | ||
import { mixinSession } from '../../session/mixin'; | ||
import { mixinMinimalOAuth } from '../../oidc/mixin/minimal'; | ||
|
||
export function createMinimalOktaAuthIdx< | ||
M extends IdxTransactionMeta = IdxTransactionMeta, | ||
S extends IdxStorageManagerInterface<M> = IdxStorageManagerInterface<M>, | ||
O extends OktaAuthIdxOptions = OktaAuthIdxOptions, | ||
TM extends IdxTransactionManagerInterface = IdxTransactionManagerInterface | ||
>( | ||
StorageManagerConstructor: StorageManagerConstructor<S>, | ||
OptionsConstructor: OktaAuthOptionsConstructor<O>, | ||
TransactionManagerConstructor: TransactionManagerConstructor<TM> | ||
) | ||
: OktaAuthIdxConstructor< | ||
MinimalOktaAuthIdxInterface<M, S, O, TM> & OktaAuthBaseOAuthInterface<M, S, O, TM> | ||
> | ||
{ | ||
const Base = createOktaAuthBase(OptionsConstructor); | ||
const WithStorage = mixinStorage<S, O>(Base, StorageManagerConstructor); | ||
const WithHttp = mixinHttp<S, O>(WithStorage); | ||
const WithSession = mixinSession<S, O>(WithHttp); | ||
const WithOAuth = mixinMinimalOAuth<M, S, O, TM>(WithSession, TransactionManagerConstructor); | ||
// do not mixin core | ||
const WithIdx = mixinMinimalIdx(WithOAuth); | ||
return WithIdx; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './api'; | ||
export * from './OktaAuthIdx'; | ||
export * from './MinimalOktaAuthIdx'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/*! | ||
* 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. | ||
* | ||
*/ | ||
|
||
import { makeIdxState } from '../idxState'; | ||
import { canProceed, proceed } from '../proceed'; | ||
import { startTransaction } from '../startTransaction'; | ||
import { | ||
clearTransactionMeta, | ||
createTransactionMeta, | ||
getSavedTransactionMeta, | ||
getTransactionMeta, | ||
isTransactionMetaValid, | ||
saveTransactionMeta | ||
} from '../transactionMeta'; | ||
import { MinimalIdxAPI, MinimalOktaAuthIdxInterface } from '../types'; | ||
|
||
// Factory | ||
export function createMinimalIdxAPI(sdk: MinimalOktaAuthIdxInterface): MinimalIdxAPI { | ||
const boundStartTransaction = startTransaction.bind(null, sdk); | ||
const idx = { | ||
makeIdxResponse: makeIdxState.bind(null, sdk), | ||
|
||
start: boundStartTransaction, | ||
startTransaction: boundStartTransaction, // Use `start` instead. `startTransaction` will be removed in 7.0 | ||
proceed: proceed.bind(null, sdk), | ||
canProceed: canProceed.bind(null, sdk), | ||
|
||
getSavedTransactionMeta: getSavedTransactionMeta.bind(null, sdk), | ||
createTransactionMeta: createTransactionMeta.bind(null, sdk), | ||
getTransactionMeta: getTransactionMeta.bind(null, sdk), | ||
saveTransactionMeta: saveTransactionMeta.bind(null, sdk), | ||
clearTransactionMeta: clearTransactionMeta.bind(null, sdk), | ||
isTransactionMetaValid, | ||
}; | ||
return idx; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,22 +11,22 @@ | |
*/ | ||
|
||
/* eslint-disable max-len */ | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-nocheck | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed |
||
import { OktaAuthIdxInterface } from '../../types'; // auth-js/types | ||
|
||
import { MinimalOktaAuthIdxInterface, IdxResponse, IdxRemediation, IdxContext } from '../../types'; // auth-js/types | ||
import { IdxActions } from '../../types/idx-js'; | ||
import { generateRemediationFunctions } from './remediationParser'; | ||
import generateIdxAction from './generateIdxAction'; | ||
import { jsonpath } from '../../../util/jsonpath'; | ||
import { AuthSdkError } from '../../../errors'; | ||
|
||
const SKIP_FIELDS = Object.fromEntries([ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using |
||
'remediation', // remediations are put into proceed/neededToProceed | ||
'context', // the API response of 'context' isn't externally useful. We ignore it and put all non-action (contextual) info into idxState.context | ||
].map( (field) => [ field, !!'skip this field' ] )); | ||
const SKIP_FIELDS = { | ||
'remediation': true, // remediations are put into proceed/neededToProceed | ||
'context': true, // the API response of 'context' isn't externally useful. We ignore it and put all non-action (contextual) info into idxState.context | ||
}; | ||
|
||
export const parseNonRemediations = function parseNonRemediations( authClient: OktaAuthIdxInterface, idxResponse, toPersist = {} ) { | ||
export const parseNonRemediations = function parseNonRemediations( authClient: MinimalOktaAuthIdxInterface, idxResponse: IdxResponse, toPersist = {} ) { | ||
const actions = {}; | ||
const context = {}; | ||
const context = {} as IdxContext; | ||
|
||
Object.keys(idxResponse) | ||
.filter( field => !SKIP_FIELDS[field]) | ||
|
@@ -56,10 +56,12 @@ export const parseNonRemediations = function parseNonRemediations( authClient: O | |
|
||
// We are an object field containing an object value | ||
context[field].value = {}; | ||
Object.entries(fieldValue) | ||
Object.entries<IdxRemediation>(fieldValue) | ||
.forEach( ([subField, value]) => { | ||
if (value.rel) { // is [field].value[subField] an action? | ||
// add any "action" value subfields to actions | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the TS error being ignored here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Error in |
||
actions[`${field}-${subField.name || subField}`] = generateIdxAction(authClient, value, toPersist); | ||
} else { | ||
// add non-action value subfields to context | ||
|
@@ -91,7 +93,7 @@ const expandRelatesTo = (idxResponse, value) => { | |
}); | ||
}; | ||
|
||
const convertRemediationAction = (authClient: OktaAuthIdxInterface, remediation, toPersist) => { | ||
const convertRemediationAction = (authClient: MinimalOktaAuthIdxInterface, remediation, toPersist) => { | ||
// Only remediation that has `rel` field (indicator for form submission) can have http action | ||
if (remediation.rel) { | ||
const remediationActions = generateRemediationFunctions( authClient, [remediation], toPersist ); | ||
|
@@ -105,7 +107,7 @@ const convertRemediationAction = (authClient: OktaAuthIdxInterface, remediation, | |
return remediation; | ||
}; | ||
|
||
export const parseIdxResponse = function parseIdxResponse( authClient: OktaAuthIdxInterface, idxResponse, toPersist = {} ): { | ||
export const parseIdxResponse = function parseIdxResponse( authClient: MinimalOktaAuthIdxInterface, idxResponse, toPersist = {} ): { | ||
remediations: IdxRemediation[]; | ||
context: IdxContext; | ||
actions: IdxActions; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See
setRemediatorsCtx
in utils - https://github.com/okta/okta-auth-js/pull/1476/files#diff-71b56cc120e09a7c5f1d47c7637461aece91f39807b35359697038d48b38ddd3This is needed for minimal IDX API to not import all remediators and flow specifications (except GenericRemediator).
By default
remediatorsCtx
has empty list of remediators