-
Notifications
You must be signed in to change notification settings - Fork 36
feat(core): add me & expose functions and models #4
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d2c16aa
feat(core): :sparkles: add me function
movinsilva 14a5d9a
refactor(core):
movinsilva a387166
feat(core): :sparkles: add public api
movinsilva c3333d1
feat(core): :sparkles: export required functions from js-ui-core
movinsilva 7f7d88a
feat(core): :sparkles: export required models from js-ui-core
movinsilva b8aef0d
docs(core): :memo: update internal headers
movinsilva b9bbc59
refactor(core): :recycle: update exports and paths in branding
movinsilva 8fcc99c
fix(core): :bug: update import style
movinsilva d453b07
style(core): :art: improve formatting of me function
movinsilva 53b413a
refactor(core): :recycle: rename me function and the file
movinsilva b7bfa97
docs(core): :memo: add js docs for getProfileInformation function
movinsilva 43e3cf4
refactor(core): :recycle: update error codes in getProfileInformation
movinsilva File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* 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} from 'src/auth-client'; | ||
import AsgardeoUIException from 'src/exception'; | ||
import {MeAPIResponse} from 'src/models/me-api-response'; | ||
|
||
/** | ||
* Fetch the profile information of the authenticated user. | ||
* | ||
* This function uses the `AuthClient` instance to get the base URL and access token, | ||
* and then makes a GET request to the `/scim2/Me` endpoint to fetch the user's profile information. | ||
* | ||
* @returns {Promise<MeAPIResponse>} A promise that resolves to an object containing the user's profile information. | ||
* @throws {AsgardeoUIException} Throws an exception if there's an error getting the base URL and access token, or if the fetch request fails. | ||
*/ | ||
const getProfileInformation = async (): Promise<MeAPIResponse> => { | ||
let baseUrl: string; | ||
let accessToken: string; | ||
let response: Response; | ||
|
||
try { | ||
baseUrl = (await AuthClient.getInstance().getDataLayer().getConfigData()).baseUrl; | ||
accessToken = await AuthClient.getInstance().getAccessToken(); | ||
} catch (error) { | ||
throw new AsgardeoUIException( | ||
'JS_UI_CORE-ME-GPI-NF', | ||
'Failed in getting the base URL and access token.', | ||
error.stack, | ||
); | ||
} | ||
|
||
if (!accessToken) { | ||
throw new AsgardeoUIException('JS_UI_CORE-ME-GPI-IV', 'Access token is null.'); | ||
} | ||
|
||
const headers: Headers = new Headers(); | ||
headers.append('Authorization', `Bearer ${accessToken}`); | ||
headers.append('Content-Type', 'application/json'); | ||
|
||
const requestOptions: RequestInit = { | ||
headers, | ||
method: 'GET', | ||
}; | ||
|
||
try { | ||
response = await fetch(new Request(`${baseUrl}/scim2/Me`, requestOptions)); | ||
} catch (error) { | ||
throw new AsgardeoUIException('JS_UI_CORE-ME-GPI-NE', 'Me API call failed.', error.stack); | ||
} | ||
|
||
if (response.ok) { | ||
return (await response.json()) as MeAPIResponse; | ||
} | ||
|
||
throw new AsgardeoUIException('JS_UI_CORE-ME-GPI-HE', 'Failed to receive a successful response from the Me API.'); | ||
}; | ||
|
||
export default getProfileInformation; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* 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 authorize} from './authorize'; | ||
export {default as authenticate} from './authenticate'; | ||
export {default as getBrandingPreference} from './branding-preference'; | ||
export {default as getProfileInformation} from './profile'; | ||
export {default as getBrandingPreferenceText} from './branding-preference-text'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* 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 * from './api/public-api'; | ||
export {default as getBranding} from './branding/branding'; | ||
export * from './i18n/public'; | ||
export * from './auth-client'; | ||
export * from './models/public-models'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* The interface for the response from the "me" API endpoint. | ||
*/ | ||
export interface MeAPIResponse { | ||
/** | ||
* The user's email addresses. | ||
*/ | ||
emails: string[]; | ||
/** | ||
* The user's id. | ||
*/ | ||
id: string; | ||
/** | ||
* The user's names. | ||
*/ | ||
name: Name; | ||
/** | ||
* When signed in using a social login, the photos field will be populated instead of profile URL. | ||
*/ | ||
photos?: Photos[]; | ||
/** | ||
* The user's profile URL. | ||
*/ | ||
profileUrl: string; | ||
/** | ||
* The user's username. | ||
*/ | ||
userName: string; | ||
} | ||
|
||
/** | ||
* The interface for the name field in the "me" API response. | ||
*/ | ||
export interface Name { | ||
familyName?: string; | ||
givenName?: string; | ||
} | ||
|
||
/** | ||
* The interface for the photos field in the "me" API response. | ||
*/ | ||
export interface Photos { | ||
type: string; | ||
value: string; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* 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 * from './auth-api-request'; | ||
export * from './auth-api-response'; | ||
export * from './auth-config'; | ||
export * from './branding-api-response'; | ||
export * from './customization'; | ||
export * from './me-api-response'; | ||
export * from './screen-type'; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.