add france connect authorize

This commit is contained in:
OxSaitama 2023-05-09 17:39:25 +02:00
parent 85728353a0
commit 04f366611d
8 changed files with 43 additions and 17 deletions

View File

@ -18,6 +18,7 @@
"@types/react-dom": "18.0.11",
"class-validator": "^0.14.0",
"classnames": "^2.3.2",
"crypto-random-string": "^5.0.0",
"dotenv": "^16.0.3",
"eslint": "8.36.0",
"eslint-config-next": "13.2.4",

View File

@ -58,6 +58,11 @@ export default class Files extends BaseSuperAdmin {
}
}
public getUploadLink(uid: string): string {
return this.baseURl.concat(`/upload/${uid}`);
}
public async getByUid(uid: string, q?: any): Promise<File> {
const url = new URL(this.baseURl.concat(`/${uid}`));
const query = { q };

View File

@ -20,6 +20,7 @@ import React from "react";
import BasePage from "../../Base";
import classes from "./classes.module.scss";
import OcrResult from "./OcrResult";
import Files from "@Front/Api/LeCoffreApi/SuperAdmin/Files/Files";
type IProps = {};
@ -90,7 +91,7 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
</div>
)}
<div className={classes["file-container"]}>
<FilePreview href={this.state.selectedFile.file_path as string} key={this.state.selectedFile.uid} />
<FilePreview href={Files.getInstance().getUploadLink(this.state.selectedFile?.uid as string)} key={this.state.selectedFile.uid} />
</div>
{this.state.document.files.length > 1 && (
<div
@ -199,7 +200,7 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
private downloadFile() {
const fileName = this.state.selectedFile?.file_path?.split("/").pop();
fetch(this.state.selectedFile?.file_path as string)
fetch(Files.getInstance().getUploadLink(this.state.selectedFile?.uid as string))
.then((resp) => resp.blob())
.then((blob) => {
const url = window.URL.createObjectURL(blob);

View File

@ -10,7 +10,7 @@ import { useRouter } from "next/router";
//import React, { useEffect, useState } from "react";
import React from "react";
//import Loader from "@Front/Components/DesignSystem/Loader";
import Auth from "@Front/Api/Auth/IdNot";
//import Auth from "@Front/Api/Auth/IdNot";
import Folder from "../Folder";
import LoginClass from "../Login";
@ -75,15 +75,15 @@ export default function LoginCallBack(props: IPropsClass) {
const router = useRouter();
const { code } = router.query;
if (code) {
const getIdNotJwt = async () => {
try {
const authService = Auth.getInstance();
await authService.getIdnotJwt(code);
} catch (error) {
console.error(error);
}
};
getIdNotJwt();
// const getIdNotJwt = async () => {
// try {
// const authService = Auth.getInstance();
// await authService.getIdnotJwt(code);
// } catch (error) {
// console.error(error);
// }
// };
//getIdNotJwt();
return <Folder {...props} />;
}
return <LoginClass {...props} />;

View File

@ -6,6 +6,8 @@ import Image from "next/image";
import DefaultDoubleSidePage from "@Front/Components/LayoutTemplates/DefaultDoubleSidePage";
import FranceConnectIcon from "./france-connect.svg";
import ExportIcon from "@Assets/Icons/export.svg";
import { FrontendVariables } from "@Front/Config/VariablesFront";
import cryptoRandomString from "crypto-random-string";
export default class LoginCustomer extends BasePage {
public override render(): JSX.Element {
@ -35,12 +37,12 @@ export default class LoginCustomer extends BasePage {
}
private redirectUserOnConnection() {
// const variables = FrontendVariables.getInstance();
const variables = FrontendVariables.getInstance();
// const baseFronturl =
// variables.BACK_API_PROTOCOL + variables.FRONT_APP_HOST + (variables.FRONT_APP_PORT ? ":" + variables.FRONT_APP_PORT : "");
// const authorizeEndPoint = variables.IDNOT_AUTHORIZE_ENDPOINT;
// const clientId = variables.IDNOT_CLIENT_ID;
// const url = `${authorizeEndPoint}?client_id=${clientId}&redirect_uri=${baseFronturl}/authorized-client&scope=openid,profile,offline_access&response_type=code`;
// window.location.assign(url);
const authorizeEndPoint = variables.FC_AUTHORIZE_ENDPOINT;
const clientId = variables.FC_CLIENT_ID;
const url = `${authorizeEndPoint}?client_id=${clientId}&redirect_uri=http://localhost:8080/login-callback&scope=openid&response_type=code&state=${cryptoRandomString({length: 64})}&nonce=${cryptoRandomString({length: 64})}&acr_values=eidas1`;
window.location.assign(url);
}
}

View File

@ -19,6 +19,10 @@ export class FrontendVariables {
public KEY_DATA!: string;
public FC_AUTHORIZE_ENDPOINT!: string;
public FC_CLIENT_ID!: string;
private constructor() {}
public static getInstance(): FrontendVariables {

View File

@ -20,6 +20,8 @@ type AppPropsWithLayout = AppProps & {
frontAppPort: string;
idNotAuthorizeEndpoint: string;
idNotClientId: string;
fcAuthorizeEndpoint: string;
fcClientId: string;
};
const MyApp = (({
@ -33,6 +35,8 @@ const MyApp = (({
frontAppPort,
idNotAuthorizeEndpoint,
idNotClientId,
fcAuthorizeEndpoint,
fcClientId
}: AppPropsWithLayout) => {
const getLayout = Component.getLayout ?? ((page) => <DefaultLayout children={page}></DefaultLayout>);
@ -45,6 +49,8 @@ const MyApp = (({
instance.FRONT_APP_PORT = frontAppPort;
instance.IDNOT_AUTHORIZE_ENDPOINT = idNotAuthorizeEndpoint;
instance.IDNOT_CLIENT_ID = idNotClientId;
instance.FC_AUTHORIZE_ENDPOINT= fcAuthorizeEndpoint;
instance.FC_CLIENT_ID = fcClientId
return getLayout(<Component {...pageProps} />);
}) as AppType;
@ -59,6 +65,8 @@ MyApp.getInitialProps = async () => {
frontAppPort: process.env["NEXT_PUBLIC_FRONT_APP_PORT"],
idNotAuthorizeEndpoint: process.env["NEXT_PUBLIC_IDNOT_AUTHORIZE_ENDPOINT"],
idNotClientId: process.env["NEXT_PUBLIC_IDNOT_CLIENT_ID"],
fcAuthorizeEndpoint: process.env["NEXT_PUBLIC_FC_AUTHORIZE_ENDPOINT"],
fcClientId: process.env["NEXT_PUBLIC_FC_CLIENT_ID"]
};
};

View File

@ -0,0 +1,5 @@
import ClientDashboard from "@Front/Components/Layouts/ClientDashboard";
export default function Route() {
return <ClientDashboard />;
}