Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
deadlock-desktop
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
deadlock-public
deadlock-desktop
Commits
d94042b2
Commit
d94042b2
authored
Apr 7, 2022
by
Christian ZHENG
Browse files
Options
Downloads
Patches
Plain Diff
fix(login): fix some side use cases & refactor logging
parent
32b114ec
No related branches found
No related tags found
2 merge requests
!14
feat: added mounted, .bashrc, .zshrc, added tests, added keycloak tests
,
!8
feat(extension): login, open in devcontainer, automaticly save code, open briefing, publish extension
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
deadlock-plugins/deadlock-extension/src/core/keycloakOAuth2DeviceFlowConnection.ts
+7
-11
7 additions, 11 deletions
...-extension/src/core/keycloakOAuth2DeviceFlowConnection.ts
with
7 additions
and
11 deletions
deadlock-plugins/deadlock-extension/src/core/keycloakOAuth2DeviceFlowConnection.ts
+
7
−
11
View file @
d94042b2
...
...
@@ -21,7 +21,7 @@ export default class KeycloakOAuth2DeviceFlowConnection {
public
async
getToken
(
args
:
{
refreshToken
?:
string
;
openLink
:
(
link
:
string
)
=>
void
})
{
const
{
refreshToken
,
openLink
}
=
args
;
if
(
refreshToken
)
{
if
(
!!
refreshToken
)
{
await
this
.
createUserAuthentication
({
url
:
this
.
_tokenUrl
,
body
:
(()
=>
{
...
...
@@ -36,7 +36,6 @@ export default class KeycloakOAuth2DeviceFlowConnection {
return
Promise
.
resolve
({
accessToken
:
this
.
_accessToken
,
refreshToken
:
this
.
_refreshToken
});
}
if
(
!
this
.
_deviceIsRegistered
())
{
console
.
log
(
'
--- device not registered
'
);
await
this
.
_registerDevice
();
}
try
{
...
...
@@ -52,12 +51,10 @@ export default class KeycloakOAuth2DeviceFlowConnection {
return
params
.
toString
();
})(),
});
console
.
log
(
'
access token:
'
,
this
.
_accessToken
);
console
.
log
(
'
refresh token:
'
,
this
.
_refreshToken
);
Promise
.
resolve
({
accessToken
:
this
.
_accessToken
,
refreshToken
:
this
.
_refreshToken
});
return
Promise
.
resolve
({
accessToken
:
this
.
_accessToken
,
refreshToken
:
this
.
_refreshToken
});
}
catch
(
error
:
any
)
{
err
(
error
);
Promise
.
reject
(
error
);
return
Promise
.
reject
(
error
);
}
}
...
...
@@ -66,6 +63,7 @@ export default class KeycloakOAuth2DeviceFlowConnection {
}
private
async
_registerDevice
()
{
log
(
'
Device not registered. Registering ...
'
);
const
deviceAuthorizationRequestResponse
:
Response
=
await
this
.
createDeviceAuthorization
({
url
:
this
.
_deviceUrl
,
body
:
(()
=>
{
...
...
@@ -76,11 +74,11 @@ export default class KeycloakOAuth2DeviceFlowConnection {
});
this
.
_deviceAuthorizationRequestResponseData
=
(
await
deviceAuthorizationRequestResponse
.
json
())
as
DeviceAuthorizationRequestResponseData
;
console
.
log
(
'
DeviceAuthorizationRequestResponseData
'
,
this
.
_deviceAuthorizationRequestResponseData
);
}
private
async
createDeviceAuthorization
(
args
:
{
url
:
string
;
body
:
string
}):
Promise
<
Response
>
{
const
{
url
,
body
}
=
args
;
log
(
`[POST]
${
url
}
\n
${
body
}
`
);
return
fetch
(
url
,
{
method
:
'
POST
'
,
headers
:
{
...
...
@@ -100,6 +98,7 @@ export default class KeycloakOAuth2DeviceFlowConnection {
const
{
url
,
body
}
=
args
;
let
userAuthenticationRequestResponseCode
=
HttpStatusCode
.
I_AM_A_TEAPOT
;
while
(
userAuthenticationRequestResponseCode
!==
HttpStatusCode
.
OK
)
{
log
(
`[POST]
${
url
}
\n
${
body
}
`
);
const
userAuthenticationRequestResponse
:
Response
=
await
fetch
(
url
,
{
method
:
'
POST
'
,
headers
:
{
...
...
@@ -114,8 +113,7 @@ export default class KeycloakOAuth2DeviceFlowConnection {
{
const
badRequestResponse
=
(
await
userAuthenticationRequestResponse
.
json
())
as
FailedAuthenticationReponseData
;
log
(
badRequestResponse
.
error_description
);
log
(
badRequestResponse
.
error
!
);
log
(
`
${
badRequestResponse
.
error
!
}
:
${
badRequestResponse
.
error_description
}
`
);
const
errorCode
=
TokenFetchErrorCode
[
badRequestResponse
.
error
!
];
switch
(
errorCode
)
{
case
TokenFetchErrorCode
.
invalid_client
:
...
...
@@ -144,7 +142,6 @@ export default class KeycloakOAuth2DeviceFlowConnection {
(
await
userAuthenticationRequestResponse
.
json
())
as
SuccessfulAuthenticationResponseData
;
this
.
_accessToken
=
successRequestResponse
.
access_token
??
''
;
this
.
_refreshToken
=
successRequestResponse
.
refresh_token
??
''
;
console
.
log
(
successRequestResponse
);
break
;
}
default
:
{
...
...
@@ -210,7 +207,6 @@ class WaitDuration {
}
public
increase
():
void
{
if
(
this
.
_index
<
this
.
_durations
.
length
-
1
)
{
console
.
log
(
'
index
'
,
this
.
_index
);
this
.
_index
+=
1
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment