Skip to content
This repository has been archived by the owner on Jun 2, 2021. It is now read-only.

feat: anonymous access #82

Merged
merged 31 commits into from
Nov 5, 2019
Merged

Conversation

abutterworth
Copy link
Contributor

@abutterworth abutterworth commented Nov 1, 2019

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 CHANGES:

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.

@coveralls
Copy link

coveralls commented Nov 1, 2019

Coverage Status

Coverage remained the same at 100.0% when pulling 46c8a2f on abutterworth/anonymous-access-refactor into 1667c95 on master.

@abutterworth abutterworth changed the title feat: move to a more functional programmatic structure feat: anonymous access Nov 4, 2019
@abutterworth abutterworth requested a review from a team November 4, 2019 17:22
Copy link
Contributor

@davidjoy davidjoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do like the idea of changing the signature of getConfig() a bit, but otherwise this looks good to me, so I'll provisionally approve!

Copy link
Contributor

@robrap robrap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay.

README.rst Outdated Show resolved Hide resolved
README.rst Outdated Show resolved Hide resolved
README.rst Outdated Show resolved Hide resolved
@@ -0,0 +1,115 @@
<a name="LoginRedirect"></a>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should consider as part of future runway efforts:

  1. automatically generating and publishing to read-the-docs
  2. Not needing to check this in here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

src/AuthenticatedApiClient/axiosInterceptors.js Outdated Show resolved Hide resolved
src/AuthenticatedApiClient/index.js Show resolved Hide resolved
@abutterworth abutterworth merged commit de68ed4 into master Nov 5, 2019
@abutterworth abutterworth deleted the abutterworth/anonymous-access-refactor branch November 5, 2019 22:00
abutterworth pushed a commit to edx/frontend-base that referenced this pull request Nov 6, 2019
* feat: upgrade frontend-auth with anonymous access capability

BREAKING CHANGE: Uses the new api offered by frontend auth. App.apiClient no longer has methods login, logout, getDecodedAccessToken or refreshAccessToken. Refer to edx/frontend-auth#82 for more info.

* docs: typo

* docs: update redirect description

* fix: upgrade frontend-auth
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants