-
Notifications
You must be signed in to change notification settings - Fork 36
feat(core): add logout, getBrandingCSS & refactor branding, profile files #9
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
Changes from all commits
c6503aa
353b2ef
00ddb20
1f4b061
ee1212b
ade9935
a5742cc
6a0c425
9e71074
287bf73
42b2d42
97b0093
ea330fd
0792b1f
395e7ef
48dc84f
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,82 @@ | ||
/** | ||
* Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). | ||
* | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with 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 {AuthClient, ResponseMode} from '../auth-client'; | ||
import AsgardeoUIException from '../exception'; | ||
|
||
/** | ||
* Sign out the user. | ||
* | ||
* This function sends a signout request to the server. | ||
* | ||
* @returns {Promise<void>} A promise that resolves when the sign out process is complete. | ||
* | ||
* @example | ||
* signOut() | ||
* .then(() => { | ||
* console.log('Signed out!'); | ||
* }) | ||
* .catch((error) => { | ||
* console.error('Failed to sign out:', error); | ||
* }); | ||
*/ | ||
const signOut = async (): Promise<void> => { | ||
let response: Response; | ||
let signOutUrl: string; | ||
|
||
const headers: Headers = new Headers(); | ||
headers.append('Accept', 'application/json'); | ||
headers.append('Content-Type', 'application/x-www-form-urlencoded'); | ||
|
||
const formBody: URLSearchParams = new URLSearchParams(); | ||
|
||
try { | ||
formBody.append('id_token_hint', await AuthClient.getInstance().getIDToken()); | ||
formBody.append('client_id', (await AuthClient.getInstance().getDataLayer().getConfigData()).clientID); | ||
formBody.append('response_mode', ResponseMode.direct); | ||
} catch (error) { | ||
throw new AsgardeoUIException('JS_UI_CORE-SIGNOUT-SO-IV', 'Failed to build the body of the signout request.'); | ||
} | ||
|
||
const requestOptions: RequestInit = { | ||
body: formBody.toString(), | ||
headers, | ||
method: 'POST', | ||
}; | ||
|
||
try { | ||
signOutUrl = (await AuthClient.getInstance().getOIDCServiceEndpoints()).endSessionEndpoint; | ||
} catch (error) { | ||
throw new AsgardeoUIException('JS_UI_CORE-SIGNOUT-SO-NF', 'Failed to retrieve the sign out endpoint.'); | ||
} | ||
|
||
try { | ||
response = await fetch(signOutUrl, requestOptions); | ||
} catch (error) { | ||
throw new AsgardeoUIException('JS_UI_CORE-SIGNOUT-SO-NE', 'Failed to send a request to the sign out endpoint.'); | ||
} | ||
|
||
if (!response.ok) { | ||
throw new AsgardeoUIException( | ||
'JS_UI_CORE-SIGNOUT-SO-HE', | ||
'Failed to receive a successful response from the sign out endpoint.', | ||
); | ||
} | ||
}; | ||
|
||
export default signOut; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/** | ||
* Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). | ||
* | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with 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 {BrandingPreferenceThemeInterface, ThemeConfigInterface} from '../models/branding-api-response'; | ||
import isEmpty from 'lodash.isempty'; | ||
|
||
const getBrandingCSS = (theme: BrandingPreferenceThemeInterface): string => { | ||
if (!theme) { | ||
return ''; | ||
} | ||
const activeTheme: ThemeConfigInterface = theme[theme.activeTheme]; | ||
|
||
const footerFontColor: string = !isEmpty(activeTheme.footer.font.color) ? activeTheme.footer.font.color : 'inherit'; | ||
const headingFontColor: string = !isEmpty(activeTheme.typography.heading.font.color) | ||
? activeTheme.typography.heading.font.color | ||
: 'inherit'; | ||
const loginBoxFontColor: string = !isEmpty(activeTheme.loginBox.font.color) | ||
? activeTheme.loginBox.font.color | ||
: 'inherit'; | ||
const inputBaseFontColor: string = !isEmpty(activeTheme.inputs.base.font.color) | ||
? activeTheme.inputs.base.font.color | ||
: 'inherit'; | ||
const inputBaseLabelFontColor: string = !isEmpty(activeTheme.inputs.base.labels.font.color) | ||
? activeTheme.inputs.base.labels.font.color | ||
: 'inherit'; | ||
|
||
return ` | ||
${activeTheme.typography.font.importURL ? `@import url(${activeTheme.typography.font.importURL});` : ''} | ||
|
||
:root { | ||
--asg-colors-primary-main: ${activeTheme.colors.primary.main}; | ||
--asg-colors-secondary-main: ${activeTheme.colors.secondary.main}; | ||
--asg-colors-background-body-main: ${activeTheme.colors.background?.body?.main}; | ||
--asg-colors-background-surface-main: ${activeTheme.colors.background?.surface?.main}; | ||
--asg-colors-background-surface-light: ${activeTheme.colors.background?.surface?.light}; | ||
--asg-colors-background-surface-dark: ${activeTheme.colors.background?.surface?.dark}; | ||
--asg-colors-background-surface-inverted: ${activeTheme.colors.background?.surface?.inverted}; | ||
--asg-colors-outlined-default: ${activeTheme.colors.outlined?.default}; | ||
--asg-colors-text-primary: ${activeTheme.colors.text?.primary}; | ||
--asg-colors-text-secondary: ${activeTheme.colors.text?.secondary}; | ||
--asg-colors-alerts-error-main: ${activeTheme.colors.alerts?.error?.main}; | ||
--asg-colors-alerts-neutral-main: ${activeTheme.colors.alerts?.neutral?.main}; | ||
--asg-colors-alerts-info-main: ${activeTheme.colors.alerts?.info?.main}; | ||
--asg-colors-alerts-warning-main: ${activeTheme.colors.alerts?.warning?.main}; | ||
--asg-colors-illustrations-primary-main: ${activeTheme.colors.illustrations?.primary?.main}; | ||
--asg-colors-illustrations-secondary-main: ${activeTheme.colors.illustrations?.secondary?.main}; | ||
--asg-colors-illustrations-accent1-main: ${activeTheme.colors.illustrations?.accent1?.main}; | ||
--asg-colors-illustrations-accent2-main: ${activeTheme.colors.illustrations?.accent2?.main}; | ||
--asg-colors-illustrations-accent3-main: ${activeTheme.colors.illustrations?.accent3?.main}; | ||
|
||
/* Components */ | ||
--asg-footer-text-color: ${footerFontColor}; | ||
--asg-footer-border-color: ${activeTheme.footer?.border?.borderColor || 'var(--asg-colors-outlined-default)'}; | ||
--asg-primary-font-family: ${activeTheme.typography.font.fontFamily}; | ||
--asg-heading-text-color: ${headingFontColor}; | ||
--asg-primary-button-base-text-color: ${activeTheme.buttons.primary.base.font.color}; | ||
--asg-primary-button-base-border-radius: ${activeTheme.buttons.primary.base.border.borderRadius}; | ||
--asg-secondary-button-base-text-color: ${activeTheme.buttons.secondary.base.font.color}; | ||
--asg-secondary-button-base-border-radius: ${activeTheme.buttons.secondary.base.border.borderRadius}; | ||
--asg-external-login-button-base-background-color: ${ | ||
activeTheme.buttons.externalConnection.base.background.backgroundColor | ||
}; | ||
--asg-external-login-button-base-text-color: ${activeTheme.buttons.externalConnection.base.font.color}; | ||
--asg-external-login-button-base-border-radius: ${activeTheme.buttons.externalConnection.base.border.borderRadius}; | ||
--asg-login-box-background-color: ${ | ||
activeTheme.loginBox?.background?.backgroundColor || 'var(--asg-colors-background-surface-main)' | ||
}; | ||
--asg-login-box-border-color: ${activeTheme.loginBox?.border?.borderColor || 'var(--asg-colors-outlined-default)'}; | ||
--asg-login-box-border-width: ${activeTheme.loginBox.border.borderWidth}; | ||
--asg-login-box-border-style: solid; | ||
--asg-login-box-border-radius: ${activeTheme.loginBox.border.borderRadius}; | ||
--asg-login-box-text-color: ${loginBoxFontColor}; | ||
--asg-login-page-background-color: ${ | ||
activeTheme.loginPage?.background?.backgroundColor || 'var(--asg-colors-background-body-main)' | ||
}; | ||
--asg-login-page-font-color: ${activeTheme.loginPage?.font?.color || 'var(--asg-colors-text-primary)'}; | ||
--asg-input-field-base-text-color: ${inputBaseFontColor || 'var(--asg-colors-text-primary)'}; | ||
--asg-input-field-base-background-color: ${activeTheme.inputs.base.background.backgroundColor}; | ||
--asg-input-field-base-label-text-color: ${inputBaseLabelFontColor}; | ||
--asg-input-field-base-border-color: ${ | ||
activeTheme.inputs.base.border.borderColor || 'var(--asg-colors-outlined-default)' | ||
}; | ||
--asg-input-field-base-border-radius: ${activeTheme.inputs.base.border.borderRadius}; | ||
--language-selector-background-color: var(--asg-login-page-background-color) !important; | ||
--language-selector-text-color: var(--asg-footer-text-color) !important; | ||
--language-selector-border-color: var(--asg-colors-primary-main) !important; | ||
|
||
/* Oxygen UI variables */ | ||
--oxygen-palette-text-primary: ${activeTheme.colors.text?.primary}; | ||
} `; | ||
}; | ||
|
||
export default getBrandingCSS; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). | ||
* | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with 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. | ||
*/ | ||
|
||
export {default as getBranding} from './get-branding'; | ||
export {default as getBrandingCSS} from './get-branding-css'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
*/ | ||
|
||
export * from './api/public-api'; | ||
export {default as getBranding} from './branding/branding'; | ||
export * from './branding/public'; | ||
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. do we need to use index files? 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. It's not strictly necessary to use an |
||
export * from './i18n/public'; | ||
export * from './auth-client'; | ||
export * from './models/public-models'; | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.