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

Authentication example using hooks #431

Closed
wizardlevel9 opened this issue Oct 7, 2020 · 6 comments
Closed

Authentication example using hooks #431

wizardlevel9 opened this issue Oct 7, 2020 · 6 comments
Labels

Comments

@wizardlevel9
Copy link

Can you please provide a detailed example of how i would set up authentication (username and password) using hooks.

The documentation outlines that this is possible, but does not provide any guidance or examples.

I would like to take advantage of this fantastic capability, but I'm not sure how to do it correctly.

Any documentation or assistance with examples would be greatly appreciated.

Thanks in advance.

@Acconut
Copy link
Member

Acconut commented Oct 10, 2020

I can't provide you with a "detailed example" right now but the basic gist is that you configure the tus client to put the authentication credentials (e.g. password or token) into an header, such as Authentication. The tusd hooks have access to these headers (see https://github.com/tus/tusd/blob/master/docs/hooks.md#the-hooks-environment) and can validate and check the credentials. If authentication fails, the hook should error out and tusd will reject the upload. I hope that makes sense.

@benitogf
Copy link
Contributor

I was able to implement authentication using the http hook:

tusd -hooks-http="http://localhost:8081/tusd/hook"
  server.Router.HandleFunc("/tusd/hook", func(w http.ResponseWriter, r *http.Request) {
    // https://github.com/tus/tusd/blob/master/docs/hooks.md#usage
    // log.Println("HOOK: ", r.Header.Get("hook-name"))
    hookName := r.Header.Get("hook-name")
    _, account, _ := auth.Audit(r)
    if account == "" && hookName == "pre-create" {
	    log.Println("file upload not authorized")
	    w.WriteHeader(http.StatusUnauthorized)
	    return
    }
    w.WriteHeader(http.StatusOK)
  }).Methods(http.MethodPost)

but I would like to limit file reading as well, is there a way to do this? I think that adding a read hook would be useful

@Acconut
Copy link
Member

Acconut commented May 20, 2021

I would like to limit file reading as well, is there a way to do this?

I am not sure what you mean by this. However, tusd has a MaxSize setting, which controls the maximum allowed upload size.

@benitogf
Copy link
Contributor

I am not sure what you mean by this

Sorry I meant read access limit, a way to prevent unwanted file reads

@Acconut
Copy link
Member

Acconut commented May 25, 2021

Sorry I meant read access limit, a way to prevent unwanted file reads

This is not possible using hooks at the moment. When using the tusd binary the only option right now is to put a proxy in front of tusd to handle authentication for GET requests. There is no hook emitted for GET requests.

@Acconut
Copy link
Member

Acconut commented Jan 24, 2024

The documentation now contains an example for authentication: https://github.com/tus/tusd/blob/main/docs/hooks.md#authenticating-users

@Acconut Acconut closed this as completed Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants