mirror of
https://github.com/MikroWizard/mikrofront.git
synced 2025-08-01 16:54:32 +02:00
login with apple and 365 done
This commit is contained in:
parent
d8ed8ce2ce
commit
9fbb3ad18a
6 changed files with 64 additions and 15 deletions
15
package-lock.json
generated
15
package-lock.json
generated
|
@ -42,6 +42,7 @@
|
||||||
"diff-match-patch-ts": "^0.6.0",
|
"diff-match-patch-ts": "^0.6.0",
|
||||||
"font-awesome": "^4.7.0",
|
"font-awesome": "^4.7.0",
|
||||||
"install": "^0.13.0",
|
"install": "^0.13.0",
|
||||||
|
"jwt-decode": "^4.0.0",
|
||||||
"lodash-es": "^4.17.21",
|
"lodash-es": "^4.17.21",
|
||||||
"mat-progress-buttons": "^9.3.1",
|
"mat-progress-buttons": "^9.3.1",
|
||||||
"ngx-cron-editor": "^0.8.1",
|
"ngx-cron-editor": "^0.8.1",
|
||||||
|
@ -8907,6 +8908,15 @@
|
||||||
"safe-buffer": "^5.0.1"
|
"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": {
|
"node_modules/karma": {
|
||||||
"version": "6.4.3",
|
"version": "6.4.3",
|
||||||
"resolved": "https://registry.npmjs.org/karma/-/karma-6.4.3.tgz",
|
"resolved": "https://registry.npmjs.org/karma/-/karma-6.4.3.tgz",
|
||||||
|
@ -20454,6 +20464,11 @@
|
||||||
"safe-buffer": "^5.0.1"
|
"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": {
|
"karma": {
|
||||||
"version": "6.4.3",
|
"version": "6.4.3",
|
||||||
"resolved": "https://registry.npmjs.org/karma/-/karma-6.4.3.tgz",
|
"resolved": "https://registry.npmjs.org/karma/-/karma-6.4.3.tgz",
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"ng": "ng",
|
"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",
|
"startnp": "ng serve --proxy-config=./proxy.conf.ts --host 0.0.0.0",
|
||||||
"build": "ng build",
|
"build": "ng build",
|
||||||
"watch": "ng build --watch --configuration development",
|
"watch": "ng build --watch --configuration development",
|
||||||
|
@ -52,6 +52,7 @@
|
||||||
"diff-match-patch-ts": "^0.6.0",
|
"diff-match-patch-ts": "^0.6.0",
|
||||||
"font-awesome": "^4.7.0",
|
"font-awesome": "^4.7.0",
|
||||||
"install": "^0.13.0",
|
"install": "^0.13.0",
|
||||||
|
"jwt-decode": "^4.0.0",
|
||||||
"lodash-es": "^4.17.21",
|
"lodash-es": "^4.17.21",
|
||||||
"mat-progress-buttons": "^9.3.1",
|
"mat-progress-buttons": "^9.3.1",
|
||||||
"ngx-cron-editor": "^0.8.1",
|
"ngx-cron-editor": "^0.8.1",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"/api": {
|
"/api": {
|
||||||
"target": "http://192.168.1.26:3000/",
|
"target": "http://localhost:3000",
|
||||||
"secure": false,
|
"secure": false,
|
||||||
"changeOrigin": true,
|
"changeOrigin": true,
|
||||||
"logLevel": "debug",
|
"logLevel": "debug",
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { User } from './user';
|
||||||
export class dataProvider {
|
export class dataProvider {
|
||||||
|
|
||||||
// public serverUrl: string = "/api";
|
// public serverUrl: string = "/api";
|
||||||
public serverUrl: string = "http://192.168.1.26:3000";
|
public serverUrl: string = "http://localhost:3000";
|
||||||
private db: string = "NothingImportant";
|
private db: string = "NothingImportant";
|
||||||
private apiUrl: string = "/api";
|
private apiUrl: string = "/api";
|
||||||
|
|
||||||
|
@ -652,12 +652,9 @@ export class dataProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async loginWithApple(appleResponse: any): Promise<any> {
|
async singSignonLoginForUser(data: any): Promise<any> {
|
||||||
try {
|
try {
|
||||||
const data = {
|
return this.MikroWizardRPC.sendJsonRequest("/api/single-signon/user/create", data);
|
||||||
appleResponse: appleResponse
|
|
||||||
};
|
|
||||||
return this.MikroWizardRPC.sendJsonRequest("/api/auth/apple", data);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import { MsalService } from '@azure/msal-angular';
|
||||||
import { loginRequest } from '../../../auth/msal-config';
|
import { loginRequest } from '../../../auth/msal-config';
|
||||||
import { appleConfig } from '../../../auth/apple-config';
|
import { appleConfig } from '../../../auth/apple-config';
|
||||||
import appleSignin from 'apple-signin-auth';
|
import appleSignin from 'apple-signin-auth';
|
||||||
|
import { MikroWizardUtils } from '../../../../components/utils/common-functions';
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
|
@ -35,6 +36,7 @@ export class LoginComponent implements OnInit {
|
||||||
private data_provider: dataProvider,
|
private data_provider: dataProvider,
|
||||||
private login_checker: loginChecker,
|
private login_checker: loginChecker,
|
||||||
private msalService: MsalService
|
private msalService: MsalService
|
||||||
|
|
||||||
) {
|
) {
|
||||||
this.createForm();
|
this.createForm();
|
||||||
};
|
};
|
||||||
|
@ -42,7 +44,7 @@ export class LoginComponent implements OnInit {
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
// Check if user is already logged in with MSAL
|
// Check if user is already logged in with MSAL
|
||||||
if (this.msalService.instance.getActiveAccount()) {
|
if (this.msalService.instance.getActiveAccount()) {
|
||||||
this.handleMsalLogin();
|
// this.handleMsalLogin();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize Apple Sign In
|
// Initialize Apple Sign In
|
||||||
|
@ -89,7 +91,8 @@ export class LoginComponent implements OnInit {
|
||||||
this.msalService.loginPopup(loginRequest)
|
this.msalService.loginPopup(loginRequest)
|
||||||
.subscribe({
|
.subscribe({
|
||||||
next: (result) => {
|
next: (result) => {
|
||||||
this.handleMsalLogin();
|
console.log(result)
|
||||||
|
this.handleMsalLogin(result?.account);
|
||||||
},
|
},
|
||||||
error: (error) => {
|
error: (error) => {
|
||||||
this.error_msg = "Error during Office 365 login: " + error.message;
|
this.error_msg = "Error during Office 365 login: " + error.message;
|
||||||
|
@ -98,10 +101,16 @@ export class LoginComponent implements OnInit {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleMsalLogin() {
|
private handleMsalLogin(request: any) {
|
||||||
const account = this.msalService.instance.getActiveAccount();
|
if (request) {
|
||||||
if (account) {
|
let data = {
|
||||||
this.data_provider.loginWithOffice365(account.idTokenClaims)
|
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 => {
|
.then(res => {
|
||||||
if ('uid' in res && res['uid']) {
|
if ('uid' in res && res['uid']) {
|
||||||
this.error_msg = "";
|
this.error_msg = "";
|
||||||
|
@ -152,7 +161,7 @@ export class LoginComponent implements OnInit {
|
||||||
|
|
||||||
private handleAppleLogin(response: any) {
|
private handleAppleLogin(response: any) {
|
||||||
console.log(JSON.stringify(response));
|
console.log(JSON.stringify(response));
|
||||||
this.data_provider.loginWithApple(response)
|
this.data_provider.singSignonLoginForUser(response)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
if ('uid' in res && res['uid']) {
|
if ('uid' in res && res['uid']) {
|
||||||
this.error_msg = "";
|
this.error_msg = "";
|
||||||
|
|
27
src/components/utils/common-functions.ts
Normal file
27
src/components/utils/common-functions.ts
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue