Social logins with Masked domain - laravel-5.1

I use sub-domain for all clients like client.example.com and then i masked their domain over it. i have added social logins Google, Facebook and LinkedIn.
Facebook and LinkedIn Seems to be working but the issue with Google Login its just showing blank white page when i hit the URL for login.
is it possible to use social logins for masked domain?
because other two are working fine and google is not throwing any error so could not figure out the solution.
Project is in Laravel-5.1 and i use Socialite
Any help would be great
Thank you in advance

step 1
Install Pod File for pod 'Google/SignIn'
step 2
For below code to Add AppDelegate
AppDelegate.swift
import UIKit
import Google
import GoogleSignIn
import FacebookCore
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
var configureError: NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
assert(configureError == nil, "Error configuring Google services: \(String(describing: configureError))")
return SDKApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
}
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
print("Google+ url scheme")
return GIDSignIn.sharedInstance().handle(url, sourceApplication: sourceApplication, annotation: annotation)
}
#available(iOS 9.0, *)
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
print("Google+ url scheme")
let sourceApplication = options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String
let annotation = options[UIApplicationOpenURLOptionsKey.annotation]
return GIDSignIn.sharedInstance().handle(url, sourceApplication: sourceApplication, annotation: annotation)
}
ViewController.swift
import UIKit
import GoogleSignIn
import FacebookCore
import FacebookLogin
class ViewController: UIViewController, GIDSignInDelegate, GIDSignInUIDelegate {
#IBOutlet weak var profileImage: UIImageView!
#IBOutlet weak var emailText: UITextField!
#IBOutlet weak var passwordText: UITextField!
#IBOutlet weak var rememberMeSegment: UISwitch!
#IBOutlet weak var appSignInButton: UIButton!
#IBOutlet weak var googleSignInButton: UIButton!
#IBOutlet weak var facebookSignInButton: UIButton!
#IBOutlet weak var appSignUpButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
self.profileImage.layer.masksToBounds = false
self.profileImage.layer.cornerRadius = self.profileImage.frame.height/2
self.profileImage.clipsToBounds = true
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.navigationBar.isHidden = true
}
#IBAction func googleSignIn(sender: UIButton) {
GIDSignIn.sharedInstance().scopes = ["https://www.googleapis.com/auth/plus.login","https://www.googleapis.com/auth/plus.me"]
GIDSignIn.sharedInstance().shouldFetchBasicProfile = true
GIDSignIn.sharedInstance().uiDelegate = self
GIDSignIn.sharedInstance().delegate = self
GIDSignIn.sharedInstance().signIn()
}
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
if (error == nil) {
print("Name : \(user.profile.name!)")
print("Email : \(user.profile.email!)")
if let email = user.profile.email {
self.emailText.text = email
}
if(user.profile.hasImage){
print("Profile Image : \(user.profile.imageURL(withDimension: 100))")
self.profileImage.downloadedFrom(link: user.profile.imageURL(withDimension: 100).absoluteString)
} else {
print("Profile Image : Profile image not available")
}
GIDSignIn.sharedInstance().signOut()
GIDSignIn.sharedInstance().disconnect()
} else {
let alertController = UIAlertController(title: "Error", message: "\(error.localizedDescription)")
self.present(alertController, animated: true, completion: nil)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
- extension String {
func hexStringToUIColor () -> UIColor {
var cString:String = self.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()
if (cString.hasPrefix("#")) {
cString.remove(at: cString.startIndex)
}
if ((cString.characters.count) != 6) {
return UIColor.gray
}
var rgbValue:UInt32 = 0
Scanner(string: cString).scanHexInt32(&rgbValue)
return UIColor(
red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0,
blue: CGFloat(rgbValue & 0x0000FF) / 255.0,
alpha: CGFloat(1.0)
)
}
}
extension UIAlertController {
convenience init(title: String, message: String) {
self.init(title: title, message: message, preferredStyle: .alert)
let action = UIAlertAction(title: NSLocalizedString("OK", comment: "OK action"), style: .default, handler: nil)
addAction(action)
}
}

Related

Google Sign-in crash & error: uiDelegate must either be a |UIViewController|

I'm trying to implement Google Sign-in to an iOS app but the app crashes on clicking on the Sign-in button with the following error:
reason: 'uiDelegate must either be a |UIViewController| or implement the |signIn:presentViewController:| and |signIn:dismissViewController:| methods from |GIDSignInUIDelegate|.'
I'm not sure where I'm going wrong. I've followed the sample code from Google's iOS github exactly. I also can't get Google's sample to compile. If anyone could point me in the right direction, that would be great. Most of the SO questions are based on dated code.
Viewcontroller
import UIKit
import GoogleSignIn
#objc(ViewController)
class ViewController: UIViewController, GIDSignInUIDelegate {
// Viewcontroller buttons
#IBOutlet weak var signInButton: GIDSignInButton!
#IBOutlet weak var signOutButton: UIButton!
#IBOutlet weak var disconnectButton: UIButton!
#IBOutlet weak var statusText: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
GIDSignIn.sharedInstance().uiDelegate = self
// Sign in automatically
GIDSignIn.sharedInstance().signInSilently()
// Something to do with notifications
NotificationCenter.default.addObserver(self,
selector: #selector(ViewController.receiveToggleAuthUINotification(_:)),
name: NSNotification.Name(rawValue: "ToggleAuthUINotification"),
object: nil)
statusText.text = "Initialized Swift App..."
toggleAuthUi()
}
// Sign out tapped
#IBAction func didTapDisconnect(_ sender: AnyObject) {
GIDSignIn.sharedInstance().disconnect()
statusText.text = "Disconnecting"
}
// Toggle auth
func toggleAuthUi() {
if GIDSignIn.sharedInstance().hasAuthInKeychain() {
signInButton.isHidden = true
signOutButton.isHidden = false
disconnectButton.isHidden = false
} else {
signInButton.isHidden = false
signOutButton.isHidden = true
disconnectButton.isHidden = true
}
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return UIStatusBarStyle.lightContent
}
deinit {
NotificationCenter.default.removeObserver(self,
name: NSNotification.Name(rawValue: "ToggleAuthUINotification"),
object: nil)
}
#objc func receiveToggleAuthUINotification(_ notification: NSNotification) {
if notification.name.rawValue == "ToggleAuthUINotification" {
self.toggleAuthUi()
if notification.userInfo != nil {
guard let userInfo = notification.userInfo as? [String:String] else {return}
self.statusText.text = userInfo["statusText"]!
}
}
}
}
AppDelegate:
import UIKit
import GoogleSignIn
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {
var window: UIWindow?
// Did Finished Launching
func application (_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Init Sign in
GIDSignIn.sharedInstance().clientID = "XXXXXXXXX"
GIDSignIn.sharedInstance().delegate = self
return true
}
// Open URL
func application (_app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey: Any]) -> Bool {
return GIDSignIn.sharedInstance().handle(url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String, annotation: options[UIApplicationOpenURLOptionsKey.annotation])
}
public func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
if let error = error {
print("\(error.localizedDescription)")
NotificationCenter.default.post(
name: Notification.Name(rawValue: "ToggleAuthUINotificiation"), object: nil, userInfo: nil)
} else {
// User Stuff
let userID = user.userID
let idToken = user.authentication.idToken
let fullName = user.profile.name
let givenName = user.profile.givenName
let familyName = user.profile.familyName
let email = user.profile.email
NotificationCenter.default.post(
name: Notification.Name(rawValue: "ToggleAuthUINotification"),
object: nil,
userInfo: ["statusText": "Signed in user:\n\(fullName)"])
}
}
public func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!, withError error: Error!) {
// Disconnect the user
NotificationCenter.default.post(
name: Notification.Name(rawValue: "ToggleAuthUINotification"),
object: nil,
userInfo: ["statusText": "User has disconnect."])
}
}
tl;dr: If using a non-UIViewController as a uiDelegate - check if Xcode is warning you that "Instance method [...] nearly matches optional requirement [...]" and use the Fix-Its. Make sure your functions match the required signature exactly.
I had the same error after following the sample code.
In my case the setup was a bit different, so I am not sure if my solution is applicable to your question - but because this StackOverflow answer shows up in Google Search, I thought I'd provide my resolution here for any people stumbling upon it:
I needed a non-UIVIewController subclass to be the Google Sign In uiDelegate. As the documentation and the error state, this means you need to implement some methods. I had implemented them, so it was strange that things were crashing.
In my case, the issue was that the copy-pasted code from Google's documentation was not exactly matching the Swift function signatures. In fact, I had warnings in Xcode, saying "Instance method [...] nearly matches optional requirement [...]". I used the auto Fix-Its by Xcode (it was stuff such as Error instead of NSError, or _ before a function's argument.)
Then it all worked.

