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

Support verifying cookies from Firebase #53

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

jsmestad
Copy link

This PR adds support for verifying session cookies from Firebase. They are JWTs that have the same shape as idTokens, but are longer lived for backend applications. The difference is the kid values are unique between idToken and sessionCookies payloads.

I did my best to work inside the existing API to avoid any major rewrite, but am happy to adjust the approach.

Other Changes

I loosened the version constraints on Finch

@jsmestad
Copy link
Author

FYI I am using this fork in a new library I am working on called flame.

Given the overlap, it may make sense to pull this code into that library. Thoughts?

@Nickforall
Copy link
Owner

Will have a look at ur code later :)

Yeah there is a lot of overlap, love what you're doing with flame, looks great.

On the one hand it makes sense to have this independent, not all auth key consumers need to manage users, on the other hand I can imagine a lot of people needing both.

@jsmestad
Copy link
Author

I was debating the same thing, so glad to hear I am not alone there.

I would love to separate out the Cookie / Token APIs ideally as I think you should know which type you are dealing with at any time. However I was worried it would cause a major version bump for the library and create too much duplicate code. What do you think?

@Nickforall
Copy link
Owner

Nickforall commented Apr 29, 2022

Security wise that makes a lot of sense, we can definitely come up with an api that doesn't cause too many dupes. As long as verify_token and mock still work with the current behavior I think we're fine in terms of breaking changes?

@jsmestad
Copy link
Author

jsmestad commented May 3, 2022

@Nickforall I changed the API to ExFirebaseAuth.Cookie.verify_cookie/1 to mirror the ExFirebaseAuth.Token.verify_token/1 pattern.

I think you should be able to release this as a 0.x release in this form

@jsmestad
Copy link
Author

@Nickforall any luck on getting your eyes on this? I want to release the Flame library I've been working on, but I need a packaged version of ExFirebaseAuth first 😬

lib/token.ex Outdated Show resolved Hide resolved
@@ -30,8 +30,8 @@ defmodule ExFirebaseAuth.MixProject do
defp deps do
[
{:jose, "~> 1.10"},
{:finch, "~> 0.10.0"},
{:jason, "~> 1.3.0"},
{:finch, "~> 0.10"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this can be a problem, but it might be better to remove these changes so it will be easier for the maintainer to merge the dependabot patches that are already waiting.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah i'll verify and merge dependabot's PRs, this change should be removed after rebasing :)

@Nickforall
Copy link
Owner

@Nickforall any luck on getting your eyes on this? I want to release the Flame library I've been working on, but I need a packaged version of ExFirebaseAuth first 😬

Having a look now! Sorry for the inactivity here, founded a startup so have been super busy and no longer using this lib in production myself.

Copy link
Owner

@Nickforall Nickforall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small comments, but looking good so far 💪🏻

Comment on lines +15 to +21
with {:ok, %Finch.Response{body: body}} <-
Finch.build(:get, endpoint_url) |> Finch.request(ExFirebaseAuthFinch),
{:ok, json_data} <- Jason.decode(body) do
{:ok, convert_to_jose_keys(json_data)}
else
_ -> :error
end
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's extract this to a seperate function for readability

lib/source/google_key_source.ex Show resolved Hide resolved
Co-authored-by: Robert Parcus <[email protected]>
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

Successfully merging this pull request may close these issues.

3 participants