diff --git a/src/auth/utils.js b/src/auth/utils.js index 9dcdf91..62e8260 100644 --- a/src/auth/utils.js +++ b/src/auth/utils.js @@ -10,42 +10,58 @@ export const hostname = 'localhost'; const hostPort = '8090'; export const hostPath = `http://${hostname}:${hostPort}`; //export const apiPath = `http://192.168.0.112:8090/api`; -<<<<<<< HEAD -//export const apiPath = `${hostPath}/api`; - export const apiPath = `/api`; -======= + export const apiPath = `${hostPath}/api`; //export const apiPath = `/api`; ->>>>>>> master + export const paymentPath = `http://pnspsdev.gld.gov.hk/payment`; export const iAmSmartPath = `https://apigw-isit.staging-eid.gov.hk`; export const clientId = "cf61fa7c121e4869966f69c8694b1cd2"; -export const getBowerType=()=>{ + +export const iAmSmartCallbackPath = () => { + let hostname = window.location.hostname; + if (hostname.match("localhost")) { + hostname = "pnspsuat.gld.gov.hk"; + } + return hostname; +}; + +export const getNonce = () => { + let hostname = window.location.hostname; + if (hostname.match("localhost")) { + hostname = "pnspsuat.gld.gov.hk"; + } + return hostname; +}; + + + +export const getBowerType = () => { console.log(navigator.userAgent) // const regex = /Mobi|Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Mi|huawei|Opera Mini|SAMSUNG|Samsung|SGH-[I|N|T]|GT-[I|N]|SM-[A|N|P|T|Z]|SHV-E|SCH-[I|J|R|S]|SPH-L/i; // if(!regex.test(navigator.userAgent)) if (navigator.userAgent.indexOf("Edg") != -1) { - if(navigator.userAgent.match(/Android/i)) return "Android_Edge" - if(navigator.userAgent.match(/iPhone|iPad|iPod/i)) return "iOS_Edge" + if (navigator.userAgent.match(/Android/i)) return "Android_Edge" + if (navigator.userAgent.match(/iPhone|iPad|iPod/i)) return "iOS_Edge" return "PC_Browser" - }else if(navigator.userAgent.indexOf("Chrome") != -1){ - if(navigator.userAgent.match(/Android/i)) return "Android_Chrome" - if(navigator.userAgent.match(/iPhone|iPad|iPod/i)) return "iOS_Chrome" + } else if (navigator.userAgent.indexOf("Chrome") != -1) { + if (navigator.userAgent.match(/Android/i)) return "Android_Chrome" + if (navigator.userAgent.match(/iPhone|iPad|iPod/i)) return "iOS_Chrome" return "PC_Browser" - }else if(navigator.userAgent.indexOf("Safari") != -1){ - if(navigator.userAgent.match(/iPhone|iPad|iPod/i)) return "iOS_Safari" + } else if (navigator.userAgent.indexOf("Safari") != -1) { + if (navigator.userAgent.match(/iPhone|iPad|iPod/i)) return "iOS_Safari" return "PC_Browser" - }else if(navigator.userAgent.indexOf("Firefox") != -1){ - if(navigator.userAgent.match(/Android/i)) return "Android_Firefox" - if(navigator.userAgent.match(/iPhone|iPad|iPod/i)) return "iOS_Firefox" + } else if (navigator.userAgent.indexOf("Firefox") != -1) { + if (navigator.userAgent.match(/Android/i)) return "Android_Firefox" + if (navigator.userAgent.match(/iPhone|iPad|iPod/i)) return "iOS_Firefox" return "PC_Browser" - }else if(navigator.userAgent.match(/SAMSUNG|Samsung|SGH-[I|N|T]|GT-[I|N]|SM-[A|N|P|T|Z]|SHV-E|SCH-[I|J|R|S]|SPH-L/i)){ + } else if (navigator.userAgent.match(/SAMSUNG|Samsung|SGH-[I|N|T]|GT-[I|N]|SM-[A|N|P|T|Z]|SHV-E|SCH-[I|J|R|S]|SPH-L/i)) { return "Android_Samsung" - }else if(navigator.userAgent.match(/huawei/i)){ + } else if (navigator.userAgent.match(/huawei/i)) { return "Android_Huawei" - }else if(navigator.userAgent.match(/Mi/i)){ + } else if (navigator.userAgent.match(/Mi/i)) { return "Android_Xiaomi" } return "PC_Browser"; diff --git a/src/pages/authentication/RegisterCustom.js b/src/pages/authentication/RegisterCustom.js index 33f1558..2ed113a 100644 --- a/src/pages/authentication/RegisterCustom.js +++ b/src/pages/authentication/RegisterCustom.js @@ -9,7 +9,7 @@ import Typography from '@mui/material/Typography'; import iAmSmartICon from 'assets/images/icons/icon_iAmSmart.png'; import banner from 'assets/images/bg_ml.jpg'; import { Stack } from '../../../node_modules/@mui/material/index'; -import { iAmSmartPath, clientId, getBowerType } from 'auth/utils' +import { iAmSmartPath, clientId, getBowerType , iAmSmartCallbackPath} from 'auth/utils' import * as React from 'react'; @@ -25,13 +25,13 @@ const RegisterCustom = () => { } const getQRWithIAmSmart = () => { - let callbackUrl = "https://"+window.location.hostname+"/iamsmart/logincallback"; + let callbackUrl = "https://"+iAmSmartCallbackPath()+"/iamsmart/authcallback"; let url = iAmSmartPath + "/api/v1/auth/getQR" + "?clientID=" + clientId + "&responseType=code" +"&source=" + getBowerType() +"&redirectURI="+encodeURIComponent(callbackUrl) - +"&scope=eidapi_formFilling" + +"&scope="+encodeURIComponent("eidapi_auth eidapi_profiles") +"&lang=zh-HK"//en-US, zh-HK, or zh-CN //+"&state=" +"&brokerPage=false" diff --git a/src/pages/iAmSmart/AuthCallback/index.js b/src/pages/iAmSmart/AuthCallback/index.js index 404fe2c..b626731 100644 --- a/src/pages/iAmSmart/AuthCallback/index.js +++ b/src/pages/iAmSmart/AuthCallback/index.js @@ -10,6 +10,8 @@ import { import * as React from "react"; import { useFormik, FormikProvider } from 'formik'; import * as yup from 'yup'; +import { useParams } from "react-router-dom"; +//import { iAmSmartPath, clientId, getBowerType , iAmSmartCallbackPath} from 'auth/utils' import Loadable from 'components/Loadable'; const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent'))); @@ -29,15 +31,22 @@ const BackgroundHead = { const Index = () => { + const params = useParams(); const [onReady, setOnReady] = React.useState(false); const [checkUsername, setCheckUsername] = React.useState(false); const [props, setProps] = React.useState({}); React.useEffect(() => { - setOnReady(true); - setProps({}); + if(params.code){ + setOnReady(true); + setProps({}); + } }, []); + // function loadIAmSmartProfile(){ + + // } + function displayErrorMsg(errorMsg) { return {errorMsg} } diff --git a/src/routes/LoginRoutes.js b/src/routes/LoginRoutes.js index 3fc8167..d0adeb1 100644 --- a/src/routes/LoginRoutes.js +++ b/src/routes/LoginRoutes.js @@ -54,7 +54,7 @@ const LoginRoutes = { element: }, { - path: 'iamsmart/loginfailback', + path: 'iamsmart/loginfallback', element: }, {