Swift Firebase says internal error when creating a new user

I am trying to create new users with Firebase but it is giving me the message "An internal error has occurred, print and inspect the error details for more information." I have enabled the email password authentication on Firebase as well.
This is all the code that I have written as a test and it still doesn't work.
import UIKit
import Firebase
class ViewController: UIViewController {
#IBOutlet weak var emailTextField: UITextField!
#IBOutlet weak var pwordTxtField: UITextField!
#IBOutlet weak var continuebutton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
}
#IBAction func button(_ sender: Any) {
let email = emailTextField.text
let password = pwordTextField.text
Auth.auth().createUser(withEmail: email! , password: password!, completion: { (user, error) in
if let error = error {
print(error.localizedDescription)
}
else {
print("Success")
}
})
}
}
What I am doing wrong.
Thanks!
Include the following pods in your Podfile:
pod 'Firebase/Auth'
open the auth section and enable Email/password sign-in method and save.
make sure you have added GoogleService-Info.plist file in your project.
in Appdelegate :-
import Firebase
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions:
[UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FirebaseApp.configure()
return true
}
In Viewcontroller:-
import UIKit
import Firebase
class ViewController: UIViewController {
#IBOutlet weak var emailTextField: UITextField!
#IBOutlet weak var pwordTxtField: UITextField!
#IBOutlet weak var continuebutton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
}
#IBAction func button(_ sender: Any) {
let email = emailTextField.text
let password = pwordTextField.text
Auth.auth().createUser(withEmail: email! , password: password!,
completion: { (user, error) in
if let error = error {
print(error.localizedDescription)
}
else {
print("Success")
}
})
}
}

