Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firebase Functions Emulator Fails Over Local Network #7538

Closed
peterfriese opened this issue Feb 16, 2021 · 2 comments · Fixed by #7545
Closed

Firebase Functions Emulator Fails Over Local Network #7538

peterfriese opened this issue Feb 16, 2021 · 2 comments · Fixed by #7545
Assignees

Comments

@peterfriese
Copy link
Contributor

peterfriese commented Feb 16, 2021

Step 1: Describe your environment

  • Xcode version: 12.4
  • Firebase SDK version: 7.6.0
  • Installation method: Swift Package Manager
  • Firebase Component: Emulators , Functions

Step 2: Describe the problem

Steps to reproduce:

  1. Create a new Firebase project via the console
  2. Create a new local Firebase project using the CLI
    • Enable Functions and Emulators
    • Enable the Functions and Auth Emulators
    • Use the default ports for setting up the emulators
  3. Implement a simple callable helloWorld function (see below)
  4. Launch the emulators (firebase emulators:start)
  5. Create a new (SwiftUI) project
  6. Download GoogleService-Info.plist and add to project
  7. Enable App Transport Security (allow arbitrary loads)
  8. Initialise the emulators (see Swift code below)
  9. Call helloWorld callable function from Swift (see code below)

Expected behaviour

  • It is possible to call the helloWorld callable function from the iOS app

Observed behaviour

  • GTMSessionFetcher issues error message about http not being in list of allowed insecure schemes:
2021-02-16 16:32:29.570523+0100 FirebaseEmulatorDemo[47823:2419456] Insecure fetch request has a scheme (localhost) not found in fetcher allowedInsecureSchemes ((
    http
)): localhost:5001/peterfriese-friction-emulators/us-central1/helloWorld
Error Domain=com.google.GTMSessionFetcher Code=-5 "(null)" UserInfo={NSErrorFailingURLStringKey=localhost:5001/peterfriese-friction-emulators/us-central1/helloWorld}

Relevant Code:

Callable Function:
exports.helloWorld = functions.https.onCall((data, context) => {
    return {
        message: "Hello World from Firebase" 
    };  
});

Swift code for initialising emulators and calling the Function

class FirebaseEmulatorDemo: ObservableObject {
  
  lazy var functions = Functions.functions()
  
  init() {
    FirebaseApp.configure()
    
    // set up emulators
    Auth.auth().useEmulator(withHost: "localhost", port: 9099)
    functions.useEmulator(withHost: "localhost", port: 5001)
  }
  
  func helloWorld() {
    let helloWorld = functions.httpsCallable("helloWorld")
    helloWorld.call() { result, error in
      if let error = error {
        print(error)
      }
      else {
        if let message = (result?.data as? [String: Any])?["message"] as? String {
          print("The function returned: \(message)")
        }
      }
    }
  }
  
}

Related material

// Override normal security rules if this is a local test.
if (_emulatorOrigin) {
fetcher.allowLocalhostRequest = YES;
fetcher.allowedInsecureSchemes = @[ @"http" ];
}

@peterfriese
Copy link
Contributor Author

Update: as discussed on #7537, prefixing the Functions Emulator host with http:// fixes the issue.

@peterfriese
Copy link
Contributor Author

Assigning to @samtstern to look into whether providing the protocol should be required.

@peterfriese peterfriese reopened this Feb 17, 2021
@samtstern samtstern self-assigned this Feb 17, 2021
@firebase firebase locked and limited conversation to collaborators Mar 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
4 participants