Skip to content

Commit

Permalink
Fix line feed ios (#3) (#50)
Browse files Browse the repository at this point in the history
Fix line feed ios for 2.1.1
  • Loading branch information
Thibaud authored May 1, 2020
1 parent a356225 commit 5d2165d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 23 deletions.
29 changes: 8 additions & 21 deletions ios/Plugin/Plugin.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import Capacitor
import GoogleSignIn

/**
* Please read the Capacitor iOS Plugin Development Guide
* here: https://capacitor.ionicframework.com/docs/plugins/ios
Expand All @@ -16,30 +16,24 @@ public class GoogleAuth: CAPPlugin {
guard let path = Bundle.main.path(forResource: "GoogleService-Info", ofType: "plist") else {return}
guard let dict = NSDictionary(contentsOfFile: path) as? [String: AnyObject] else {return}
guard let clientId = dict["CLIENT_ID"] as? String else {return}
googleSignIn.clientID = clientId;
googleSignIn.delegate = self;
googleSignIn.presentingViewController = bridge.viewController;
if let serverClientId = getConfigValue("serverClientId") as? String {
googleSignIn.serverClientID = serverClientId;
}
if let scopes = getConfigValue("scopes") as? [String] {
googleSignIn.scopes = scopes;
}
if let forceAuthCodeConfig = getConfigValue("forceCodeForRefreshToken") as? Bool {
forceAuthCode = forceAuthCodeConfig;
}

NotificationCenter.default.addObserver(self, selector: #selector(handleOpenUrl(_ :)), name: Notification.Name(CAPNotifications.URLOpen.name()), object: nil);
}
@objc
func signIn(_ call: CAPPluginCall) {
signInCall = call;
DispatchQueue.main.async {
if self.googleSignIn.hasPreviousSignIn() && !self.forceAuthCode {
self.googleSignIn.restorePreviousSignIn();
Expand All @@ -48,21 +42,19 @@ public class GoogleAuth: CAPPlugin {
}
}
}
@objc
func refresh(_ call: CAPPluginCall) {
DispatchQueue.main.async {
if self.googleSignIn.currentUser == nil {
call.error("User not logged in.");
return
}
self.googleSignIn.currentUser.authentication.getTokensWithHandler { (authentication, error) in
guard let authentication = authentication else {
call.error(error?.localizedDescription ?? "Something went wrong.");
return;
}
let authenticationData: [String: Any] = [
"accessToken": authentication.accessToken,
"idToken": authentication.idToken,
Expand All @@ -72,30 +64,28 @@ public class GoogleAuth: CAPPlugin {
}
}
}
@objc
func signOut(_ call: CAPPluginCall) {
DispatchQueue.main.async {
self.googleSignIn.signOut();
}
call.success();
}
@objc
func handleOpenUrl(_ notification: Notification) {
guard let object = notification.object as? [String: Any] else {
print("There is no object on handleOpenUrl");
return;
}
guard let url = object["url"] as? URL else {
print("There is no url on handleOpenUrl");
return;
}
googleSignIn.handle(url);
}
func processCallback(user: GIDGoogleUser) {
var userData: [String: Any] = [
"authentication": [
Expand All @@ -110,22 +100,19 @@ public class GoogleAuth: CAPPlugin {
"id": user.userID,
"name": user.profile.name
];
if let imageUrl = user.profile.imageURL(withDimension: 100)?.absoluteString {
userData["imageUrl"] = imageUrl;
}
signInCall?.success(userData);
}
}

extension GoogleAuth: GIDSignInDelegate {
public func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
if let error = error {
signInCall?.error(error.localizedDescription);
return;
}
processCallback(user: user);
}
}
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codetrix-studio/capacitor-google-auth",
"version": "2.1.0",
"version": "2.1.1",
"description": "Google Auth plugin for capacitor.",
"main": "dist/esm/index.js",
"types": "dist/esm/index.d.ts",
Expand Down

0 comments on commit 5d2165d

Please sign in to comment.