Not presenting Safari view on click of Google sign in button

I am clicking on the google sign in button but it is not presenting the SafariView, but the delegate methods of GIDSignInUIDelegate is called.
Besides this the delegate methods of GIDSignInDelegate are not called from the App Delegate .
What are the possible reasons? Below is the code given:
My URL Scheme:
com.googleusercontent.apps.1028134765971-6ok9n9pemgs3709q70so3bn5u08e84f6
AppDelegate.h
//
// AppDelegate.swift
// ESO
//
// Created by BBI USER 1027 on 23/05/17.
// Copyright © 2017 BBI. All rights reserved.
//
import UIKit
import Firebase
import GoogleSignIn
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
let signIn = GIDSignIn.sharedInstance()
signIn?.clientID = FirebaseApp.app()?.options.clientID!
signIn?.scopes = ["https://www.googleapis.com/auth/plus.login"]
signIn?.delegate = self
return true
}
func application(_ application: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any])
-> Bool {
print(GIDSignIn.sharedInstance().handle(url,
sourceApplication:options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,
annotation: [:]))
return GIDSignIn.sharedInstance().handle(url,
sourceApplication:options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,
annotation: [:])
}
//MARK : Google sign in delegate methods
func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!,
withError error: NSError!) {
if (error == nil) {
// Perform any operations on signed in user here.
let userId = user.userID // For client-side use only!
let idToken = user.authentication.idToken // Safe to send to the server
let fullName = user.profile.name
let givenName = user.profile.givenName
let familyName = user.profile.familyName
let email = user.profile.email
// ...
} else {
print("\(error.localizedDescription)")
}
}
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error?) {
// ...
if let error = error {
// ...
return
}
guard let authentication = user.authentication else { return }
let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken,
accessToken: authentication.accessToken)
// ...
Auth.auth().signIn(with: credential) { (user, error) in
if let error = error {
// ...
return
}
// User is signed in
// ...
}
}
}
FBGoogleSigninViewController.swift
//
// FBGoogleSigninViewController.swift
// LoginModule
//
// Created by Shubham Ojha on 8/4/17.
// Copyright © 2017 BBI. All rights reserved.
//
import UIKit
import Firebase
import GoogleSignIn
class FBGoogleSigninViewController: UIViewController,GIDSignInUIDelegate {
#IBOutlet weak var segmentView: UISegmentedControl!
#IBOutlet weak var loginIDCustomTextField: CustomTextField!
#IBOutlet weak var passwordCustomTextField: CustomTextField!
#IBOutlet weak var loginIdLabel: UILabel!
// On click of this button I am not getting any response.
#IBOutlet weak var SignInButton: GIDSignInButton!
override func viewDidLoad() {
super.viewDidLoad()
GIDSignIn.sharedInstance().uiDelegate = self;
GIDSignIn.sharedInstance().signIn()
self.SignInButton.layer.cornerRadius = 5.0;
self.navigationController?.setNavigationBarHidden(false, animated: true)
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBAction func segmentValueChanged(_ sender: Any) {
let segment = sender as! UISegmentedControl
if segment.selectedSegmentIndex == 0 {
self.loginIdLabel.text = "Login ID"
self.SignInButton.backgroundColor = UIColor.blue
}
else{
self.loginIdLabel.text = "Email ID"
self.SignInButton.backgroundColor = UIColor.red
}
}
// MARK: google sign in delegate methods
public func sign(inWillDispatch signIn: GIDSignIn!, error: Error!){
}
func sign(_ signIn: GIDSignIn!, present viewController: UIViewController!){
print(viewController.description)
}
}

I can't load second url from another function

I'll try to load second url from 3D touch shortcuts but when I try to load url into webview from another function of viewDidLoad not working.
I'm always getting EXC_BREAKPOINT warning. I have tried all the day can anyone know how to load url into webview from some function called from AppDelegate.
handleShortcut: this function calling from AppDelegate.
import UIKit
class FirstViewController: UIViewController, UIWebViewDelegate {
#IBOutlet weak var webView: UIWebView!
#IBOutlet weak var loading_splash_text: UIImageView!
#IBOutlet weak var loading_splash: UIImageView!
//internal var urlToLoad: String?
func didFailLoadWithError(webView: UIWebView) {
//print("connection error");
/*
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("ConnectionError")
self.navigationController!.pushViewController(vc, animated: true)
*/
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let url = NSURL (string: "http://example.com/");
let requestObj = NSURLRequest(URL: url!);
webView.delegate = self
webView.loadRequest(requestObj);
}
func webViewDidFinishLoad(webView: UIWebView) {
print("did finished");
loading_splash.hidden = true;
loading_splash_text.hidden = true;
}
func webViewDidStartLoad(webView : UIWebView) {
print("did load");
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func handleShortcut() {
let url = NSURL (string: "http://www.example.com/");
let requestObj = NSURLRequest(URL: url!);
webView.loadRequest(requestObj);
}
}
AppDelegate.swift:
import UIKit
public var urlToLoad: String?
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var vc = FirstViewController()
#available(iOS 9.0, *)
func application(application: UIApplication, performActionForShortcutItem shortcutItem: UIApplicationShortcutItem, completionHandler: (Bool) -> Void) {
if(shortcutItem.type == "com..videos"){
urlToLoad = "example.com";
} else if(shortcutItem.type == "com..contact") {
urlToLoad = "example.com";
} else if(shortcutItem.type == "com..projects") {
urlToLoad = "example.com";
} else {
urlToLoad = "example.com";
}
completionHandler(false)
vc.handleShortcut();
print("Shortcut: "+urlToLoad!);

firebase, swift, ios - Failed to fetch default token Error Domain=com.firebase.iid Code=6 "(null)"

I'm making a login app that tracks whether someone is logged in or not. I'm using firebase as a way to do this. if a person is not in firebase, they cannot be logged in.
PROBLEM
I keep getting the console error
<FIRInstanceID/WARNING> Failed to fetch default token Error Domain=com.firebase.iid Code=6 "(null)"
when I simulate the app. when I try to log in as Ash Dreyer, it does not log me in. I click it several times so even though I am logged in in firebase, it should log me out and log me back in again.
FIREBASE
{
"Ash Dreyer" : {
"activity" : "None",
"current_status" : "IN",
"num_of_logins" : 0,
"total_hours" : 0,
"type" : "mentor"
},
"Bryton Moeller" : {
"activity" : "None",
"current_status" : "OUT",
"num_of_logins" : 0,
"total_hours" : 0,
"type" : "student"
}
}
APP DELEGATE
import UIKit
import Firebase
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
override init() {
FIRApp.configure()
}
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
FIRApp.configure()
return true
}
}
LOGINVIEWCONTROLLER
import Firebase
import UIKit
class LoginViewController: UIViewController {
#IBOutlet weak var activity_label: UILabel!
#IBOutlet weak var activity_picker: UIPickerView!
#IBOutlet weak var name_field: UITextField!
#IBOutlet weak var login_button: UIButton!
#IBOutlet weak var location_switch: UISwitch!
var root_ref = FIRDatabase.database().reference()
// Color scheme
let grey = UIColor(red: 0.933, green: 0.929, blue: 0.922, alpha: 1.0)
let dark_orange = UIColor(red: 0.769, green: 0.396, blue: 0.176, alpha: 1.0)
let dark_blue = UIColor(red: 0.188, green: 0.463, blue: 0.541, alpha: 1.0)
let light_blue = UIColor(red: 0.412, green: 0.663, blue: 0.686, alpha: 1.0)
let light_orange = UIColor(red: 0.871, green: 0.612, blue: 0.451, alpha: 1.0)
var user: Person!
func update_UI() {
if let _ = user {
if user!.current_status == "IN" {
login_button.setTitleColor(dark_blue, for: UIControlState.normal)
login_button.setTitle("LOG OUT", for: UIControlState.normal)
} else {
login_button.setTitleColor(dark_orange, for: UIControlState.normal)
login_button.setTitle("LOG IN", for: UIControlState.normal)
}
}
}
func login(member: inout Person) {
if member.current_status == "IN" {
member.current_status = "OUT"
} else {
member.current_status = "IN"
}
root_ref.child(byAppendingPath: member.key).updateChildValues(["current_status": member.current_status]);
update_UI()
}
func login_new_user(member_name: String) {
root_ref.observe(FIRDataEventType.value, with: { (snapshot) -> Void in
for member in snapshot.children {
if member.key == member_name {
self.user = Person(snapshot: member as! FIRDataSnapshot)
}
}
})
if let _ = user {
login(member: &user!)
}
}
#IBAction func login_user(_ sender: UIButton) {
if let _ = user, let name_text = name_field.text, name_text != "" {
if user.key != name_text {
login_new_user(member_name: name_text)
}
} else if let name_text = name_field.text, name_text != "" {
login_new_user(member_name: name_text)
} else if let _ = user {
login(member: &user!)
} else {
print("Please enter text into the text field")
}
}
#IBAction func toggle_location(_ sender: UISwitch) {
}
#IBAction func other_login(_ sender: UIButton) {
}
}
NOTES
when I just had FIRApp.configure() in func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool, it gave me a SIGABRT error.
it's a small group that we are tracking, so I've decided to use first names instead of UIDs.
I'm using firebase 3
Just to update, these errors should no longer appear in the latest version of Firebase when using the Xcode 8.2+ version of the simulator. There was an issue (in fact a couple) with the simulator, and some overly aggressive logging in InstanceID.

Resources