Skip to main content

Angular

The Angular code of our domain.com/callback page

import { Component } from '@angular/core';
import axios from "axios";

const CONFIG = {
API_URL: "https://xxx.api.com",
CALLBACK_URL: "https://localhost:3000/callback",
};

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
})
export class AppComponent {
code: string = new URLSearchParams(window.location.href).get("code");
midentitytUser: Object = null;
loading: Boolean = false;

ngOnInit() {
this.authorize();
}

private async authorize() {
if(!this.code){
this.loading = true;
axios
.get(
CONFIG.API_URL +
"/auth/oidc?redirect_uri=" +
CONFIG.CALLBACK_URL
)
.then((response) => {
window.location.href = response.data.composed_url;
})
.catch((error) => {})
.finally(() => this.loading = false);
}else{
if(!this.midentitytUser){
this.loading = true;
axios
.post(CONFIG.API_URL + "/auth/code", {
code: this.code,
redirect_uri: CONFIG.CALLBACK_URL,
})
.then((response) => {
this.midentitytUser = response.data.user;
})
.catch((error) => {})
.finally(() => this.loading = false);
}else{
return
}
}
}
}


info