firebase / firebase-admin-dotnet

Firebase Admin .NET SDK
https://firebase.google.com/docs/admin/setup
Apache License 2.0
357 stars 129 forks source link

CreateSessionCookieAsync use wrong url to make request to the API #331

Open AlexanderVorobyov opened 1 year ago

AlexanderVorobyov commented 1 year ago

[REQUIRED] Step 2: Describe your environment

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

CreateSessionCookieAsync always results with Not Found status code. (Tested with Emulator)

PostAndDeserializeAsync method builds URL always including / character between base Url and Path.

In case of createSessionCookie API the result url will be wrong:

Current:

Firebase: POST https://identitytoolkit.googleapis.com/v1/projects/{targetProjectId}/:createSessionCookie
Emulator: POST http:/localhost:9099/identitytoolkit.googleapis.com/v1/projects/{targetProjectId}/:createSessionCookie

Should be:

Firebase: POST https://identitytoolkit.googleapis.com/v1/projects/{targetProjectId}:createSessionCookie
Emulator: POST http:/localhost:9099/identitytoolkit.googleapis.com/v1/projects/{targetProjectId}:createSessionCookie

Relevant Code:

https://github.com/firebase/firebase-admin-dotnet/blob/0870aa628e2b6b7632001e1d5c9a2e782cda3598/FirebaseAdmin/FirebaseAdmin/Auth/Users/FirebaseUserManager.cs#L386

https://github.com/firebase/firebase-admin-dotnet/blob/0870aa628e2b6b7632001e1d5c9a2e782cda3598/FirebaseAdmin/FirebaseAdmin/Auth/Users/FirebaseUserManager.cs#L430

AlexanderVorobyov commented 1 year ago

Also, I found that CreateSessionCookieVerifier() has missing setup for IsEmulatorMode argument and that causing the error when validate session cookie from emulator.

https://github.com/firebase/firebase-admin-dotnet/blob/0870aa628e2b6b7632001e1d5c9a2e782cda3598/FirebaseAdmin/FirebaseAdmin/Auth/Jwt/FirebaseTokenVerifier.cs#L142