-
Notifications
You must be signed in to change notification settings - Fork 132
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
initial implementation of DA #2300
Conversation
|
Size Change: +14.3 kB (+1%) Total Size: 1.08 MB
ℹ️ View Unchanged
|
SonarCloud Quality Gate failed. 0 Bugs 2.9% Coverage Catch issues before they fail your Quality Gate with our IDE extension SonarLint |
|
||
this.props.onComplete(data); // (equals onAdditionalDetails - except for 3DS2InMDFlow) | ||
if (this.state.challengeData.delegatedAuthenticationSDKInput && resultObj.transStatus === 'Y') { | ||
this.setState({ status: 'delegatedAuthenticationEnrollment' }); |
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.
Since there are a few different status' it would be cleaner to create an enum rather than relying on strings.
@@ -207,3 +237,11 @@ export const get3DS2FlowProps = (actionSubtype, props) => { | |||
i18n: props.i18n | |||
}; | |||
}; | |||
|
|||
export const isInIframe = () => { | |||
try { |
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.
There is no need for a try/catch here, just need to check window is defined and then return the boolean expression.
const [supported, setSupported] = useState<boolean>(); | ||
const [spcSupported, setSpcSupported] = useState<boolean>(); | ||
|
||
const inIframe = useMemo(() => { |
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.
This function doesn't need to memoized, it's not doing a heavy calculation just returning a boolean.
authorisationToken, | ||
onComplete | ||
}: DelegatedAuthenticationEnrollmentProps) => { | ||
const [status, setStatus] = useState<string>('loading'); |
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.
Here also I would use an enum for status rather than strings.
transStatus: string, | ||
authorisationToken: string, | ||
delegatedAuthenticationSDKOutput?: string | ||
): any => ({ |
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.
This should also have a return type rather than any.
@@ -0,0 +1,8 @@ | |||
export const decodeBase64 = (value: string) => { |
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.
Why are these in a different utils file when there already is a utils file?
const complete = (sdkOutput: string) => { | ||
setStatus('loading'); | ||
const resolveDataFunction = useOriginalFlow ? createOldChallengeResolveData : createChallengeResolveData; | ||
const data = resolveDataFunction(dataKey, 'Y', authorisationToken, sdkOutput); |
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.
It's not good practice to pass strings like this, better to extract it to a constant and name it.
complete(sdkOutput); | ||
}; | ||
|
||
useEffect(() => { |
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.
This could be a extracted into a hook
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.
Or the async function could be a util, that way it's testable
} | ||
|
||
try { | ||
return await mockPaymentRequest().canMakePayment(); |
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.
Does this mean everytime a user does DA a mock payment request is made first to determine if the payment can be made?
} | ||
}; | ||
|
||
const mockPaymentRequest = () => { |
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.
This should be a util then it's independently testable.
document.cookie = `${credentialId}=; path=/; expires=${expiryDate.toUTCString()};`; | ||
}; | ||
|
||
const createPaymentCredential = async (registrationData: DelegatedAuthenticationEnrollmentInputData): Promise<PublicKeyCredential> => { |
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.
This could be a util, then it is independently testable.
// todo: this should be a part of the token data | ||
const useCookiesInSpc = true; | ||
|
||
const shouldDoSpc = useMemo(() => { |
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.
useMemo is not required here, it should only be used when doing calculation type stuff otherwise it can negatively impact performance when used unnecessarily.
} else { | ||
complete({ errorCode: DelegatedAuthenticationError.NoInputDataPresent }); | ||
} | ||
}, []); |
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.
This useEffect depends on token
so it should have token
in it's dependency array.
}, [authenticationData]); | ||
|
||
useEffect(() => { | ||
if (!authenticationData) { |
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.
This useEffect depends on hasCookieForCrediential but doesn't call it anywhere? Should the if perhaps be (!authenticationData && hasCookieForCredential) otherwise every time hasCookieForCrediential gets updated this will run regardless of it's value.
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.
Although actually I see hasCookieForCredential is a function so is this a mistake?
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.
Review still in progress but added some comments.
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.
There is a lot of logic in the components that could be extracted to utils or hooks. This will make the code easier to test and keep the components clean.
complete({ errorCode: DelegatedAuthenticationError.Canceled, deleteCredential: true }); | ||
}; | ||
|
||
const getAmountValue = (amount: PaymentAmount, currencyExponent: number): string => { |
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.
This function and the one below should be a util so it can independently tested
|
||
useEffect(() => { | ||
if (token) { | ||
try { |
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.
Why are you using a try/catch here?
SonarCloud Quality Gate failed. 0 Bugs 3.4% Coverage Catch issues before they fail your Quality Gate with our IDE extension SonarLint |
Summary
initial implementation of delegated authentication:
DelegatedAuthenticationEnrollment.tsx
component)delegatedAuthentication
action typedelegatedAuthentication
action type (viaDelegatedAuthentication.tsx
component)/v1/submitDelegatedAuthenticationResult
) and handle followup action