diff --git a/android/app/capacitor.build.gradle b/android/app/capacitor.build.gradle index 6692e26..0fcb2b3 100755 --- a/android/app/capacitor.build.gradle +++ b/android/app/capacitor.build.gradle @@ -17,6 +17,7 @@ dependencies { implementation project(':capacitor-keyboard') implementation project(':capacitor-preferences') implementation project(':capacitor-status-bar') + implementation project(':codetrix-studio-capacitor-google-auth') implementation "com.onesignal:OneSignal:5.0.0-beta4" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10" } diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml index d00ba1a..db53c9c 100755 --- a/android/app/src/main/res/values/strings.xml +++ b/android/app/src/main/res/values/strings.xml @@ -6,4 +6,5 @@ com.wrenchboard.users 390204307987009 70e8f7ea883417e96f137e0bd025bfce + 817021856543-ad9nsjgdpsu2s2jrl63j3ihrv7lbf6ma.apps.googleusercontent.com diff --git a/android/capacitor.settings.gradle b/android/capacitor.settings.gradle index 40f6acc..7499601 100755 --- a/android/capacitor.settings.gradle +++ b/android/capacitor.settings.gradle @@ -25,3 +25,6 @@ project(':capacitor-preferences').projectDir = new File('../node_modules/@capaci include ':capacitor-status-bar' project(':capacitor-status-bar').projectDir = new File('../node_modules/@capacitor/status-bar/android') + +include ':codetrix-studio-capacitor-google-auth' +project(':codetrix-studio-capacitor-google-auth').projectDir = new File('../node_modules/@codetrix-studio/capacitor-google-auth/android') diff --git a/capacitor.config.json b/capacitor.config.json new file mode 100644 index 0000000..8991d40 --- /dev/null +++ b/capacitor.config.json @@ -0,0 +1,14 @@ +{ + "appId": "com.wrenchboard.users", + "appName": "WrenchBoard", + "webDir": "www", + "bundledWebRuntime": false, + "plugins": { + "GoogleAuth": { + "scopes": ["profile","email"], + "clientId": "817021856543-ad9nsjgdpsu2s2jrl63j3ihrv7lbf6ma.apps.googleusercontent.com", + "serverClientId": "817021856543-ad9nsjgdpsu2s2jrl63j3ihrv7lbf6ma.apps.googleusercontent.com", + "forceCodeForRefreshToken": true + } + } +} diff --git a/capacitor.config.ts b/capacitor.config.ts index 345df4a..9742e59 100644 --- a/capacitor.config.ts +++ b/capacitor.config.ts @@ -4,7 +4,15 @@ const config: CapacitorConfig = { appId: 'com.wrenchboard.users', appName: 'WrenchBoard', webDir: 'www', - bundledWebRuntime: false + bundledWebRuntime: false, + plugins: { + GoogleAuth: { + scopes: ['profile', 'email'], + clientId: '817021856543-ad9nsjgdpsu2s2jrl63j3ihrv7lbf6ma.apps.googleusercontent.com', + serverClientId: '817021856543-ad9nsjgdpsu2s2jrl63j3ihrv7lbf6ma.apps.googleusercontent.com', + forceCodeForRefreshToken: true, + }, + }, }; export default config; diff --git a/ios/App/App/Info.plist b/ios/App/App/Info.plist index 1b3bd80..8e7c3f8 100644 --- a/ios/App/App/Info.plist +++ b/ios/App/App/Info.plist @@ -2,8 +2,6 @@ - NSCameraUsageDescription - Scan QR Code to login CFBundleDevelopmentRegion en CFBundleDisplayName @@ -25,18 +23,19 @@ CFBundleURLSchemes - fb677857427521030 + fb390204307987009 + com.googleusercontent.apps.817021856543-ad9nsjgdpsu2s2jrl63j3ihrv7lbf6ma CFBundleVersion $(CURRENT_PROJECT_VERSION) FacebookAppID - 677857427521030 + 390204307987009 FacebookClientToken - a6fb48571d9dd9fe5f3454b1ae2401e2 + 70e8f7ea883417e96f137e0bd025bfce FacebookDisplayName - wrenchboard.com - development + WrenchBoard LSApplicationQueriesSchemes fbapi @@ -57,6 +56,8 @@ LSRequiresIPhoneOS + NSCameraUsageDescription + Scan QR Code to login NSLocationAlwaysAndWhenInUseUsageDescription We need to enable geotagging to send you notifications and messages based on your location, so you will get the relevant ones only NSLocationAlwaysUsageDescription diff --git a/ios/App/Podfile b/ios/App/Podfile index d7eeb90..6aff0b7 100644 --- a/ios/App/Podfile +++ b/ios/App/Podfile @@ -8,6 +8,8 @@ use_frameworks! # Requires CocoaPods 1.6 or newer install! 'cocoapods', :disable_input_output_paths => true +gem 'activesupport', '~> 7.0', '<= 7.0.8' + def capacitor_pods pod 'Capacitor', :path => '../../node_modules/@capacitor/ios' pod 'CapacitorCordova', :path => '../../node_modules/@capacitor/ios' @@ -19,6 +21,7 @@ def capacitor_pods pod 'CapacitorKeyboard', :path => '../../node_modules/@capacitor/keyboard' pod 'CapacitorPreferences', :path => '../../node_modules/@capacitor/preferences' pod 'CapacitorStatusBar', :path => '../../node_modules/@capacitor/status-bar' + pod 'CodetrixStudioCapacitorGoogleAuth', :path => '../../node_modules/@codetrix-studio/capacitor-google-auth' pod 'CordovaPluginsStatic', :path => '../capacitor-cordova-ios-plugins' end diff --git a/ios/App/Podfile.lock b/ios/App/Podfile.lock index ff71fd4..3fd1fd0 100644 --- a/ios/App/Podfile.lock +++ b/ios/App/Podfile.lock @@ -1,4 +1,10 @@ PODS: + - AppAuth (1.6.2): + - AppAuth/Core (= 1.6.2) + - AppAuth/ExternalUserAgent (= 1.6.2) + - AppAuth/Core (1.6.2) + - AppAuth/ExternalUserAgent (1.6.2): + - AppAuth/Core - Capacitor (5.0.5): - CapacitorCordova - CapacitorApp (5.0.3): @@ -20,6 +26,9 @@ PODS: - Capacitor - CapacitorStatusBar (5.0.4): - Capacitor + - CodetrixStudioCapacitorGoogleAuth (0.0.1): + - Capacitor + - GoogleSignIn (~> 6.2.4) - CordovaPluginsStatic (5.0.5): - CapacitorCordova - OneSignalXCFramework (= 5.0.0-beta-04) @@ -31,6 +40,14 @@ PODS: - FBSDKCoreKit_Basics (16.1.3) - FBSDKLoginKit (16.1.3): - FBSDKCoreKit (= 16.1.3) + - GoogleSignIn (6.2.4): + - AppAuth (~> 1.5) + - GTMAppAuth (~> 1.3) + - GTMSessionFetcher/Core (< 3.0, >= 1.1) + - GTMAppAuth (1.3.1): + - AppAuth/Core (~> 1.6) + - GTMSessionFetcher/Core (< 3.0, >= 1.5) + - GTMSessionFetcher/Core (2.3.0) - OneSignalXCFramework (5.0.0-beta-04): - OneSignalXCFramework/OneSignalCore (= 5.0.0-beta-04) - OneSignalXCFramework/OneSignalExtension (= 5.0.0-beta-04) @@ -67,6 +84,7 @@ DEPENDENCIES: - "CapacitorKeyboard (from `../../node_modules/@capacitor/keyboard`)" - "CapacitorPreferences (from `../../node_modules/@capacitor/preferences`)" - "CapacitorStatusBar (from `../../node_modules/@capacitor/status-bar`)" + - "CodetrixStudioCapacitorGoogleAuth (from `../../node_modules/@codetrix-studio/capacitor-google-auth`)" - CordovaPluginsStatic (from `../capacitor-cordova-ios-plugins`) - FBSDKCoreKit (= 16.1.3) - FBSDKLoginKit (= 16.1.3) @@ -74,10 +92,14 @@ DEPENDENCIES: SPEC REPOS: trunk: + - AppAuth - FBAEMKit - FBSDKCoreKit - FBSDKCoreKit_Basics - FBSDKLoginKit + - GoogleSignIn + - GTMAppAuth + - GTMSessionFetcher - OneSignalXCFramework EXTERNAL SOURCES: @@ -101,10 +123,13 @@ EXTERNAL SOURCES: :path: "../../node_modules/@capacitor/preferences" CapacitorStatusBar: :path: "../../node_modules/@capacitor/status-bar" + CodetrixStudioCapacitorGoogleAuth: + :path: "../../node_modules/@codetrix-studio/capacitor-google-auth" CordovaPluginsStatic: :path: "../capacitor-cordova-ios-plugins" SPEC CHECKSUMS: + AppAuth: 3bb1d1cd9340bd09f5ed189fb00b1cc28e1e8570 Capacitor: b1248915663add1bd6567e2b67c1c1fa3abcf5e8 CapacitorApp: 7a5dec8b33573707164b293475d5c89ba684364a CapacitorCommunityAppleSignIn: eafdd59b18b38161fa5cceee7b0e31312b122958 @@ -115,13 +140,17 @@ SPEC CHECKSUMS: CapacitorKeyboard: d1b25fde6f19744ad09c890862aefc6e2a7ded3d CapacitorPreferences: f03954bcb0ff09c792909e46bff88e3183c16b10 CapacitorStatusBar: 190e0321b8734f4244d0c81baa183a00d5806ddf + CodetrixStudioCapacitorGoogleAuth: fcce058390347c1ce5d8ac4764bdf1f5c1ee233b CordovaPluginsStatic: c1b87170d7e6c70c473250768081e07414af3879 FBAEMKit: af2972f39bb0f3f7c45998f435b007833c32ffb2 FBSDKCoreKit: 19e2e18b3be578d7a51fed8fdd8c152bef0b9511 FBSDKCoreKit_Basics: dd9826ce3c9fd9f8cdf8dbbd0ef0a53e6c0c9e7e FBSDKLoginKit: c395c63a1a6cf4a8a1e6103fd94b8c46329ee81c + GoogleSignIn: 5651ce3a61e56ca864160e79b484cd9ed3f49b7a + GTMAppAuth: 0ff230db599948a9ad7470ca667337803b3fc4dd + GTMSessionFetcher: 3a63d75eecd6aa32c2fc79f578064e1214dfdec2 OneSignalXCFramework: 0225dc78b9c611be84733e5adc9b68638632c1e8 -PODFILE CHECKSUM: 7d6a1b0dbd7cb987c2121b75ec46088af01da740 +PODFILE CHECKSUM: 6f3fca74c9da63a49dc76a4a79d1ca8197e91f23 -COCOAPODS: 1.12.1 +COCOAPODS: 1.13.0 diff --git a/package-lock.json b/package-lock.json index 11cd058..73eb905 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "WrenchBoard", - "version": "42.4.2", + "version": "42.8.7", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "WrenchBoard", - "version": "42.4.2", + "version": "42.8.7", "dependencies": { "@angular/common": "^14.0.0", "@angular/core": "^14.0.0", @@ -25,6 +25,7 @@ "@capacitor/keyboard": "^5.0.0", "@capacitor/preferences": "^5.0.6", "@capacitor/status-bar": "^5.0.0", + "@codetrix-studio/capacitor-google-auth": "^3.3.2", "@ionic/angular": "^6.1.9", "angularx-qrcode": "^14.0.0", "bn-ng-idle": "^2.0.5", @@ -2629,6 +2630,14 @@ "@capacitor/core": "^5.0.0" } }, + "node_modules/@codetrix-studio/capacitor-google-auth": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/@codetrix-studio/capacitor-google-auth/-/capacitor-google-auth-3.3.2.tgz", + "integrity": "sha512-RHYsgm/pU4JNmed5lYlT+xtoU6ktfw4/xG3o1iI5n7dhWO77kptOr2ZaVSXsYeOu1J93VeyOAyyqdaF+qkzxhw==", + "peerDependencies": { + "@capacitor/core": "^5.0.0" + } + }, "node_modules/@colors/colors": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz", @@ -21661,6 +21670,12 @@ "integrity": "sha512-6gvkUTotpzHlfn5KoIglbIqdaEWV/crLtCYXebtFtRAPofCU8EWcljGeeISKBYPE99xqsk3M66vRUY4OzsAYyA==", "requires": {} }, + "@codetrix-studio/capacitor-google-auth": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/@codetrix-studio/capacitor-google-auth/-/capacitor-google-auth-3.3.2.tgz", + "integrity": "sha512-RHYsgm/pU4JNmed5lYlT+xtoU6ktfw4/xG3o1iI5n7dhWO77kptOr2ZaVSXsYeOu1J93VeyOAyyqdaF+qkzxhw==", + "requires": {} + }, "@colors/colors": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz", diff --git a/package.json b/package.json index e8184c4..8d4119a 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "@capacitor/keyboard": "^5.0.0", "@capacitor/preferences": "^5.0.6", "@capacitor/status-bar": "^5.0.0", + "@codetrix-studio/capacitor-google-auth": "^3.3.2", "@ionic/angular": "^6.1.9", "angularx-qrcode": "^14.0.0", "bn-ng-idle": "^2.0.5", diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 6b73509..f309142 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -2,6 +2,8 @@ import { Component } from '@angular/core'; import { BnNgIdleService } from 'bn-ng-idle'; import {SessionDataProviderService} from "./store/session-data-provider.service"; import {Router} from "@angular/router"; // import it to your component +import { Platform } from '@ionic/angular'; +import { GoogleAuth } from '@codetrix-studio/capacitor-google-auth'; @Component({ selector: 'app-root', @@ -9,7 +11,11 @@ import {Router} from "@angular/router"; // import it to your component styleUrls: ['app.component.scss'], }) export class AppComponent { - constructor(private bnIdle: BnNgIdleService,private sessionDataProviderService : SessionDataProviderService, public router: Router) { + constructor( + private bnIdle: BnNgIdleService, + private sessionDataProviderService : SessionDataProviderService, + public router: Router, + public platform: Platform) { // this.OneSignalInit(); this.bnIdle.startWatching(2500).subscribe((res) => { if(res) { @@ -18,11 +24,18 @@ export class AppComponent { this.sessionDataProviderService.DestroySessionOnLogout(); this.router.navigate(['login']); } - }) + }); + this.initializeApp(); } // Call this function when your app starts OneSignalInit(): void { console.log('Moved to home'); } + + initializeApp(): void { + this.platform.ready().then(() => { + //GoogleAuth.initialize() + }) + } } diff --git a/src/app/pages/login/login.page.html b/src/app/pages/login/login.page.html index 52ace49..44b8e8c 100644 --- a/src/app/pages/login/login.page.html +++ b/src/app/pages/login/login.page.html @@ -72,12 +72,12 @@ - + - + diff --git a/src/app/pages/login/login.page.ts b/src/app/pages/login/login.page.ts index 9868667..e68881e 100644 --- a/src/app/pages/login/login.page.ts +++ b/src/app/pages/login/login.page.ts @@ -4,7 +4,7 @@ import { WrenchService } from 'src/app/services/wrench.service'; import { SessionDataProviderService } from 'src/app/store/session-data-provider.service'; import { BlogDataService } from 'src/app/store/blog-data.service'; import { environment} from "../../../environments/environment"; -import { AlertController } from '@ionic/angular'; +import { AlertController, Platform } from '@ionic/angular'; import { Preferences } from '@capacitor/preferences'; import { Capacitor } from '@capacitor/core'; import jwt_decode from "jwt-decode"; @@ -17,6 +17,7 @@ import { FacebookLogin, FacebookLoginResponse, } from '@capacitor-community/facebook-login'; +import { GoogleAuth, User } from '@codetrix-studio/capacitor-google-auth'; @Component({ selector: 'app-login', @@ -32,15 +33,30 @@ export class LoginPage implements OnInit { appleSignInAbortController: any; appleSignInWindow: any; state: any; + ios: boolean; + android: boolean; constructor( private router: Router, private wrenchService: WrenchService, public sessionDataProviderService:SessionDataProviderService, public blogDataService:BlogDataService, - private alertController: AlertController + private alertController: AlertController, + public platform: Platform ) { - + // https://ionicframework.com/docs/angular/platform + this.ios = platform.is('ios'); + this.android = platform.is('android'); + } + + ionViewDidEnter() { + // GoogleAuth.init(); + // use hook after platform dom ready + GoogleAuth.initialize({ + clientId: '817021856543-ad9nsjgdpsu2s2jrl63j3ihrv7lbf6ma.apps.googleusercontent.com', + scopes: ['profile', 'email'], + grantOfflineAccess: true, + }); } ngOnInit() { @@ -115,6 +131,54 @@ getBlogData(){ this.router.navigate(['startscan']); } + onLoginGoogle() { + GoogleAuth.signIn().then((user: User) => { + //const credential = auth.GoogleAuthProvider.credential(user.authentication.idToken); + //return this.afAuth.auth.signInAndRetrieveDataWithCredential(credential); + + if (user) { + const oauth2Data = { + "auth_type": "GOOGLE", + "access_token": user.authentication.accessToken, + "refresh_token": user.authentication.refreshToken, + "idToken": user.authentication.idToken, + "auth_code": user.serverAuthCode, + "user": user + }; + console.log(oauth2Data); + // Validate token with server and create new session + this.wrenchService.authStart(oauth2Data).subscribe( + loginResult => { + console.log(loginResult); + this.loginResult = loginResult; + console.log("INTERNAL RETURN->" + this.loginResult.internal_return); + + if (loginResult != null && loginResult.internal_return == 100 && this.sessionDataProviderService.ConstructGlobalSessionData(this.loginResult) == true) { + const setName = async () => { + await Preferences.set({ + key: 'username', + value: this.username, + }); + }; + + this.getBlogData(); + this.router.navigate(['tabs/tab1']); + } + else{ + this.showAlert("Error","Invalid username/password"); + } + } + ); + } else { + console.log(user); + this.showAlert("Error", "Login failed!"); + } + }).catch((error: any) => { + this.showAlert("Error", error); + console.log(error); + }); + } + onLoginFacebook() { const FACEBOOK_PERMISSIONS = [ 'email',