-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into WRPD-feature-377
- Loading branch information
Showing
10 changed files
with
354 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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,84 @@ | ||
// eslint-disable-next-line unused-imports/no-unused-imports, no-unused-vars | ||
import React, { useEffect } from "react"; | ||
|
||
// eslint-disable-next-line import/no-unresolved | ||
import { NativeFacebookAuthComponent } from "@wrappid/native"; | ||
// eslint-disable-next-line import/no-unresolved | ||
import { WrappidDataContext } from "@wrappid/styles"; | ||
import { useDispatch } from "react-redux"; | ||
|
||
import { HTTP } from "../../../config/constants"; | ||
import { apiRequestAction } from "../../../store/action/appActions"; | ||
import CoreButton from "../CoreButton"; | ||
|
||
const FacebookAuthComponent = (props) => { | ||
const dispatch = useDispatch(); | ||
const { config } = React.useContext(WrappidDataContext); | ||
|
||
useEffect(() => { | ||
// Load the Facebook SDK | ||
window.fbAsyncInit = function () { | ||
window.FB.init({ | ||
appId : config?.wrappid?.socialLogin?.facebook?.appId, | ||
config_id: config?.wrappid?.socialLogin?.facebook?.configId, | ||
cookie : true, | ||
version : "v20.0", | ||
xfbml : true, | ||
|
||
}); | ||
}; | ||
|
||
(function (document, elementType, scriptId) { | ||
let facebookScript, | ||
fjs = document.getElementsByTagName(elementType)[0]; | ||
|
||
if (document.getElementById(scriptId)) return; | ||
facebookScript = document.createElement(elementType); | ||
facebookScript.id = scriptId; | ||
facebookScript.src = "https://connect.facebook.net/en_US/sdk.js"; | ||
fjs.parentNode.insertBefore(facebookScript, fjs); | ||
})(document, "script", "facebook-jssdk"); | ||
}, []); | ||
|
||
const handleFacebookLogin = () => { | ||
window.FB.login( | ||
function (response) { | ||
if (response.authResponse) { | ||
fetchUserData(response.authResponse.accessToken); | ||
} | ||
}, | ||
{ | ||
config_id : config?.wrappid?.socialLogin?.facebook?.configId, | ||
response_type: "code", | ||
scope : "public_profile,email", | ||
} | ||
); | ||
}; | ||
|
||
const fetchUserData = (accessToken) => { | ||
const data = { platformToken: accessToken }; | ||
|
||
dispatch( | ||
apiRequestAction( | ||
HTTP.POST, | ||
"/login/social/facebook", | ||
false, | ||
data, | ||
"LOGIN_SUCCESS", | ||
"LOGIN_ERROR" | ||
) | ||
); | ||
}; | ||
|
||
return ( | ||
<NativeFacebookAuthComponent | ||
onClick={() => handleFacebookLogin()} | ||
label="Facebook" | ||
{...props} | ||
/> | ||
); | ||
}; | ||
|
||
FacebookAuthComponent.ValidProps = [...CoreButton.validProps]; | ||
|
||
export default FacebookAuthComponent; |
This file contains 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,47 @@ | ||
/* eslint-disable etc/no-commented-out-code */ | ||
/* eslint-disable import/no-unresolved */ | ||
import React, { useEffect, useState } from "react"; | ||
|
||
import { apiRequestAction, HTTP } from "@wrappid/core"; | ||
import { NativeGithubAuthComponent } from "@wrappid/native"; | ||
import { WrappidDataContext } from "@wrappid/styles"; | ||
import { useDispatch } from "react-redux"; | ||
|
||
export default function GithubAuthComponent(props) { | ||
const { config } = React.useContext(WrappidDataContext); | ||
const dispatch = useDispatch(); | ||
const [github_code, setGithub_code] = useState(""); | ||
|
||
useEffect(() => { | ||
const currentUrl = window.location.href; | ||
|
||
const state = new URLSearchParams(window.location.search).get("state"); | ||
|
||
if (currentUrl.includes("checkUserExist?code=") && state === null) { | ||
const urlParams = new URLSearchParams(window.location.search); | ||
const extractedCode = urlParams.get("code"); | ||
|
||
setGithub_code(extractedCode); | ||
} | ||
}, []); | ||
|
||
useEffect(() => { | ||
const backend_Endpoint = "/login/social/github"; | ||
|
||
if(github_code === ""){return;} | ||
dispatch( | ||
apiRequestAction(HTTP.POST, backend_Endpoint, false, { "platformToken": github_code }, "LOGIN_SUCCESS", | ||
"LOGIN_ERROR")); | ||
setGithub_code(""); | ||
}, [github_code]); | ||
|
||
const handleAuthoriseGithub = () => { | ||
|
||
const clientId = config.wrappid.socialLogin.github.clientId; | ||
|
||
window.location.href = `https://github.com/login/oauth/authorize?client_id=${clientId}&scope=repo,discussions,read:user,user:email `; | ||
return; | ||
}; | ||
|
||
return (<NativeGithubAuthComponent onClick={handleAuthoriseGithub} {...props} label="Github"/>); | ||
} |
This file contains 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,71 @@ | ||
// eslint-disable-next-line no-unused-vars, unused-imports/no-unused-imports | ||
import React, { useEffect, useRef } from "react"; | ||
|
||
// eslint-disable-next-line import/no-unresolved | ||
import { WrappidDataContext } from "@wrappid/styles"; | ||
import { useDispatch } from "react-redux"; | ||
|
||
import { HTTP } from "../../../config/constants"; | ||
import { apiRequestAction } from "../../../store/action/appActions"; | ||
import CoreBox from "../../layouts/CoreBox"; | ||
|
||
const GoogleAuthComponent = () => { | ||
const { config } = React.useContext(WrappidDataContext); | ||
const dispatch = useDispatch(); | ||
|
||
const buttonRef = useRef(null); | ||
|
||
useEffect(() => { | ||
const script = document.createElement("script"); | ||
|
||
script.src = "https://accounts.google.com/gsi/client"; | ||
script.async = true; | ||
script.defer = true; | ||
script.onload = initializeGoogleSignIn; | ||
document.body.appendChild(script); | ||
|
||
return () => { | ||
document.body.removeChild(script); | ||
}; | ||
}, []); | ||
|
||
const handleCredentialResponse = (response) => { | ||
// You can send this token to your server or handle it as needed | ||
const data = { platformToken: response.credential }; | ||
|
||
dispatch( | ||
apiRequestAction( | ||
HTTP.POST, | ||
"/login/social/google", | ||
false, | ||
data, | ||
"LOGIN_SUCCESS", | ||
"LOGIN_ERROR" | ||
) | ||
); | ||
}; | ||
|
||
const initializeGoogleSignIn = () => { | ||
if (window.google) { | ||
window.google.accounts.id.initialize({ | ||
|
||
auto_select: true, | ||
// Replace with your actual client ID | ||
callback : handleCredentialResponse, | ||
client_id : config.wrappid.socialLogin.google.clientId | ||
}); | ||
|
||
window.google.accounts.id.renderButton( | ||
buttonRef.current, | ||
{ size: "large", theme: "outline" } // customization attributes | ||
); | ||
window.google.accounts.id.prompt(); // also display the One Tap dialog | ||
} | ||
}; | ||
|
||
return ( | ||
<CoreBox ref={buttonRef}></CoreBox> | ||
); | ||
}; | ||
|
||
export default GoogleAuthComponent; |
This file contains 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 @@ | ||
/* eslint-disable no-console */ | ||
// eslint-disable-next-line unused-imports/no-unused-imports, no-unused-vars | ||
import React, { useState, useEffect } from "react"; | ||
|
||
// eslint-disable-next-line import/no-unresolved | ||
import { NativeLinkedInAuthComponent } from "@wrappid/native"; | ||
// eslint-disable-next-line import/no-unresolved | ||
import { WrappidDataContext } from "@wrappid/styles"; | ||
import { useDispatch } from "react-redux"; | ||
|
||
import CoreButton from "./../CoreButton"; | ||
import { HTTP } from "../../../config/constants"; | ||
import { apiRequestAction } from "../../../store/action/appActions"; | ||
import CoreBox from "../../layouts/CoreBox"; | ||
|
||
export default function LinkedInAuthComponent(props){ | ||
const { config } = React.useContext(WrappidDataContext); | ||
const dispatch = useDispatch(); | ||
|
||
const clientId = config?.wrappid?.socialLogin?.linkedin?.apiKey; | ||
const redirectUri = config?.wrappid?.socialLogin?.linkedin?.callbackURL; | ||
const scopes = "profile w_member_social email openid"; | ||
const state = "4b1a92d8c1e7a9"; | ||
|
||
const authUrl = `https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=${clientId}&redirect_uri=${encodeURIComponent( | ||
redirectUri | ||
)}&state=${state}&scope=${encodeURIComponent(scopes)}`; | ||
|
||
const handleClick = () => { | ||
// Redirect user to LinkedIn auth URL | ||
console.log(authUrl); | ||
window.location.href = authUrl; | ||
}; | ||
const fetchUserData = (authCode) => { | ||
const data = { platformToken: authCode }; | ||
|
||
dispatch( | ||
apiRequestAction( | ||
HTTP.POST, | ||
"/login/social/linkedin", | ||
false, | ||
data, | ||
"LOGIN_SUCCESS", | ||
"LOGIN_ERROR" | ||
) | ||
); | ||
}; | ||
const [authCode, setAuthCode] = useState(null); | ||
|
||
useEffect(() => { | ||
// Extract the authorization code from the URL | ||
const queryParams = new URLSearchParams(window.location.search); | ||
const state = new URLSearchParams(window.location.search).get("state"); | ||
|
||
const code = queryParams.get("code"); | ||
|
||
if ((code != null) && (state != null)) { | ||
setAuthCode(code); | ||
} | ||
|
||
if(authCode !== null){ | ||
// eslint-disable-next-line no-unused-vars | ||
fetchUserData(authCode); | ||
} | ||
}, [authCode]); | ||
|
||
return ( | ||
<CoreBox> | ||
<NativeLinkedInAuthComponent onClick={handleClick} {...props} label="LinkedIn"/> | ||
</CoreBox> | ||
); | ||
} | ||
|
||
LinkedInAuthComponent.validProps = [...CoreButton.validProps]; |
This file contains 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
Oops, something went wrong.