userver: userver/server/auth/user_auth_info.hpp Source File
Loading...
Searching...
No Matches
user_auth_info.hpp
1#pragma once
2
3#include <optional>
4#include <string>
5
6#include <userver/server/request/request_context.hpp>
7#include <userver/utils/strong_typedef.hpp>
8
9#include <userver/server/auth/user_env.hpp>
10#include <userver/server/auth/user_id.hpp>
11#include <userver/server/auth/user_provider.hpp>
12#include <userver/server/auth/user_scopes.hpp>
13
14USERVER_NAMESPACE_BEGIN
15
16namespace server::handlers::auth {
17class AuthCheckerBase;
18}
19
20namespace server::auth {
21
22class UserAuthInfo final {
23 public:
24 using Ticket = utils::NonLoggable<class TicketTag, std::string>;
25
26 UserAuthInfo(UserId default_id, UserEnv env, UserProvider provider);
27 UserAuthInfo(UserId default_id, Ticket user_ticket, UserEnv env,
28 UserProvider provider);
29
30 UserAuthInfo(UserId default_id, UserIds ids, UserScopes scopes, UserEnv env,
31 UserProvider provider);
32 UserAuthInfo(UserId default_id, UserIds ids, UserScopes scopes,
33 Ticket user_ticket, UserEnv env, UserProvider provider);
34
35 UserId GetDefaultUserId() const;
36 const UserIds& GetUserIds() const;
37 const std::optional<UserScopes>& GetUserScopesOptional() const;
38 const std::optional<Ticket>& GetTicketOptional() const;
39 UserEnv GetUserEnv() const { return user_env_; }
40 UserProvider GetUserProvider() const { return user_provider_; }
41
42 private:
43 friend class server::handlers::auth::AuthCheckerBase;
44 static void Set(server::request::RequestContext& request_context,
45 UserAuthInfo&& info);
46
47 UserId default_id_;
48 UserIds ids_;
49 std::optional<UserScopes> scopes_;
50 std::optional<Ticket> user_ticket_;
51 UserEnv user_env_;
52 UserProvider user_provider_;
53};
54
55const UserAuthInfo& GetUserAuthInfo(
56 const server::request::RequestContext& request_context);
57
58} // namespace server::auth
59
60USERVER_NAMESPACE_END