From 4d5e50edb9fc2c91f0f221e9d0632a1c6055ffc6 Mon Sep 17 00:00:00 2001 From: Christian Zheng <czheng@takima.fr> Date: Thu, 7 Apr 2022 13:39:50 +0200 Subject: [PATCH] refactor(login): rewrite test class --- ...keycloakOAuth2DeviceFlowConnection.test.ts | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/deadlock-plugins/deadlock-extension/src/core/keycloakOAuth2DeviceFlowConnection.test.ts b/deadlock-plugins/deadlock-extension/src/core/keycloakOAuth2DeviceFlowConnection.test.ts index 9fc4ee91..f845dc54 100644 --- a/deadlock-plugins/deadlock-extension/src/core/keycloakOAuth2DeviceFlowConnection.test.ts +++ b/deadlock-plugins/deadlock-extension/src/core/keycloakOAuth2DeviceFlowConnection.test.ts @@ -1,12 +1,42 @@ +import { log } from 'recorder/utils'; import KeycloakOAuth2DeviceFlowConnection from './keycloakOAuth2DeviceFlowConnection'; +/** + * Maybe temporary file ?\ + * This class shows how to use KeycloakOAuth2DeviceFlowConnection.\ + * It is currently based on dev.deadlock instance\ + * but there are only some urls to change for further testings. + * + */ export default class KeycloakOAuth2DeviceFlowConnectionTest { public connection: KeycloakOAuth2DeviceFlowConnection; constructor() { + log(' --- KeycloakOAuth2DeviceFlowConnectionTest --- '); this.connection = new KeycloakOAuth2DeviceFlowConnection( 'https://auth.dev.deadlock.io/auth/realms/Deadlock/protocol/openid-connect/auth/device', 'https://auth.dev.deadlock.io/auth/realms/Deadlock/protocol/openid-connect/token', ); } - public run(): void {} + + /** + * Simple working examples + */ + public async run() { + const openLinkPlaceholder = (link: string) => { + log(`click here: ${link}`); + }; + + let tokens = await this.connection.getToken({ openLink: openLinkPlaceholder }); + console.log('tokens', tokens); + if (!tokens?.refreshToken) { + console.log("refresh token doesn't exist"); + return; + } + + let refreshedTokens = await this.connection.getToken({ + refreshToken: tokens.refreshToken, + openLink: openLinkPlaceholder, + }); + console.log('refreshed tokens', refreshedTokens); + } } -- GitLab