Skip to content
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

Checks for auth token on app refresh #2793

Merged
merged 9 commits into from Jan 10, 2023

Conversation

vindex10
Copy link
Contributor

Hi, All!

I noticed that, at least, in case of basic auth, the token stored in the storage is not checked for. Therefore, upon refresh user needs to login again.

I suggest some potential change that fixes this. I'm a newcomer to dispatch, so I expect I will learn something new soon :)

Look forward to your feedback!

Cheers,
Victor

@vindex10 vindex10 force-pushed the bug/logout_on_refresh_basic_auth branch from 317c526 to 7b8a9c0 Compare January 4, 2023 13:29
@mvilanova
Copy link
Contributor

Thanks for the PR, @vindex10 . I'll take a look and circle back soon.

@mvilanova mvilanova added the bug Something isn't working label Jan 5, 2023
@mvilanova mvilanova changed the title check for auth token on app refresh Checks for auth token on app refresh Jan 5, 2023
@mvilanova
Copy link
Contributor

Changes look good to me. I'll let @kevgliss take a look at them before merging them.

@kevgliss
Copy link
Contributor

kevgliss commented Jan 9, 2023

@vindex10 Could you explain a little more about the behavior you are seeing? Locally, I can't replicate what you describe (a page refresh does not force login if the user has a valid token).

If the app state gets wiped (e.g. by a refresh), we explicitly test for an existing token here and use if it's available:

let token = localStorage.getItem("token")

Local storage should not be wiped out by a refresh (a user needs to do a hard refresh or otherwise delete this data).

@vindex10
Copy link
Contributor Author

vindex10 commented Jan 9, 2023

OK, thanks! indeed it works. For dev, I had to:

export VITE_DISPATCH_AUTHENTICATION_PROVIDER_SLUG=dispatch-auth-provider-basic

For prod I had to change docker-compose.yaml:

core:
    build:
        context: ../dispatch
        args:
            VITE_DISPATCH_AUTHENTICATION_PROVIDER_SLUG: "dispatch-auth-provider-basic"

And basic auth is enabled by default in the backend? So should this become a part of?
https://github.com/Netflix/dispatch-docker

@vindex10
Copy link
Contributor Author

vindex10 commented Jan 10, 2023

upd: disregard this. it was a wrong guess, and the message above works now for both dev and compose run.

Hmm. It actually didn't work with docker compose. And I have a suspect.

In the setup.py, it looks like the env is not propagated to the npm command:

self._run_npm_command(["run", "build", "--quiet"])

and build_static that used to build the frontend before, doesn't do it anymore:

def _build_static(self):

but it actually handled env vars before.

@vindex10
Copy link
Contributor Author

sorry for the noise :) in summary:

  1. I was wrong. env in setup py is fine.
  2. I had to change build-args for core not for web
  3. I corrected my messages above so that they look less confusing

I'm trying to understand now, which PR to open :) I see the options:

  1. Set default arg in the Netflix/dispatch dockerfile (moderate intrusive option)
  2. Set build arg in the Netflix/dispatch-docker, in the docker-compose.yaml (the least intrusive option)
  3. Set default in router (we are consistent with backend, and api.js)
  4. just mention in the docs that empty auth slug is a feature and how to use it + comment that for the basic auth you need to specify the variable VITE_DISPATCH_AUTHENTICATION_PROVIDER_SLUG explicitly during build
  5. do nothing :)

What confuses me is the slight inconsistency between:

api.js:

import.meta.env.VITE_DISPATCH_AUTHENTICATION_PROVIDER_SLUG || "dispatch-auth-provider-basic"

where default auth is assumed to be "basic auth"

router/index.js:

let authProviderSlug = import.meta.env.VITE_DISPATCH_AUTHENTICATION_PROVIDER_SLUG

here empty authentication slug falls back to custom auth (which seems to be a feature, not a bug)

backend config.py:

"DISPATCH_AUTHENTICATION_PROVIDER_SLUG", default="dispatch-auth-provider-basic"

@kevgliss look forward to your feedback )

@kevgliss
Copy link
Contributor

kevgliss commented Jan 10, 2023

I think your right when you point out the inconsistency here:

let authProviderSlug = import.meta.env.VITE_DISPATCH_AUTHENTICATION_PROVIDER_SLUG

I think the change should align the default to basic-auth similar to what we do here:

import.meta.env.VITE_DISPATCH_AUTHENTICATION_PROVIDER_SLUG || "dispatch-auth-provider-basic"

So, in summary I think we should define:

const authProviderSlug =
  import.meta.env.VITE_DISPATCH_AUTHENTICATION_PROVIDER_SLUG || "dispatch-auth-provider-basic"

here:

I think this is option # 3 that you mentioned.

@vindex10
Copy link
Contributor Author

@kevgliss done. I checked, at least it worked when I ran locally :)

@kevgliss
Copy link
Contributor

LGTM, thanks for the contribution!

@kevgliss kevgliss merged commit 72200f6 into Netflix:master Jan 10, 2023
vindex10 added a commit to LetsData-net/dispatch that referenced this pull request Jan 11, 2023
* make basic auth provider default in vue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants