forked from obsproject/obs-studio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth-base.cpp
More file actions
87 lines (73 loc) · 1.7 KB
/
auth-base.cpp
File metadata and controls
87 lines (73 loc) · 1.7 KB
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
#include "auth-base.hpp"
#include "window-basic-main.hpp"
#include <vector>
#include <map>
struct AuthInfo {
Auth::Def def;
Auth::create_cb create;
};
static std::vector<AuthInfo> authDefs;
void Auth::RegisterAuth(const Def &d, create_cb create)
{
AuthInfo info = {d, create};
authDefs.push_back(info);
}
std::shared_ptr<Auth> Auth::Create(const std::string &service)
{
for (auto &a : authDefs) {
if (service.find(a.def.service) != std::string::npos) {
return a.create();
}
}
return nullptr;
}
Auth::Type Auth::AuthType(const std::string &service)
{
for (auto &a : authDefs) {
if (service.find(a.def.service) != std::string::npos) {
return a.def.type;
}
}
return Type::None;
}
bool Auth::External(const std::string &service)
{
for (auto &a : authDefs) {
if (service.find(a.def.service) != std::string::npos) {
return a.def.externalOAuth;
}
}
return false;
}
void Auth::Load()
{
OBSBasic *main = OBSBasic::Get();
const char *typeStr = config_get_string(main->Config(), "Auth", "Type");
if (!typeStr)
typeStr = "";
main->auth = Create(typeStr);
if (main->auth) {
if (main->auth->LoadInternal()) {
main->auth->LoadUI();
main->SetBroadcastFlowEnabled(
main->auth->broadcastFlow());
}
} else {
main->SetBroadcastFlowEnabled(false);
}
}
void Auth::Save()
{
OBSBasic *main = OBSBasic::Get();
Auth *auth = main->auth.get();
if (!auth) {
if (config_has_user_value(main->Config(), "Auth", "Type")) {
config_remove_value(main->Config(), "Auth", "Type");
config_save_safe(main->Config(), "tmp", nullptr);
}
return;
}
config_set_string(main->Config(), "Auth", "Type", auth->service());
auth->SaveInternal();
config_save_safe(main->Config(), "tmp", nullptr);
}