Added connections. Added url redirect for login.

This commit is contained in:
Tom
2025-03-27 01:25:56 +00:00
parent 56deb3384c
commit 6e5efab5ec
36 changed files with 948 additions and 39 deletions

View File

@ -0,0 +1,48 @@
import { Component, inject, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { HermesClientService } from '../../hermes-client.service';
import { HttpClient } from '@angular/common/http';
@Component({
selector: 'connection-callback',
imports: [],
templateUrl: './callback.component.html',
styleUrl: './callback.component.scss'
})
export class ConnectionCallbackComponent implements OnInit {
private readonly client = inject(HermesClientService);
private readonly http = inject(HttpClient);
private readonly router = inject(Router);
success: boolean = false;
failure: boolean = false;
async ngOnInit() {
const url = this.router.parseUrl(this.router.url);
if (!url.fragment) {
this.failure = true;
await this.router.navigate(['connections']);
return;
}
const paramsParts = url.fragment.split('&');
const params = Object.assign({}, ...paramsParts.map((p: string) => ({ [p.split('=')[0]]: p.split('=')[1] })));
if (!params.access_token || !params.scope || !params.state || !params.token_type) {
this.failure = true;
await this.router.navigate(['connections']);
return;
}
this.http.get(`https://beta.tomtospeech.com/api/auth/connections?token=${params['access_token']}&state=${params['state']}&expires_in=${params['expires_in']}`).subscribe(async (d: any) => {
const data = d.data;
this.success = true;
await setTimeout(async () => {
this.client.createConnection(data.connection.name, data.connection.type, data.connection.clientId, params['access_token'], data.connection.grantType, params['scope'], data.expires_at);
await this.router.navigate(['connections']);
}, 2000)
});
;
}
}