Skip to content

Conversation

movinsilva
Copy link
Contributor

Purpose

  • Add components
    • SignIn
      • BasicAuth
      • EmailOTP
      • TOTP
      • SMSOTP
      • SocialLogins
    • SignInButton
    • SignedIn
    • SignedOut
    • SignOutButton
  • Initialized sample react-vite application
  • Add localization for new signin fragments

Related Issues

Related PRs

  • N/A

Checklist

  • e2e cypress tests locally verified.
  • Manual test round performed and verified.
  • UX/UI review done on the final implementation.
  • Documentation provided. (Add links if there are any)
  • Unit tests provided. (Add links if there are any)
  • Integration tests provided. (Add links if there are any)

Security checks

movinsilva added 30 commits May 15, 2024 04:51
take the complete authenticator object as a parameter
if ((await AuthClient.getInstance().getDataLayer().getConfigData()).enableConsoleBranding ?? true) {
brandingFromConsole = await getBrandingPreference();
try {
if ((await AuthClient.getInstance().getDataLayer().getConfigData()).enableConsoleBranding ?? true) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's move this to a variable for better readability

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do this in the next PR

brandingFromConsole = await getBrandingPreference();
try {
if ((await AuthClient.getInstance().getDataLayer().getConfigData()).enableConsoleBranding ?? true) {
brandingFromConsole = await getBrandingPreference();
Copy link
Contributor

Choose a reason for hiding this comment

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

brandingFromConsole is this term correct? We are not getting branding from the console rather from the IS/Asgardeo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree. Since we don't have a unified name yet, there was a discussion sometime back to use more common words without siding with either of them. Any suggestions for a better name?


const configData: AuthClientConfig<UIAuthConfig> = await AuthClient.getInstance().getDataLayer().getConfigData();

const DEFAULT_NAME: string = 'carbon.super';
Copy link
Contributor

Choose a reason for hiding this comment

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

Shall we move this to a default value of the AuthConfig itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will address this in the coming PR.
Is the actual default value carbon.super?

authenticate,
authorize,
getBranding,
keys,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
keys,
keys
``
It looks like linter is not working properly. Check and see. It should catch these formatting errors

Comment on lines +92 to +101
authorize()
.then((response: AuthApiResponse) => {
setAuthResponse(response);
setIsComponentLoading(false);
})
.catch((error: Error) => {
setAlert({alertType: {error: true}, key: keys.common.error});
setIsComponentLoading(false);
throw new AsgardeoUIException('REACT_UI-SIGN_IN-SI-SE01', 'Authorization failed', error.stack);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to call this inside this hook? This will cause the authorize call to fire when the dependency array changes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I will move this out.

Comment on lines +85 to +87
getBranding({branding: brandingProps, merged: brandingPreference}).then((response: Branding) => {
setComponentBranding(response);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

We might be able to convert this to a hook like useBranding()

setAlert(undefined);

if (authResponse === undefined) {
throw new AsgardeoUIException('REACT_UI-SIGN_IN-HA-IV02', 'Auth response is undefined.');
Copy link
Contributor

Choose a reason for hiding this comment

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

I hope you have documented these error codes and their meaning somewhere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm following the same format in Asgardeo Auth-JS. This is the format.
will add this to the docs and readme later.

const {code, state} = event.data;

if (code && state) {
handleAuthenticate(resp.nextStep.authenticators[0].authenticatorId, {code, state});
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
handleAuthenticate(resp.nextStep.authenticators[0].authenticatorId, {code, state});
handleAuthenticate(resp?.nextStep?.authenticators[0]?.authenticatorId, {code, state});

Add null checks. Check in other places as well

return (
<UISignIn.Paper className="multiple-options-paper">
<UISignIn.Typography title className="multiple-otions-title">
Sign In
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we access this from text customization

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is kind of a special scenario where multiple authenticators are there without username & password. So this text doesn't belong to a specific authenticator screen. Could add this to the common set of texts. But doesn't seem much logical to add it there as well. WDYT?

{authResponse?.flowStatus !== FlowStatus.SuccessCompleted && !isAuthenticated && (
<>
{renderSignIn()}

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wouldn't these spacing be better for readability?

</UISignIn.Link>
),
},
{children: <UISignIn.Typography>{componentBranding?.locale ?? 'en-US'}</UISignIn.Typography>},
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's keep the fallback locale in a constant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will address this in the next PR.

showSelfSignUp,
renderLoginOptions,
}: BasicAuthProps): JSX.Element => {
const [username, setUsername] = useState('');
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const [username, setUsername] = useState('');
const [username, setUsername] = useState<string>('');

Define types for states. Check in other places as well

Comment on lines +56 to +62
if (isLoading) {
return (
<div className="circular-progress-holder">
<CircularProgress className="circular-progress" />
</div>
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (isLoading) {
return (
<div className="circular-progress-holder">
<CircularProgress className="circular-progress" />
</div>
);
}
if (isLoading) => (
<div className="circular-progress-holder">
<CircularProgress className="circular-progress" />
</div>
);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think that if statements support arrow functions like this.

window.location.reload();
signOutApiCall().then(() => {
sessionStorage.clear();
window.location.reload();
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this logic and expose an onSignOut hooks so the app user can handle it themselves

Comment on lines +26 to +29
alertType:
| {error?: boolean; info?: never; warning?: never}
| {error?: never; info?: boolean; warning?: never}
| {error?: never; infor?: never; warning?: boolean};
Copy link
Contributor

Choose a reason for hiding this comment

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

Why can't we use an enum here?

Comment on lines +27 to +30
dangerouslySetInnerHTML={{
__html: JSON.stringify(user, null, 2).replace(
/\n/g,
"<br />"
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid using dangerouslySetInnerHTML as this could lead to XSS attacks

Comment on lines +5 to +18
const config: UIAuthConfig = {
baseUrl: "https://localhost:9443",
clientID: "b1uRjwpqydvxjGR42Y6BnIdQMRMa",
scope: ["openid", "internal_login", "profile"],
signInRedirectURL: "https://localhost:5173",
enableConsoleTextBranding: true,
};

const devConfig: UIAuthConfig = {
baseUrl: "https://dev.api.asgardeo.io/t/movinorg",
clientID: "kH5OfXOvpGLOvp1iAw4zQmNvv4oa",
scope: ["openid", "internal_login", "profile"],
signInRedirectURL: "https://localhost:5173",
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't hardcode this within the code. Let's read from a config.json file or a .env file

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this?

@DonOmalVindula DonOmalVindula merged commit d951d7c into asgardeo:main May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants