Jellyfin Qt
QML Library for interacting with the Jellyfin multimedia server
Loading...
Searching...
No Matches
credentialmanager.h
Go to the documentation of this file.
1/*
2Sailfin: a Jellyfin client written using Qt
3Copyright (C) 2021 Chris Josten
4
5This library is free software; you can redistribute it and/or
6modify it under the terms of the GNU Lesser General Public
7License as published by the Free Software Foundation; either
8version 2.1 of the License, or (at your option) any later version.
9
10This library is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13Lesser General Public License for more details.
14
15You should have received a copy of the GNU Lesser General Public
16License along with this library; if not, write to the Free Software
17Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*/
19
20#ifndef CREDENTIALS_MANAGER_H
21#define CREDENTIALS_MANAGER_H
22
23#include <QDebug>
24#include <QHash>
25#include <QObject>
26#include <QSettings>
27#include <QString>
28
36class CredentialsManager : public QObject {
37 Q_OBJECT
38public:
45 virtual void store(const QString &server, const QString &user, const QString &token) {
46 Q_UNUSED(server)
47 Q_UNUSED(user)
48 Q_UNUSED(token)
49 Q_UNIMPLEMENTED();
50 }
56 virtual void get(const QString &server, const QString &user) const {
57 Q_UNUSED(server)
58 Q_UNUSED(user)
59 Q_UNIMPLEMENTED();
60 }
61
67 virtual void remove(const QString &server, const QString &user) {
68 Q_UNUSED(server)
69 Q_UNUSED(user)
70 Q_UNIMPLEMENTED();
71 }
72
76 virtual void listServers() const { Q_UNIMPLEMENTED(); }
77
82 virtual void listUsers(const QString &server) {
83 Q_UNUSED(server)
84 Q_UNIMPLEMENTED();
85 }
86
94 static CredentialsManager *newInstance(QObject *parent = nullptr);
95
99 virtual bool isSecure() const { return false; }
100
101signals:
102 void tokenRetrieved(const QString &server, const QString &user, const QString &token) const;
103 void serversListed(const QStringList &servers) const;
104 void usersListed(const QString& server, const QStringList &users) const;
105
106protected:
107 explicit CredentialsManager(QObject *parent = nullptr) : QObject (parent) {}
108};
109
114 Q_OBJECT
115public:
116 FallbackCredentialsManager(QObject *parent = nullptr);
117 void store(const QString &server, const QString &user, const QString &token) override;
118 void get(const QString &server, const QString &user) const override;
119 void remove(const QString &server, const QString &user) override;
120 void listServers() const override;
121 void listUsers(const QString &server) override;
122 bool isSecure() const override { return false; }
123
124private:
125 QString urlToGroupName(const QString &url) const;
126 QSettings m_settings;
127};
128
129#endif // CREDENTIAL_MANAGER_H
The CredentialsManager class stores credentials for users.
Definition credentialmanager.h:36
virtual void listServers() const
Gives the list of servers that have a user stored with a token.
Definition credentialmanager.h:76
void tokenRetrieved(const QString &server, const QString &user, const QString &token) const
void usersListed(const QString &server, const QStringList &users) const
virtual void get(const QString &server, const QString &user) const
Retrieves a stored token. Emits tokenRetrieved when the token is retrieved.
Definition credentialmanager.h:56
virtual void remove(const QString &server, const QString &user)
removes a token
Definition credentialmanager.h:67
virtual void store(const QString &server, const QString &user, const QString &token)
Stores a token.
Definition credentialmanager.h:45
virtual bool isSecure() const
Definition credentialmanager.h:99
CredentialsManager(QObject *parent=nullptr)
Definition credentialmanager.h:107
static CredentialsManager * newInstance(QObject *parent=nullptr)
Retrieves an implementation which can store this token.
Definition credentialmanager.cpp:22
virtual void listUsers(const QString &server)
List the users with a token on a server.
Definition credentialmanager.h:82
void serversListed(const QStringList &servers) const
Implementation of CredentialsManager that stores credentials in plain-text.
Definition credentialmanager.h:113
void get(const QString &server, const QString &user) const override
Retrieves a stored token. Emits tokenRetrieved when the token is retrieved.
Definition credentialmanager.cpp:50
void remove(const QString &server, const QString &user) override
removes a token
Definition credentialmanager.cpp:55
void listServers() const override
Gives the list of servers that have a user stored with a token.
Definition credentialmanager.cpp:67
void listUsers(const QString &server) override
List the users with a token on a server.
Definition credentialmanager.cpp:78
void store(const QString &server, const QString &user, const QString &token) override
Stores a token.
Definition credentialmanager.cpp:45
bool isSecure() const override
Definition credentialmanager.h:122
FallbackCredentialsManager(QObject *parent=nullptr)
Definition credentialmanager.cpp:29