aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/tvmauth/checked_user_ticket.h
blob: 32256de6a7420aa4f47fc5da3bc4650479b93875 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#pragma once

#include "ticket_status.h"
#include "type.h"
#include "utils.h"

#include <util/generic/ptr.h>

#include <optional>

namespace NTvmAuth::NInternal {
    class TCanningKnife;
}

namespace NTvmAuth {
    /*!
     * BlackboxEnv describes environment of Passport:
     * https://wiki.yandex-team.ru/passport/tvm2/user-ticket/#0-opredeljaemsjasokruzhenijami
     */
    enum class EBlackboxEnv: ui8 {
        Prod,
        Test,
        ProdYateam,
        TestYateam,
        Stress
    };

    /*!
     * UserTicket contains only valid users.
     * Details: https://wiki.yandex-team.ru/passport/tvm2/user-ticket/#chtoestvusertickete
     */
    class TCheckedUserTicket {
    public:
        class TImpl;

        TCheckedUserTicket(THolder<TImpl> impl);
        TCheckedUserTicket(TCheckedUserTicket&&);
        ~TCheckedUserTicket();

        TCheckedUserTicket& operator=(TCheckedUserTicket&&);

        /*!
         * @return True value if ticket parsed and checked successfully
         */
        explicit operator bool() const;

        /*!
         * Never empty
         * @return UIDs of users listed in ticket
         */
        const TUids& GetUids() const;

        /*!
         * Maybe 0
         * @return Default user in ticket
         */
        TUid GetDefaultUid() const;

        /*!
         * Never empty
         * @return UIDs of users listed in ticket with user extended fields
         */
        TUidsExtFieldsMap GetUidsExtFields() const;

        /*!
         * Empty if there is no default uid in ticket
         * @return Default user in ticket with extended fields
         */
        std::optional<TUserExtFields> GetDefaultUidExtFields() const;

        /*!
         * Scopes inherited from credential - never empty
         * @return Newly constructed vector of scopes
         */
        const TScopes& GetScopes() const;

        /*!
         * Check if scope presented in ticket
         */
        bool HasScope(TStringBuf scopeName) const;

        /*!
         * @return Ticket check status
         */
        ETicketStatus GetStatus() const;

        /*!
         * DebugInfo is human readable data for debug purposes
         * @return Serialized ticket
         */
        TString DebugInfo() const;

        /*!
         * Env of user
         */
        EBlackboxEnv GetEnv() const;

        /*!
         * @return login_id of user
         * empty if ticket does not contain login_id
         */
        const TString& GetLoginId() const;

    public: // for python binding
        TCheckedUserTicket() = default;

    private:
        THolder<TImpl> Impl_;
        friend class NInternal::TCanningKnife;
    };
}