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
af4d4a7a
Commit
af4d4a7a
authored
Apr 6, 2022
by
Christian ZHENG
Browse files
Options
Downloads
Patches
Plain Diff
chore(login): format
parent
b226fa1d
Branches
Branches containing commit
Tags
Tags containing commit
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
+38
-34
38 additions, 34 deletions
...-extension/src/core/keycloakOAuth2DeviceFlowConnection.ts
with
38 additions
and
34 deletions
deadlock-plugins/deadlock-extension/src/core/keycloakOAuth2DeviceFlowConnection.ts
+
38
−
34
View file @
af4d4a7a
...
@@ -11,13 +11,48 @@ export default class OAuth2DeviceFlowConnection {
...
@@ -11,13 +11,48 @@ export default class OAuth2DeviceFlowConnection {
private
_accessToken
:
string
;
private
_accessToken
:
string
;
private
_refreshToken
:
string
;
private
_refreshToken
:
string
;
private
_deviceAuthorizationRequestResponseData
:
DeviceAuthorizationRequestResponseData
;
private
_deviceAuthorizationRequestResponseData
:
DeviceAuthorizationRequestResponseData
;
constructor
()
{
constructor
()
{
this
.
_waitDuration
=
new
WaitDuration
([
5
_000
,
5
_000
,
5
_000
,
10
_000
,
10
_000
,
10
_000
,
30
_000
,
30
_000
,
100
_000
]);
this
.
_waitDuration
=
new
WaitDuration
([
5
_000
,
5
_000
,
5
_000
,
10
_000
,
10
_000
,
10
_000
,
30
_000
,
30
_000
,
100
_000
]);
this
.
_accessToken
=
''
;
this
.
_accessToken
=
''
;
this
.
_refreshToken
=
''
;
this
.
_refreshToken
=
''
;
this
.
_deviceAuthorizationRequestResponseData
=
{};
this
.
_deviceAuthorizationRequestResponseData
=
{};
}
}
async
createDeviceAuthorization
(
args
:
{
url
:
string
;
body
:
string
}):
Promise
<
Response
>
{
public
async
start
()
{
const
deviceAuthorizationRequestResponse
:
Response
=
await
this
.
createDeviceAuthorization
({
url
:
'
https://auth.dev.deadlock.io/auth/realms/Deadlock/protocol/openid-connect/auth/device
'
,
body
:
(()
=>
{
const
params
=
new
URLSearchParams
();
params
.
append
(
'
client_id
'
,
'
deadlock-desktop
'
);
return
params
.
toString
();
})(),
});
this
.
_deviceAuthorizationRequestResponseData
=
(
await
deviceAuthorizationRequestResponse
.
json
())
as
DeviceAuthorizationRequestResponseData
;
console
.
log
(
this
.
_deviceAuthorizationRequestResponseData
);
try
{
await
this
.
createUserAuthentication
({
url
:
'
https://auth.dev.deadlock.io/auth/realms/Deadlock/protocol/openid-connect/token
'
,
body
:
(()
=>
{
const
params
=
new
URLSearchParams
();
params
.
append
(
'
response_type
'
,
'
token
'
);
params
.
append
(
'
device_code
'
,
this
.
_deviceAuthorizationRequestResponseData
.
device_code
??
''
);
params
.
append
(
'
grant_type
'
,
'
urn:ietf:params:oauth:grant-type:device_code
'
);
params
.
append
(
'
client_id
'
,
'
deadlock-desktop
'
);
console
.
log
(
'
token query body:
'
,
params
.
toString
());
return
params
.
toString
();
})(),
});
console
.
log
(
'
access token:
'
,
this
.
_accessToken
);
console
.
log
(
'
refresh token:
'
,
this
.
_refreshToken
);
}
catch
(
error
:
any
)
{
err
(
error
);
return
;
}
}
private
async
createDeviceAuthorization
(
args
:
{
url
:
string
;
body
:
string
}):
Promise
<
Response
>
{
const
{
url
,
body
}
=
args
;
const
{
url
,
body
}
=
args
;
return
fetch
(
url
,
{
return
fetch
(
url
,
{
method
:
'
POST
'
,
method
:
'
POST
'
,
...
@@ -28,12 +63,13 @@ export default class OAuth2DeviceFlowConnection {
...
@@ -28,12 +63,13 @@ export default class OAuth2DeviceFlowConnection {
agent
:
new
https
.
Agent
({
rejectUnauthorized
:
false
}),
// TODO: remove when SSL will work
agent
:
new
https
.
Agent
({
rejectUnauthorized
:
false
}),
// TODO: remove when SSL will work
});
});
}
}
/**
/**
*
*
* @param args API URL endpoint to ask for a new token & request form parameters
* @param args API URL endpoint to ask for a new token & request form parameters
* @throw Error containing Keycloak API error_code
* @throw Error containing Keycloak API error_code
*/
*/
async
createUserAuthentication
(
args
:
{
url
:
string
;
body
:
string
})
{
private
async
createUserAuthentication
(
args
:
{
url
:
string
;
body
:
string
})
{
const
{
url
,
body
}
=
args
;
const
{
url
,
body
}
=
args
;
let
userAuthenticationRequestResponseCode
=
HttpStatusCode
.
I_AM_A_TEAPOT
;
let
userAuthenticationRequestResponseCode
=
HttpStatusCode
.
I_AM_A_TEAPOT
;
while
(
userAuthenticationRequestResponseCode
!==
HttpStatusCode
.
OK
)
{
while
(
userAuthenticationRequestResponseCode
!==
HttpStatusCode
.
OK
)
{
...
@@ -90,38 +126,6 @@ export default class OAuth2DeviceFlowConnection {
...
@@ -90,38 +126,6 @@ export default class OAuth2DeviceFlowConnection {
}
}
}
}
}
}
async
start
()
{
const
deviceAuthorizationRequestResponse
:
Response
=
await
this
.
createDeviceAuthorization
({
url
:
'
https://auth.dev.deadlock.io/auth/realms/Deadlock/protocol/openid-connect/auth/device
'
,
body
:
(()
=>
{
const
params
=
new
URLSearchParams
();
params
.
append
(
'
client_id
'
,
'
deadlock-desktop
'
);
return
params
.
toString
();
})(),
});
this
.
_deviceAuthorizationRequestResponseData
=
(
await
deviceAuthorizationRequestResponse
.
json
())
as
DeviceAuthorizationRequestResponseData
;
console
.
log
(
this
.
_deviceAuthorizationRequestResponseData
);
try
{
await
this
.
createUserAuthentication
({
url
:
'
https://auth.dev.deadlock.io/auth/realms/Deadlock/protocol/openid-connect/token
'
,
body
:
(()
=>
{
const
params
=
new
URLSearchParams
();
params
.
append
(
'
response_type
'
,
'
token
'
);
params
.
append
(
'
device_code
'
,
this
.
_deviceAuthorizationRequestResponseData
.
device_code
??
''
);
params
.
append
(
'
grant_type
'
,
'
urn:ietf:params:oauth:grant-type:device_code
'
);
params
.
append
(
'
client_id
'
,
'
deadlock-desktop
'
);
console
.
log
(
'
token query body:
'
,
params
.
toString
());
return
params
.
toString
();
})(),
});
console
.
log
(
'
access token:
'
,
this
.
_accessToken
);
console
.
log
(
'
refresh token:
'
,
this
.
_refreshToken
);
}
catch
(
error
:
any
)
{
err
(
error
);
return
;
}
}
}
}
export
interface
DeviceAuthorizationRequestResponseData
{
export
interface
DeviceAuthorizationRequestResponseData
{
...
...
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