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

[FR] There should be a way to send custom login parameter into blocking function context #1451

Open
Thaina opened this issue Jun 27, 2023 · 2 comments

Comments

@Thaina
Copy link

Thaina commented Jun 27, 2023

Is your feature request related to a problem? Please describe.
Since firebase function support blocking functions. I wish to have logic to set session claims or reject signin based on session context. Such as the current page or domain user currently used to signing in

Describe the solution you'd like
In client, I wish that the api auth().signInWithPopup and similar function should support adding custom parameter, such as

auth().signInWithPopup(new auth.GoogleAuthProvider(),{ customKey : 1234 });

Then in the server api, I wish that the AuthEventContext parameter at the API functions.auth.user().beforeSignIn should have params value being set as the custom value

exports.checkClaimBeforeSignIn = functions.auth.user().beforeSignIn((user,context) => {
    // get sessionClaims only in the page that set customKey as 1234
    if(context.params.customKey == 1234)
    {
         const doc = await getFirestore().collection("users").doc(user.uid).get();
         const adminLevel = doc.get("adminLevel");
         // get sessionClaims only in the page that set customKey as 1234
         if(adminLevel > 0)
             return { sessionClaims: { adminLevel : doc.get("adminLevel")  }  };

         // reject access to admin page
         throw new Error("Not admin");
    }
});

I don't know any workaround that could utilize blocking function this ways, is it possible?

@google-oss-bot
Copy link
Collaborator

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

@colerogers colerogers transferred this issue from firebase/firebase-admin-node Jul 24, 2023
@mmarifat
Copy link

mmarifat commented Oct 6, 2023

Desperately need a solution on this too

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

No branches or pull requests

5 participants