💡 (docs-code) add code documentation
This commit is contained in:
@ -9,9 +9,14 @@ export const githubCallbackService = async (
|
|||||||
userHeaderInfo: UserHeaderInformation
|
userHeaderInfo: UserHeaderInformation
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
|
// Initialize GitHub provider
|
||||||
const github = githubProvider(query.callbackURI);
|
const github = githubProvider(query.callbackURI);
|
||||||
|
|
||||||
|
// Validate the authorization code and get tokens
|
||||||
const tokens = await github.validateAuthorizationCode(query.code);
|
const tokens = await github.validateAuthorizationCode(query.code);
|
||||||
const accessToken = tokens.accessToken();
|
const accessToken = tokens.accessToken();
|
||||||
|
|
||||||
|
// Fetch user data and email from GitHub API
|
||||||
const userdata = await fetch("https://api.github.com/user", {
|
const userdata = await fetch("https://api.github.com/user", {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${accessToken}`,
|
Authorization: `Bearer ${accessToken}`,
|
||||||
@ -23,11 +28,13 @@ export const githubCallbackService = async (
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Parse the user data and email responses into JSON, then combine them into a single payload
|
||||||
const userPayload: GithubCallbackUserData = {
|
const userPayload: GithubCallbackUserData = {
|
||||||
user_data: await userdata.json(),
|
user_data: await userdata.json(),
|
||||||
user_email: await useremail.json(),
|
user_email: await useremail.json(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Provision or authenticate the user in the system
|
||||||
return await OAuthUserProvisionService(
|
return await OAuthUserProvisionService(
|
||||||
{
|
{
|
||||||
provider: "github",
|
provider: "github",
|
||||||
|
|||||||
@ -43,8 +43,10 @@ export const googleCallbackService = async (
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// parse the user data response
|
||||||
const userData = (await response.json()) as GoogleCallbackUserData;
|
const userData = (await response.json()) as GoogleCallbackUserData;
|
||||||
|
|
||||||
|
// Provision or authenticate the user in the system
|
||||||
return await OAuthUserProvisionService(
|
return await OAuthUserProvisionService(
|
||||||
{
|
{
|
||||||
provider: "google",
|
provider: "google",
|
||||||
|
|||||||
Reference in New Issue
Block a user