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

Invalid API Key when using with gcp-iap-web-toolkit and nextjs #1114

Open
aaron-tillekeratne opened this issue Jan 1, 2025 · 0 comments
Open

Comments

@aaron-tillekeratne
Copy link

aaron-tillekeratne commented Jan 1, 2025

Hi FirebaseUI team,

Issue

I'm currently attempting to integrate cloud IAP external Identities with the login page using firebase UI. However it's currently resulting in a runtime error which is "Error: Invalid project configuration: API key is invalid!"

I have had a look at a few other issues but unfortunately have not worked for me.

Background

As per the google documentation in integrating external identities for Cloud IAP, I'm using the gcp-iap-web-toolkit. After attempting their prebuilt container and source code with mixed results I have decided to build a nextjs app for the authentication handler.

I have configured the identity platform, and other GCP components as per the documentation.

The nextjs application is simple and is contained in a single page.tsx. I will link the code below.

You can access the URL at test.tille.io to see the runtime error.

Code

// page.tsx
'use client'

import { useEffect } from 'react';
import firebase from 'firebase/compat/app';
import { OAuthProvider } from 'firebase/auth/web-extension';
// import * as firebaseui from 'firebaseui';
// import * as ciap from 'gcip-iap';

export default function Home() {
  
    // FirebaseUI configuration for a single tenant and Microsoft login
    useEffect(() => {
    // Dynamically import firebaseui and gcip-iap because they depend on the browser environment
    const initializeFirebaseUI = async () => {
      
      const firebaseui = (await import('firebaseui'));
      const ciap = await import('gcip-iap');

      const provider = new OAuthProvider('microsoft.com');

      console.warn(firebaseui)
      // FirebaseUI configuration for a single tenant and Microsoft login
      const config = {
        "*": {
          authDomain: "tilleio*******.firebaseapp.com",
          displayMode: 'optionFirst', // Single tenant
          callbacks: {
            signInUiShown: () => {
              console.log('Sign-in page shown');
            },
            beforeSignInSuccess: (user: firebase.User) => {
              console.log('User signed in:', user);
              return Promise.resolve(user);
            },
          },
          tenants: {
            defaultTenant: {
              displayName: 'Microsoft Login',
              buttonColor: '#2F2F2F',
              iconUrl: '/images/microsoft-icon.png',
              signInOptions: [
                {
                  provider: provider, // Replace with actual Microsoft provider if different
                  providerName: 'Microsoft',
                  buttonColor: '#2F2F2F',
                  iconUrl: '/images/microsoft-icon.png',
                  loginHintKey: 'login_hint',
                },
              ],
              immediateFederatedRedirect: true,
              signInFlow: 'redirect',
            },
          },
        },
      };

      const uiHandler = new firebaseui.auth.FirebaseUiHandler(
        '#firebaseui-auth-container',
        config
      );
      const ciapInstance = new ciap.Authentication(uiHandler);
      ciapInstance.start();
    };

    initializeFirebaseUI();
  }, []);

  return (
    <div id='firebaseui-auth-container'>

    </div>
  );
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant