-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
6e3bab6
commit 2ba35fa
Showing
6 changed files
with
107 additions
and
73 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
18 changes: 17 additions & 1 deletion
18
components/inspectit-ocelot-configurationserver-ui/src/data/constants.js
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,4 +1,20 @@ | ||
/** | ||
* Various constants used by the application. | ||
*/ | ||
export const BASE_PAGE_TITLE = "inspectIT Ocelot Configuration Server"; | ||
|
||
/** | ||
* Default <title> content | ||
*/ | ||
export const BASE_PAGE_TITLE = "inspectIT Ocelot Configuration Server"; | ||
|
||
/** | ||
* Interval in which will be checked, whether the token will be expiring. | ||
*/ | ||
export const RENEW_TOKEN_TIME_INTERVAL = 60000; | ||
|
||
/** | ||
* Minimum expiration time | ||
* If the expiration time of the current token is shorter than the MIN_TOKEN_EXPIRATION_IIME, the token will be renewed. | ||
*/ | ||
export const MIN_TOKEN_EXPIRATION_TIME = 300000; | ||
|
113 changes: 49 additions & 64 deletions
113
components/inspectit-ocelot-configurationserver-ui/src/redux/ducks/authentication/actions.js
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,80 +1,65 @@ | ||
import * as types from "./types"; | ||
import {axiosPlain} from '../../../lib/axios-api'; | ||
|
||
import {configurationActions} from '../configuration'; | ||
import { axiosPlain } from "../../../lib/axios-api"; | ||
import axiosBearer from "../../../lib/axios-api"; | ||
import { configurationActions } from "../configuration"; | ||
|
||
/** | ||
* Fetches an access token for the given credentials. | ||
* | ||
* @param {string} username | ||
* @param {string} password | ||
* | ||
* @param {string} username | ||
* @param {string} password | ||
*/ | ||
export const fetchToken = (username, password) => { | ||
return dispatch => { | ||
dispatch(fetchTokenStarted()); | ||
return (dispatch) => { | ||
dispatch({ type: types.FETCH_TOKEN_STARTED }); | ||
|
||
axiosPlain | ||
.get("/account/token", { | ||
auth: { | ||
username: username, | ||
password: password | ||
} | ||
}) | ||
.then(res => { | ||
const token = res.data; | ||
dispatch(fetchTokenSuccess(token, username)); | ||
}) | ||
.catch(err => { | ||
let message; | ||
const { response } = err; | ||
if (response && response.status == 401) { | ||
message = "The given credentials are not valid."; | ||
} else { | ||
message = err.message; | ||
} | ||
dispatch(fetchTokenFailure(message)); | ||
}); | ||
}; | ||
axiosPlain | ||
.get("/account/token", { | ||
auth: { | ||
username: username, | ||
password: password | ||
} | ||
}) | ||
.then(res => { | ||
const token = res.data; | ||
dispatch({ type: types.FETCH_TOKEN_SUCCESS, payload: { token, username } }); | ||
}) | ||
.catch(err => { | ||
let message; | ||
const { response } = err; | ||
if (response && response.status == 401) { | ||
message = "The given credentials are not valid."; | ||
} else { | ||
message = err.message; | ||
} | ||
dispatch({ type: types.FETCH_TOKEN_FAILURE, payload: { error: message } }); | ||
}); | ||
}; | ||
}; | ||
|
||
/** | ||
* Is dispatched when the fetching of the access token has been started. | ||
* Renews the access token with the existing token. | ||
* | ||
*/ | ||
export const fetchTokenStarted = () => ({ | ||
type: types.FETCH_TOKEN_STARTED | ||
}); | ||
|
||
/** | ||
* Is dispatched if the fetching of the access token was not successful. | ||
* | ||
* @param {*} error | ||
*/ | ||
export const fetchTokenFailure = (error) => ({ | ||
type: types.FETCH_TOKEN_FAILURE, | ||
payload: { | ||
error | ||
} | ||
}); | ||
|
||
/** | ||
* Is dispatched when the fetching of the access token was successful. | ||
* | ||
* @param {string} token | ||
*/ | ||
export const fetchTokenSuccess = (token, username) => ({ | ||
type: types.FETCH_TOKEN_SUCCESS, | ||
payload: { | ||
token, | ||
username | ||
} | ||
}); | ||
export const renewToken = () => { | ||
return (dispatch) => { | ||
axiosBearer | ||
.get("/account/token") | ||
.then(res => { | ||
const token = res.data; | ||
dispatch({ type: types.RENEW_TOKEN_SUCCESS, payload: { token } }); | ||
}) | ||
.catch(err => { | ||
}); | ||
}; | ||
}; | ||
|
||
/** | ||
* Logout of the current user. | ||
*/ | ||
export const logout = () => { | ||
return dispatch => { | ||
dispatch({type: types.LOGOUT}); | ||
dispatch(configurationActions.resetState()); | ||
}; | ||
}; | ||
return dispatch => { | ||
dispatch({ type: types.LOGOUT }); | ||
dispatch(configurationActions.resetState()); | ||
}; | ||
}; |
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
5 changes: 4 additions & 1 deletion
5
components/inspectit-ocelot-configurationserver-ui/src/redux/ducks/authentication/types.js
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,4 +1,7 @@ | ||
export const FETCH_TOKEN_STARTED = 'authorization/FETCH_TOKEN_STARTED'; | ||
export const FETCH_TOKEN_FAILURE = 'authorization/FETCH_TOKEN_FAILURE'; | ||
export const FETCH_TOKEN_SUCCESS = 'authorization/FETCH_TOKEN_SUCCESS'; | ||
export const LOGOUT = 'authorization/LOGOUT'; | ||
|
||
export const RENEW_TOKEN_SUCCESS = 'authorization/RENEW_TOKEN_SUCCESS'; | ||
|
||
export const LOGOUT = 'authorization/LOGOUT'; |