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

[httpauth] Optional credentials #137

Closed
sanpii opened this issue Nov 30, 2020 · 2 comments
Closed

[httpauth] Optional credentials #137

sanpii opened this issue Nov 30, 2020 · 2 comments

Comments

@sanpii
Copy link

sanpii commented Nov 30, 2020

Expected Behavior

Set Authorization header optional.

Current Behavior

If I don’t send the Authorization header, the extractor fail and returns a 401 error.

Possible Solution

Impl AuthExtrator for Option<BasicAuth> and Option<BearerAuth>.

Context

Some routes aren’t require authentication, typically route for registration/sign in.

Your Environment

  • Rust Version (I.e, output of rustc -V): rustc 1.48.0 (7eac88abb 2020-11-16)
  • actix-web-httpauth crate Version: 0.5.0
@GopherJ
Copy link

GopherJ commented Dec 5, 2020

@sanpii I'm always using this PR: #6

ping @Dowwie to give a solution

@robjtede
Copy link
Member

robjtede commented Dec 5, 2020

Optional extractors are done using Option<T> in the handler parameters where you'd put your extractor (T) usually.

In your case that not all routes require auth, then consider only applying the middleare to those that do need it using Scope::wrap or Resource::wrap instead of App::wrap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants