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 {
23public:
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, UserProvider provider);
28
29 UserAuthInfo(UserId default_id, UserIds ids, UserScopes scopes, UserEnv env, UserProvider provider);
30 UserAuthInfo(
31 UserId default_id,
32 UserIds ids,
33 UserScopes scopes,
34 Ticket user_ticket,
35 UserEnv env,
36 UserProvider provider
37 );
38
39 UserId GetDefaultUserId() const;
40 const UserIds& GetUserIds() const;
41 const std::optional<UserScopes>& GetUserScopesOptional() const;
42 const std::optional<Ticket>& GetTicketOptional() const;
43 UserEnv GetUserEnv() const { return user_env_; }
44 UserProvider GetUserProvider() const { return user_provider_; }
45
46private:
47 friend class server::handlers::auth::AuthCheckerBase;
48 static void Set(server::request::RequestContext& request_context, UserAuthInfo&& info);
49
50 UserId default_id_;
51 UserIds ids_;
52 std::optional<UserScopes> scopes_;
53 std::optional<Ticket> user_ticket_;
54 UserEnv user_env_;
55 UserProvider user_provider_;
56};
57
58const UserAuthInfo& GetUserAuthInfo(const server::request::RequestContext& request_context);
59
60const std::optional<UserAuthInfo> GetUserAuthInfoOpt(const server::request::RequestContext& request_context);
61
62} // namespace server::auth
63
64USERVER_NAMESPACE_END