Commit 0c98f7a6 authored by Emiliano Balbuena's avatar Emiliano Balbuena

(feat): SSO flow upon page initialization

1 merge request!656WIP: SSO for Pro sites
Pipeline #96000549 running with stages
import { Injectable } from '@angular/core';
import { SiteService } from './site.service';
import { Client } from '../../services/api/client';
import { Session } from '../../services/session';
@Injectable()
export class SsoService {
protected readonly minds = window.Minds;
constructor(protected site: SiteService, protected client: Client) {}
constructor(
protected site: SiteService,
protected client: Client,
protected session: Session
) {}
isRequired(): boolean {
return this.site.isProDomain;
......@@ -14,9 +19,22 @@ export class SsoService {
async connect() {
try {
const response: any = await this.client.postRaw(
const connect: any = await this.client.postRaw(
`${this.minds.site_url}api/v2/sso/connect`
);
if (connect && connect.status === 'success') {
// TODO: Use headers
const authorization: any = await this.client.post(
'api/v2/sso/authorize',
{
token: connect.token,
}
);
window.Minds.user = authorization.user;
this.session.login(window.Minds.user);
}
} catch (e) {
console.error(e);
}
......
Please register or to comment