Skip to content
Snippets Groups Projects
Commit d94042b2 authored by Christian ZHENG's avatar Christian ZHENG
Browse files

fix(login): fix some side use cases & refactor logging

parent 32b114ec
No related branches found
No related tags found
2 merge requests!14feat: added mounted, .bashrc, .zshrc, added tests, added keycloak tests,!8feat(extension): login, open in devcontainer, automaticly save code, open briefing, publish extension
......@@ -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;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment