diff --git a/deadlock-plugins/deadlock-extension/src/core/keycloakOAuth2DeviceFlowConnection.test.ts b/deadlock-plugins/deadlock-extension/src/core/keycloakOAuth2DeviceFlowConnection.test.ts index 9fc4ee9197306227403f301ea83876b901b7d5f9..f845dc543be0074c135d6eb8673d8e2166467a1b 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); + } }