-
Notifications
You must be signed in to change notification settings - Fork 61
Shift Tethys API Views from CSRF and Session to JSON Web Token (JWT) #1216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
288e2bf
in reactapp, replace getSession and getCSRF with getJWTToken. getJWTT…
ckrew cf215a7
removed unnecessary djangorestframework_simplejwt[crypto] dependency
ckrew 1d253df
added option to get JWT using username and password authentication if…
ckrew 5c0ec38
added back old apis and added deprecation warning
ckrew 65d1d18
added tests for get_jwt_token and dont allow the POST basic authentic…
ckrew 8bb3604
added documentation for ALLOW_JWT_BASIC_AUTHENTICATION setting
ckrew d5b7114
Merge branch 'main' into api_view_updates
ckrew 47ad615
Merge branch 'main' into api_view_updates
ckrew 07d0565
updated deprecation warning
ckrew b315293
black format
ckrew File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
60 changes: 26 additions & 34 deletions
60
tethys_cli/scaffold_templates/app_templates/react/reactapp/components/loader/Loader.js
This file contains hidden or 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
41 changes: 30 additions & 11 deletions
41
tethys_cli/scaffold_templates/app_templates/react/reactapp/services/api/tethys.js
This file contains hidden or 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,29 +1,48 @@ | ||
| import apiClient from "services/api/client"; | ||
|
|
||
| function getSession() { | ||
| return apiClient.get('/api/session/'); | ||
| // JWT token storage helpers | ||
| const ACCESS_TOKEN_KEY = "jwt_access"; | ||
| const REFRESH_TOKEN_KEY = "jwt_refresh"; | ||
|
|
||
| export function setTokens(access, refresh) { | ||
| localStorage.setItem(ACCESS_TOKEN_KEY, access); | ||
| localStorage.setItem(REFRESH_TOKEN_KEY, refresh); | ||
| } | ||
| export function getAccessToken() { | ||
| return localStorage.getItem(ACCESS_TOKEN_KEY); | ||
| } | ||
| export function getRefreshToken() { | ||
| return localStorage.getItem(REFRESH_TOKEN_KEY); | ||
| } | ||
swainn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| async function getJWTToken() { | ||
| const response = await apiClient.get("/api/token/", {}); | ||
| const access = response.access; | ||
| const refresh = response.refresh; | ||
| setTokens(access, refresh); | ||
| return { access, refresh }; | ||
| } | ||
|
|
||
| function getCSRF() { | ||
| return apiClient.get('/api/csrf/') | ||
| .then(response => { | ||
| return response.headers['x-csrftoken']; | ||
| }); | ||
| async function refreshJWTToken() { | ||
| const response = await apiClient.post("/api/token/refresh/", { | ||
| refresh: getRefreshToken(), | ||
| }); | ||
| return response.data.access; | ||
| } | ||
|
|
||
| function getUserData() { | ||
| return apiClient.get('/api/whoami/'); | ||
| return apiClient.get("/api/whoami/"); | ||
| } | ||
|
|
||
| function getAppData(tethys_app_url) { | ||
| return apiClient.get(`/api/apps/${tethys_app_url}/`); | ||
| } | ||
|
|
||
| const tethysAPI = { | ||
| getSession, | ||
| getCSRF, | ||
| getJWTToken, | ||
| refreshJWTToken, | ||
| getAppData, | ||
| getUserData, | ||
| }; | ||
|
|
||
| export default tethysAPI; | ||
| export default tethysAPI; | ||
This file contains hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.