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

vibe.web.auth – optional authentication #2682

Open
p-mitana opened this issue Aug 5, 2022 · 0 comments
Open

vibe.web.auth – optional authentication #2682

p-mitana opened this issue Aug 5, 2022 · 0 comments

Comments

@p-mitana
Copy link

p-mitana commented Aug 5, 2022

Hello,

I found a little hole in vibe.web.auth: imagine a situation, where I want everyone to be able to access the endpoint, but still want to know, whether this is a registered users and what roles does he have.

Currently I can do:

@noAuth get() // Anyone can access, but I don't know, if he is authenticated and who he is
@anyAuth get(AuthInfo authInfo) // I do know, who the user is, but unless he is authenticated, he cannot access.

What I would like to have is:

@anyAuth get(Nullable!AuthInfo authInfo) // If user is not authenticated authInfo is Nullable.null

Suggested solution: allow an authentication method overload, which returns Nullable:

@requiresAuthentication
interface API {
    // either of these two can be used
    @noRoute AuthInfo authenticate(HTTPServerRequest, HTTPServerResponse);
    @noRoute Nullable!AuthInfo authenticate(HTTPServerRequest, HTTPServerResponse);

    // Authentication required – if there is only Nullable authenticate variant and it returns null, 401 is returned
    @anyAuth get(AuthInfo auth);

    // Authentication not required, but still attempted
    @anyAuth get(Nullable!AuthInfo auth); 
}
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

1 participant