-
-
Notifications
You must be signed in to change notification settings - Fork 866
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PUI] Session authentication (#6970)
* Adjust backend cookie settings * Allow CORS requests to /accounts/ * Refactor frontend code - Remove API token functions - Simplify cookie approach - Add isLoggedIn method * Adjust REST_AUTH settings * Cleanup auth functions in auth.tsx * Adjust CSRF_COOKIE_SAMESITE value * Fix login request * Prevent session auth on login view - Existing (invalid) session token causes 403 * Refactor ApiImage - Point to the right host - Simplify code - Now we use session cookies, so it *Just Works* * Fix download for attachment table - Now works with remote host * Cleanup settings.py * Refactor login / logout notifications * Update API version * Update src/frontend/src/components/items/AttachmentLink.tsx Co-authored-by: Lukas <[email protected]> * fix assert url * Remove comment * Add explicit page to logout user * Change tests to first logout * Prune dead code * Adjust tests * Cleanup * Direct to login view * Trying something * Update CUI test * Fix basic tests * Refactoring * Fix basic checks * Fix for PUI command tests * More test updates * Add speciifc test for quick login * More cleanup of playwright tests * Add some missing icons * Fix typo * Ignore coverage report for playwright test * Remove coveralls upload task --------- Co-authored-by: Lukas <[email protected]> Co-authored-by: Matthias Mair <[email protected]>
- Loading branch information
1 parent
d24219f
commit 0ba7f7e
Showing
30 changed files
with
342 additions
and
360 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -544,15 +544,6 @@ jobs: | |
- name: Report coverage | ||
if: always() | ||
run: cd src/frontend && npx nyc report --report-dir ./coverage --temp-dir .nyc_output --reporter=lcov --exclude-after-remap false | ||
- name: Upload Coverage Report to Coveralls | ||
if: always() | ||
uses: coverallsapp/github-action@3dfc5567390f6fa9267c0ee9c251e4c8c3f18949 # [email protected] | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
flag-name: pui | ||
git-commit: ${{ github.sha }} | ||
git-branch: ${{ github.ref }} | ||
parallel: true | ||
- name: Upload coverage reports to Codecov | ||
uses: codecov/[email protected] | ||
if: always() | ||
|
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
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
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 |
---|---|---|
@@ -1,40 +1,24 @@ | ||
import { QueryClient } from '@tanstack/react-query'; | ||
import axios from 'axios'; | ||
|
||
import { getCsrfCookie } from './functions/auth'; | ||
import { useLocalState } from './states/LocalState'; | ||
import { useSessionState } from './states/SessionState'; | ||
|
||
// Global API instance | ||
export const api = axios.create({}); | ||
|
||
/* | ||
* Setup default settings for the Axios API instance. | ||
* | ||
* This includes: | ||
* - Base URL | ||
* - Authorization token (if available) | ||
* - CSRF token (if available) | ||
*/ | ||
export function setApiDefaults() { | ||
const host = useLocalState.getState().host; | ||
const token = useSessionState.getState().token; | ||
|
||
api.defaults.baseURL = host; | ||
api.defaults.timeout = 2500; | ||
api.defaults.headers.common['Authorization'] = token | ||
? `Token ${token}` | ||
: undefined; | ||
|
||
if (!!getCsrfCookie()) { | ||
api.defaults.withCredentials = true; | ||
api.defaults.xsrfCookieName = 'csrftoken'; | ||
api.defaults.xsrfHeaderName = 'X-CSRFToken'; | ||
} else { | ||
api.defaults.withCredentials = false; | ||
api.defaults.xsrfCookieName = undefined; | ||
api.defaults.xsrfHeaderName = undefined; | ||
} | ||
api.defaults.withCredentials = true; | ||
api.defaults.withXSRFToken = true; | ||
api.defaults.xsrfCookieName = 'csrftoken'; | ||
api.defaults.xsrfHeaderName = 'X-CSRFToken'; | ||
} | ||
|
||
export const queryClient = new QueryClient(); |
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
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.