Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
LibKGAPI
Commits
69ae17e9
Verified
Commit
69ae17e9
authored
Sep 17, 2020
by
Daniel Vrátil
🤖
Browse files
Make it again possible to pass username to AuthJob
parent
d54f786a
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/core/accountmanager.cpp
View file @
69ae17e9
...
...
@@ -84,6 +84,7 @@ public:
account
->
setScopes
(
currentScopes
);
}
AuthJob
*
job
=
new
AuthJob
(
account
,
apiKey
,
apiSecret
);
job
->
setUsername
(
account
->
accountName
());
connect
(
job
,
&
AuthJob
::
finished
,
[
=
]()
{
if
(
job
->
error
()
!=
KGAPI2
::
NoError
)
{
...
...
src/core/authjob.cpp
View file @
69ae17e9
...
...
@@ -43,6 +43,7 @@ public:
AccountPtr
account
;
QString
apiKey
;
QString
secretKey
;
QString
username
;
private:
AuthJob
*
const
q
;
...
...
@@ -64,8 +65,9 @@ AccountPtr AuthJob::account() const
return
d
->
account
;
}
void
AuthJob
::
setUsername
(
const
QString
&
/*
username
*/
)
void
AuthJob
::
setUsername
(
const
QString
&
username
)
{
d
->
username
=
username
;
}
void
AuthJob
::
setPassword
(
const
QString
&
/*password*/
)
...
...
@@ -92,6 +94,7 @@ void AuthJob::start()
d
->
account
->
addScope
(
Account
::
accountInfoEmailScopeUrl
());
auto
*
job
=
new
FullAuthenticationJob
(
d
->
account
,
d
->
apiKey
,
d
->
secretKey
,
this
);
job
->
setUsername
(
d
->
username
);
job
->
setServerPort
(
kgapiTcpAuthServerPort
);
connect
(
job
,
&
Job
::
finished
,
this
,
[
this
](
Job
*
job
)
{
d
->
jobFinished
<
FullAuthenticationJob
>
(
job
);
});
}
else
{
...
...
src/core/authjob.h
View file @
69ae17e9
...
...
@@ -67,9 +67,7 @@ class KGAPICORE_EXPORT AuthJob : public KGAPI2::Job
* Sets the username that will be used when authenticate is called
*
* @param username username to use
* @deprecated
*/
QT_DEPRECATED_X
(
"It's no longer possible to prefill username"
)
void
setUsername
(
const
QString
&
username
);
/**
...
...
src/core/private/fullauthenticationjob.cpp
View file @
69ae17e9
...
...
@@ -56,7 +56,15 @@ public:
{
Q_ASSERT
(
mConnection
);
const
QByteArray
data
=
mConnection
->
readLine
();
mConnection
->
write
(
"HTTP/1.1 200 OK
\n
"
);
const
QString
title
=
tr
(
"Authentication successful"
);
const
QString
text
=
tr
(
"You can close this tab and return to the application now."
);
mConnection
->
write
(
"HTTP/1.1 200 OK
\n
"
"Content-Type: text/html
\n
"
"
\n
"
"<!DOCTYPE><html>"
"<head><title>"
+
title
.
toUtf8
()
+
"</title></head>"
"<body><h1>"
+
text
.
toUtf8
()
+
"</h1></body>"
"</html>
\n
"
);
mConnection
->
flush
();
mConnection
->
deleteLater
();
qCDebug
(
KGAPIDebug
)
<<
"Got connection on socket"
;
...
...
@@ -84,7 +92,6 @@ public:
return
;
}
Q_ASSERT
(
mServerPort
!=
-
1
);
auto
fetch
=
new
KGAPI2
::
NewTokensFetchJob
(
code
,
mApiKey
,
mSecretKey
,
mServerPort
);
q
->
connect
(
fetch
,
&
Job
::
finished
,
q
,
[
this
](
Job
*
job
)
{
tokensReceived
(
job
);
});
}
...
...
@@ -131,6 +138,7 @@ public:
AccountPtr
mAccount
;
QString
mApiKey
;
QString
mSecretKey
;
QString
mUsername
;
std
::
unique_ptr
<
QTcpServer
>
mServer
;
QTcpSocket
*
mConnection
=
nullptr
;
...
...
@@ -155,6 +163,11 @@ void FullAuthenticationJob::setServerPort(uint16_t port)
d
->
mServerPort
=
port
;
}
void
FullAuthenticationJob
::
setUsername
(
const
QString
&
username
)
{
d
->
mUsername
=
username
;
}
AccountPtr
FullAuthenticationJob
::
account
()
const
{
return
d
->
mAccount
;
...
...
@@ -205,6 +218,9 @@ void FullAuthenticationJob::start()
query
.
addQueryItem
(
QStringLiteral
(
"redirect_uri"
),
QStringLiteral
(
"http://127.0.0.1:%1"
).
arg
(
d
->
mServerPort
));
query
.
addQueryItem
(
QStringLiteral
(
"scope"
),
scopes
.
join
(
QLatin1Char
(
' '
)));
query
.
addQueryItem
(
QStringLiteral
(
"response_type"
),
QStringLiteral
(
"code"
));
if
(
!
d
->
mUsername
.
isEmpty
())
{
query
.
addQueryItem
(
QStringLiteral
(
"login_hint"
),
d
->
mUsername
);
}
url
.
setQuery
(
query
);
QDesktopServices
::
openUrl
(
url
);
...
...
src/core/private/fullauthenticationjob_p.h
View file @
69ae17e9
...
...
@@ -28,6 +28,8 @@ public:
/** For testing purposes only */
void
setServerPort
(
uint16_t
port
);
void
setUsername
(
const
QString
&
username
);
protected:
void
handleReply
(
const
QNetworkReply
*
reply
,
const
QByteArray
&
rawData
)
override
;
void
dispatchRequest
(
QNetworkAccessManager
*
accessManager
,
const
QNetworkRequest
&
request
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment