question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[FR]: Admin SDK should have a way to generate a session cookie without an ID token, or SDK should have a way to generate ID tokens

See original GitHub issue

Describe the solution you’d like Currently, to generate a session cookie, an ID token is needed. This ID token can only be generated by the client SDK through a “sign in” method like signInWithEmailAndPassword or signInWithCustomToken, then this ID can be sent over to a backend (ex: a cloud function) and there a session cookie is generated. The problem is that we need frontend logic for this which is quite cumbersome to do if I want to manage cookies server side and not leak any logic to the frontend (expect calling a single endpoint with the user credentials), as well as not dealing with cross site request forgery by using the sameSite cookie flag.

To do this, I would like a way to generate a session cookie without having an ID token, for example: user.generateSessionCookie(sessionCookieOptions) or admin.auth().generateSessionCookie(uid/UserRecord/cutomToken, sessionCookieOptions)

Describe alternatives you’ve considered One alternative that I’m going to have to take is to call the endpoint described in this link: https://firebase.google.com/docs/reference/rest/auth/#section-verify-custom-token. To exchange a custom token with an ID token and use this ID token to generate a cookie session that can last up to two weeks. Having to do this:

  1. get user (login with credentials/create new user);
  2. generate custom token;
  3. call endpoint to exchange for an ID token;
  4. generate session cookie with ID token;
  5. Use session cookie.

Is quite messy, not to mention that it’s strange that we don’t have a good way to do this yet. I also thought about using the client SDK on the server side, but the login methods are rate limited and I think I’d hit that limit quickly if I call it from a single or a few dozen server instances.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

0reactions
bojeil-googlecommented, Apr 12, 2021

All endpoints used are standard REST APIs. More documentation available here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Manage Session Cookies | Firebase Authentication
A Firebase ID token is generated, and the ID token is then sent via HTTP POST to a session login endpoint where, using...
Read more >
Firebase admin sdk: idToken OR custom token verification for ...
To verify the ID Token, you must use the mentioned token. If you try to use the session ID Token or the Custom...
Read more >
Authentication — Firebase Admin SDK for PHP Documentation
The Firebase Admin SDK has a built-in method for creating custom tokens. At a minimum, you need to provide a uid, which can...
Read more >
Firebase: Introducing session cookies for server-side web apps
The session initializer uses the create_session_cookie() function of the Admin SDK to exchange the ID token for a Firebase session cookie. Developers can ......
Read more >
OpenID Connect & OAuth 2.0 API - Okta Developer
Okta as the identity platform for your app or API ... session should be considered. scope and nonce must not be specified, because...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found