login with apple and 365 done

This commit is contained in:
divyesh 2025-07-04 22:39:01 +05:30
parent d8ed8ce2ce
commit 9fbb3ad18a
6 changed files with 64 additions and 15 deletions

15
package-lock.json generated
View file

@ -42,6 +42,7 @@
"diff-match-patch-ts": "^0.6.0",
"font-awesome": "^4.7.0",
"install": "^0.13.0",
"jwt-decode": "^4.0.0",
"lodash-es": "^4.17.21",
"mat-progress-buttons": "^9.3.1",
"ngx-cron-editor": "^0.8.1",
@ -8907,6 +8908,15 @@
"safe-buffer": "^5.0.1"
}
},
"node_modules/jwt-decode": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-4.0.0.tgz",
"integrity": "sha512-+KJGIyHgkGuIq3IEBNftfhW/LfWhXUIY6OmyVWjliu5KH1y0fw7VQ8YndE2O4qZdMSd9SqbnC8GOcZEy0Om7sA==",
"license": "MIT",
"engines": {
"node": ">=18"
}
},
"node_modules/karma": {
"version": "6.4.3",
"resolved": "https://registry.npmjs.org/karma/-/karma-6.4.3.tgz",
@ -20454,6 +20464,11 @@
"safe-buffer": "^5.0.1"
}
},
"jwt-decode": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-4.0.0.tgz",
"integrity": "sha512-+KJGIyHgkGuIq3IEBNftfhW/LfWhXUIY6OmyVWjliu5KH1y0fw7VQ8YndE2O4qZdMSd9SqbnC8GOcZEy0Om7sA=="
},
"karma": {
"version": "6.4.3",
"resolved": "https://registry.npmjs.org/karma/-/karma-6.4.3.tgz",

View file

@ -11,7 +11,7 @@
},
"scripts": {
"ng": "ng",
"start": "ng serve --host 0.0.0.0 --port 4200 --disable-host-check",
"start": "ng serve --proxy-config proxy.conf.json",
"startnp": "ng serve --proxy-config=./proxy.conf.ts --host 0.0.0.0",
"build": "ng build",
"watch": "ng build --watch --configuration development",
@ -52,6 +52,7 @@
"diff-match-patch-ts": "^0.6.0",
"font-awesome": "^4.7.0",
"install": "^0.13.0",
"jwt-decode": "^4.0.0",
"lodash-es": "^4.17.21",
"mat-progress-buttons": "^9.3.1",
"ngx-cron-editor": "^0.8.1",

View file

@ -1,6 +1,6 @@
{
"/api": {
"target": "http://192.168.1.26:3000/",
"target": "http://localhost:3000",
"secure": false,
"changeOrigin": true,
"logLevel": "debug",

View file

@ -10,7 +10,7 @@ import { User } from './user';
export class dataProvider {
// public serverUrl: string = "/api";
public serverUrl: string = "http://192.168.1.26:3000";
public serverUrl: string = "http://localhost:3000";
private db: string = "NothingImportant";
private apiUrl: string = "/api";
@ -652,12 +652,9 @@ export class dataProvider {
}
}
async loginWithApple(appleResponse: any): Promise<any> {
async singSignonLoginForUser(data: any): Promise<any> {
try {
const data = {
appleResponse: appleResponse
};
return this.MikroWizardRPC.sendJsonRequest("/api/auth/apple", data);
return this.MikroWizardRPC.sendJsonRequest("/api/single-signon/user/create", data);
} catch (error) {
throw error;
}

View file

@ -7,6 +7,7 @@ import { MsalService } from '@azure/msal-angular';
import { loginRequest } from '../../../auth/msal-config';
import { appleConfig } from '../../../auth/apple-config';
import appleSignin from 'apple-signin-auth';
import { MikroWizardUtils } from '../../../../components/utils/common-functions';
declare global {
interface Window {
@ -35,6 +36,7 @@ export class LoginComponent implements OnInit {
private data_provider: dataProvider,
private login_checker: loginChecker,
private msalService: MsalService
) {
this.createForm();
};
@ -42,7 +44,7 @@ export class LoginComponent implements OnInit {
ngOnInit() {
// Check if user is already logged in with MSAL
if (this.msalService.instance.getActiveAccount()) {
this.handleMsalLogin();
// this.handleMsalLogin();
}
// Initialize Apple Sign In
@ -89,7 +91,8 @@ export class LoginComponent implements OnInit {
this.msalService.loginPopup(loginRequest)
.subscribe({
next: (result) => {
this.handleMsalLogin();
console.log(result)
this.handleMsalLogin(result?.account);
},
error: (error) => {
this.error_msg = "Error during Office 365 login: " + error.message;
@ -98,10 +101,16 @@ export class LoginComponent implements OnInit {
});
}
private handleMsalLogin() {
const account = this.msalService.instance.getActiveAccount();
if (account) {
this.data_provider.loginWithOffice365(account.idTokenClaims)
private handleMsalLogin(request: any) {
if (request) {
let data = {
email:request?.username,
username:request?.username,
first_name:request?.name?.split(" ")[0],
last_name:request?.name?.split(" ")[1]
}
console.log(">>>>>>>>>>>>>>> data from token >>>>>>", data)
this.data_provider.singSignonLoginForUser(data)
.then(res => {
if ('uid' in res && res['uid']) {
this.error_msg = "";
@ -152,7 +161,7 @@ export class LoginComponent implements OnInit {
private handleAppleLogin(response: any) {
console.log(JSON.stringify(response));
this.data_provider.loginWithApple(response)
this.data_provider.singSignonLoginForUser(response)
.then(res => {
if ('uid' in res && res['uid']) {
this.error_msg = "";

View file

@ -0,0 +1,27 @@
// your.component.ts or service.ts
import { Injectable } from '@angular/core';
import {jwtDecode} from 'jwt-decode';
interface JwtPayload {
// Define keys you expect from the JWT payload
sub?: string;
name?: string;
email?: string;
exp?: number;
[key: string]: any; // to allow additional keys
}
export class MikroWizardUtils {
public static decodeJWT(token: any) {
try {
const decoded = jwtDecode<JwtPayload>(token);
console.log('Decoded JWT:', decoded);
console.log('User email:', decoded['unique_name']);
return decoded;
} catch (error) {
console.error('Invalid JWT token:', error);
return null;
}
}
}