This repository has been archived by the owner on Jun 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR allows unauthenticated requests to be made though the apiClient. There are breaking behavior changes. There are also breaking API changes as well as new functionality contained in this refactor. **New functionality:** - `getAuthenticatedUser`: a function that gets the jwt token and returns user information. It will return null if the user is not authenticated. It will not perform a redirect, unlike `ensureAuthenticatedUser`. - `isPublic` and `isCsrfExempt` options have been added to request configuration for axios requests (get, post, patch, etc). Setting these to true will prevent frontend-auth from attempting to refresh the jwt access token or a csrf token respectively. BREAKING CHANGE: (Behavior Change) Frontend-auth intercepts outbound requests and attempts to refresh the jwt token if it does not exist or is expired. In the case of a 401 response indicating that the user is logged out, frontend auth will not redirect the user to login, and will allow the outbound request to proceed. Prior behavior: Upon receiving a 401 response, frontend-auth would block the request and redirect the user to login. `ensureAuthenticatedUser` continues to redirect if the user is logged out. **API Changes** - `getAuthenticatedAPIClient` has been renamed to `getAuthenticatedApiClient`. Note the capitalization changes: API > Api. - `redirectToLogout` (formerly `apiClient.logout`) - `redirectToLogin` (formerly `apiClient.login`) - `ensureAuthenticatedUser` (formerly `apiClient.ensureAuthenticatedUser`) See the updated README for more details.
- Loading branch information
Adam Butterworth
authored
Nov 5, 2019
1 parent
1667c95
commit de68ed4
Showing
22 changed files
with
1,507 additions
and
471 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
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<a name="LoginRedirect"></a> | ||
|
||
## LoginRedirect : <code>ReactComponent</code> | ||
**Kind**: global class | ||
<a name="redirectToLogin"></a> | ||
|
||
## redirectToLogin(redirectUrl) | ||
Redirect the user to login | ||
|
||
**Kind**: global function | ||
|
||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| redirectUrl | <code>string</code> | the url to redirect to after login | | ||
|
||
<a name="redirectToLogout"></a> | ||
|
||
## redirectToLogout(redirectUrl) | ||
Redirect the user to logout | ||
|
||
**Kind**: global function | ||
|
||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| redirectUrl | <code>string</code> | the url to redirect to after logout | | ||
|
||
<a name="getAuthenticatedApiClient"></a> | ||
|
||
## getAuthenticatedApiClient(config) ⇒ [<code>HttpClient</code>](#HttpClient) | ||
Gets the apiClient singleton which is an axios instance. | ||
|
||
**Kind**: global function | ||
**Returns**: [<code>HttpClient</code>](#HttpClient) - Singleton. A configured axios http client | ||
|
||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| config | <code>object</code> | | | ||
| [config.appBaseUrl] | <code>string</code> | | | ||
| [config.authBaseUrl] | <code>string</code> | | | ||
| [config.loginUrl] | <code>string</code> | | | ||
| [config.logoutUrl] | <code>string</code> | | | ||
| [config.loggingService] | <code>object</code> | requires logError and logInfo methods | | ||
| [config.refreshAccessTokenEndpoint] | <code>string</code> | | | ||
| [config.accessTokenCookieName] | <code>string</code> | | | ||
| [config.csrfTokenApiPath] | <code>string</code> | | | ||
|
||
<a name="getAuthenticatedUser"></a> | ||
|
||
## getAuthenticatedUser() ⇒ [<code>Promise.<UserData></code>](#UserData) \| <code>Promise.<null></code> | ||
Gets the authenticated user's access token. Resolves to null if the user is unauthenticated. | ||
|
||
**Kind**: global function | ||
**Returns**: [<code>Promise.<UserData></code>](#UserData) \| <code>Promise.<null></code> - Resolves to the user's access token if they are logged in. | ||
<a name="ensureAuthenticatedUser"></a> | ||
|
||
## ensureAuthenticatedUser(route) ⇒ [<code>Promise.<UserData></code>](#UserData) | ||
Ensures a user is authenticated. It will redirect to login when not authenticated. | ||
|
||
**Kind**: global function | ||
|
||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| route | <code>string</code> | to return user after login when not authenticated. | | ||
|
||
<a name="PrivateRoute"></a> | ||
|
||
## PrivateRoute() : <code>ReactComponent</code> | ||
**Kind**: global function | ||
<a name="HttpClient"></a> | ||
|
||
## HttpClient | ||
A configured axios client. See axios docs for more | ||
info https://github.com/axios/axios. All the functions | ||
below accept isPublic and isCsrfExempt in the request | ||
config options. Setting these to true will prevent this | ||
client from attempting to refresh the jwt access token | ||
or a csrf token respectively. | ||
|
||
``` | ||
// A public endpoint (no jwt token refresh) | ||
apiClient.get('/path/to/endpoint', { isPublic: true }); | ||
``` | ||
|
||
``` | ||
// A csrf exempt endpoint | ||
apiClient.post('/path/to/endpoint', { data }, { isCsrfExempt: true }); | ||
``` | ||
|
||
**Kind**: global typedef | ||
**Properties** | ||
|
||
| Name | Type | Description | | ||
| --- | --- | --- | | ||
| get | <code>function</code> | | | ||
| head | <code>function</code> | | | ||
| options | <code>function</code> | | | ||
| delete | <code>function</code> | (csrf protected) | | ||
| post | <code>function</code> | (csrf protected) | | ||
| put | <code>function</code> | (csrf protected) | | ||
| patch | <code>function</code> | (csrf protected) | | ||
|
||
<a name="UserData"></a> | ||
|
||
## UserData | ||
**Kind**: global typedef | ||
**Properties** | ||
|
||
| Name | Type | | ||
| --- | --- | | ||
| userId | <code>string</code> | | ||
| username | <code>string</code> | | ||
| roles | <code>array</code> | | ||
| administrator | <code>bool</code> | | ||
|
Oops, something went wrong.