the auth provider has been improved and the README was extended
This commit is contained in:
53
README.md
53
README.md
@@ -1,13 +1,15 @@
|
|||||||
# tfp-frontend-poc
|
# TFP Frontend PoC
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
**Requirements**:
|
||||||
|
* [Node.js](https://nodejs.org/en) v20+
|
||||||
|
* [pnpm](https://pnpm.io/) v9+
|
||||||
|
|
||||||
Install the application dependencies by running:
|
Install the application dependencies by running:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
npm install
|
pnpm i
|
||||||
# or
|
|
||||||
yarn install
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
@@ -15,33 +17,28 @@ yarn install
|
|||||||
Start the application in development mode by running:
|
Start the application in development mode by running:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
npm run dev
|
pnpm dev
|
||||||
# or
|
|
||||||
yarn dev
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Production
|
|
||||||
|
|
||||||
Build the application in production mode by running:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
npm run build
|
|
||||||
# or
|
|
||||||
yarn build
|
|
||||||
```
|
|
||||||
|
|
||||||
## DataProvider
|
|
||||||
|
|
||||||
The included data provider use [ra-data-simple-rest](https://github.com/marmelab/react-admin/tree/master/packages/ra-data-simple-rest). It fits REST APIs using simple GET parameters for filters and sorting. This is the dialect used for instance in [FakeRest](https://github.com/marmelab/FakeRest).
|
|
||||||
|
|
||||||
You'll find an `.env` file at the project root that includes a `VITE_JSON_SERVER_URL` variable. Set it to the URL of your backend.
|
|
||||||
|
|
||||||
## Authentication
|
## Authentication
|
||||||
|
|
||||||
The included auth provider should only be used for development and test purposes.
|
`src/authProvider.ts` -> get the token in authProvider.login method
|
||||||
You'll find a `users.json` file in the `src` directory that includes the users you can use.
|
|
||||||
|
|
||||||
You can sign in to the application with the following usernames and password:
|
The user/pass can be anything. The token will come from `http://localhost:8080/atsp-idp/token` and it will forwarded
|
||||||
- janedoe / password
|
to the UI that can handle from this point.
|
||||||
- johndoe / password
|
|
||||||
|
|
||||||
|
## DataProvider
|
||||||
|
|
||||||
|
`src/admin-core/data-provider-extension.ts` -> Here is the user's list entry point but it can be rewrote to anything.
|
||||||
|
This is not working from this because authentication and CORS error.
|
||||||
|
|
||||||
|
I think, the authentication access_token is not enought.* I do not know what is the purpose of the three token
|
||||||
|
* `id_token`
|
||||||
|
* `access_token`
|
||||||
|
* & the `refresh_token`
|
||||||
|
|
||||||
|
It seems, the backend always wanted to redirect to somewhere when authentication or authorization happens. This purpose is not normal for a REST API.
|
||||||
|
A **REST API** back-end have to communicate through JSON only. Any redirection have to be handled by the front-end. In my opinion the Keycloak/oauth communication
|
||||||
|
should be "masked" by the backend.
|
||||||
|
|
||||||
|
The cleanest solution is that; on the REST api should have an entry point for authentication that can be used by front-end. After that, the authorization happens w/ the token only.
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export const useQueryEngine = () => {
|
|||||||
: {
|
: {
|
||||||
headers: {
|
headers: {
|
||||||
...defaultHeaders,
|
...defaultHeaders,
|
||||||
Authorization: `Bearer ${localStorage.getItem('token')}`,
|
Authorization: `Bearer ${localStorage.getItem('user')}`,
|
||||||
...(options?.headers ? { ...options.headers } : {}),
|
...(options?.headers ? { ...options.headers } : {}),
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
@@ -50,7 +50,7 @@ export const useQueryEngine = () => {
|
|||||||
* @see https://stackoverflow.com/a/71392989/3111514
|
* @see https://stackoverflow.com/a/71392989/3111514
|
||||||
*/
|
*/
|
||||||
// 'Content-Type': 'multipart/form-data',
|
// 'Content-Type': 'multipart/form-data',
|
||||||
Authorization: `Bearer ${localStorage.getItem('token')}`,
|
Authorization: `Bearer ${localStorage.getItem('user')}`,
|
||||||
},
|
},
|
||||||
...options,
|
...options,
|
||||||
}),
|
}),
|
||||||
@@ -66,7 +66,7 @@ export const useQueryEngine = () => {
|
|||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
...(options?.headers ? { headers: options.headers } : {}),
|
...(options?.headers ? { headers: options.headers } : {}),
|
||||||
...(withAuth ? { Authorization: `Bearer ${localStorage.getItem('token')}` } : {}),
|
...(withAuth ? { Authorization: `Bearer ${localStorage.getItem('user')}` } : {}),
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
...(options?.body ? { body: options.body } : {}),
|
...(options?.body ? { body: options.body } : {}),
|
||||||
|
|||||||
@@ -36,9 +36,9 @@ export const authProvider: AuthProvider = {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { access_token } = await response.json();
|
const { refresh_token } = await response.json();
|
||||||
localStorage.setItem("token", access_token);
|
localStorage.setItem("token", refresh_token);
|
||||||
localStorage.setItem("user", access_token);
|
localStorage.setItem("user", refresh_token);
|
||||||
|
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user