-
Notifications
You must be signed in to change notification settings - Fork 17
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
Endpoints 2.0.0b7 - Firebase, Service Account tokens #32
Comments
Hi I was trying to do the same thing for days now trying , to get endpoints and firebase authentication working together, is your workaround still the best way to do it ? or did google fix this and make it less confusing ? |
Hey @Tungamirai. I haven't checked out the latest version but, it doesn't look like the |
@lhmatt thanks for the reply , are they any solid examples/tutorials form start to end that use endpoints , with firebase authentication or any full repositories or complete projects that show this working ? I just started to learn app-engine and endpoints and it just seems very frustrating in general, was expecting it to be better documented with solid examples, are problems like this common with endpoints ? , I dont understand why google hasn't just made a solid example that actually works |
No worries, @Tungamirai. I have not found a full example with firebase auth, hence my post above. The closest I found was in the docs: https://cloud.google.com/endpoints/docs/frameworks/python/authenticating-users but I couldn't get it to work during the beta. Definitely give it a go if you can. This version of endpoints has just come out of beta so it's understandable that the docs may be missing some information. The best thing you can do is submit feedback (there is a button the the bottom of each page on the docs) to help them improve the information available. |
Thanks @lhmatt , will be keeping my eyes open for a documentation update , the link you found is the same one i also found but also couldn't get it to work, I hope the docs are updated soon Thanks again |
@lhmatt Thanks so much for your post. It allowed me to finally get Firebase authentication working. Google devs.....any word on when we can see the issues with Firebase authentication repaired in endpoints? |
Thank you so much! I've been banging my head against the wall for days trying to get this working and just now found this post. I ended up using |
@lhmatt Thank you so much for this. I spent a good part of my day trying to get my app to work, looking through the endpoints source code and thinking that theres no way this Firebase thing should work as described in the guides... Are you planning on making a pull request for this at all? If not, I was thinking of writing up something based on your PoC. |
No worries, @sxhan. I've abandoned my efforts with this framework so feel free to create your own pull request. After quite a bit of investigation, I've moved on to using Endpoints via ESP on App Engine flexible. I know not everyone can/wants to move to the flexible environment but it works for what I need to do. You trade higher running costs for developer productivity - with GAE flexible you can use the existing OpenAPI (swagger) tools to generate server stubs and client libraries, and you're not reliant on Google to build features into this framework. |
The example given for 3rd party issuer is like the following:
And version 2.0.5 works with the custom issuer I am using. |
@lhmatt Thanks for the suggestion! I was ready to do that yesterday before I found your post, but your reply is making me consider going that route again. Will probably play with this framework a bit more. @Al77056, thanks for the note. Unfortunately I can't get my Firebase Authentication to work without the changes lhmatt mentioned despite being on 2.0.5 . Are you testing your app locally or in the cloud? I see the following comment from a recent commit:
Which looks promising. Looks like AuthenticationMiddleware is supposed to be doing the token verifications and overriding the |
@sxhan, I am testing in the cloud. Before changes made in 2.0.5, Endpoints framework was not validating JWT signed by Google service account. 2.0.5 fixes that. |
@sxhan Could you provide sample logs of what happens when you try to use Firebase auth? 2.0.5 should indeed fix it. |
@tangiel probably this screeshot of logs can clarifay. |
Ah, so the issue isn't really the type of the user object returned, rather that it doesn't contain the id. Correct? |
I don't want to create confusion, I just start from the snippet example in the documentation https://cloud.google.com/endpoints/docs/frameworks/python/authenticating-users#authenticating_with_firebase_auth |
Looks like I'm hijacking the thread a bit. Apologies in advance for that. @tangiel, my problem is different than that of @presveva. My issue was that I kept getting I now realize that it may be because I was testing my endpoints application in the local development server (via However, I am unable to get it working with the local server. I see that the validation code path for local server is different than for when its deployed ( Following the example Al77056 provided, this is how I'm setting up the endpoints decorator:
Edit: looks like its a known issue, as reported in #55 |
@sxhan Did you make it work by appling the changes in 'endpoints/user_id_token.py' as decribed by Ihmatt or was that no longer neccessary for you? |
@sllegendre, following lhmatt's suggestions made it work, but I still have trouble without those changes. I ended up writing a wrapper around endpoints.get_current_user() to make development easier. Something like this... def get_current_user():
"""Returns the endpoint authenticated user object"""
class FakeUser:
def email(self):
return "[email protected]"
if (os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine/') or
os.getenv('SERVER_SOFTWARE', '').startswith('Development/1.0 (testbed)')):
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
else:
user = FakeUser()
return user This made it easy for me to test all my endpoints locally, although it won't help you debug any configuration issues with firebase auth. The call to |
@sxhan I was wondering how to abstract this for use in unit tests. There's also the |
@lhmatt thanks ,my project working with firebase and endpoint.but my issue is when I add file from Google drive with help of picker library of JavaScript then I try to store these document .that time I get 401(not authenticate ) error |
Spent a good few hours trying to get non-default Service Accounts and Firebase tokens to work with the endpoints framework. I wanted to feedback some issues, some work-arounds, and some general pointers for anyone else trying to do the same thing.
After following the quickstart guides on the endpoint docs I was able to get the tokens validating on the endpoint proxy. However, when the tokens reached the endpoints framework things started to go wrong -- the tokens failed to validate.
It seems a little odd that the framework re-validates the tokens, though I'm sure there is a reason why.
The endpoint proxy passes the
X-Endpoint-API-UserInfo
header, so perhaps we could just check that instead?Regardless, after some tinkering I managed to get the endpoint framework to play nicely with Firebase tokens and custom Service Accounts. These are hacks, but they serve as a proof of concept.
Although it took a long time to figure out, there weren't actually that many modifications to make. All of the changes are in
endpoints/user_id_token.py
.For reference, here is the api decorator I am using:
main.py
This is basically the
echo
example from the quickstart, modified to support Firebase tokens and non-default Service Accounts.General Comments:
The use of
try-except
with top-levelException
s makes debugging incredibly frustrating because it swallows some important details about why the exception occurred. I can see why it is used in the code, but I think it could be handled better. As it stands you need a lot of debug logging throughout the code in order to work out why a token fails to validate.The
jwks_uri
for each issuer needs to be theraw
variant in order to work properly with the endpoints framework. However, the endpoints proxy only accepts thex509
variant. I therefore had to override the uris in the endpoint framework. This is not mentioned in the endpoint docs, as far as I can tell.When using Firebase tokens,
aud
(audience
) is your project ID. This doesn't appear to be mentioned in the endpoint docs.Service accounts must supply their
client_id
as theazp
field in order for the validation to pass._verify_parsed_token
Custom Security Issuers
By default the code checks
_ISSUERS
only. This does not account for custom security directives in the api e.g. Firebase. I modified the issuer check to include custom values from the api security definition.Audiences
By default the code does not handle audiences being a dict (provider => audiences). I added a loop to iterate through each of the providers' audience values and check for a match. A potentially better solution could be to combine all of the provider audiences into a single set on init.
Firebase tokens
Firebase auth tokens do not include a
cid
value which results in aClient ID is not allowed
message. To circumvent this, I added a check on see ifiss
is equal tohttps://securetoken.google.com/[YOUR-PROJECT-ID]
. If it does then assign acid
offirebase_auth
(see themain.py
code above for theallowed_client_ids
definition)_verify_signed_jwt_with_certs
By default the code only checks
_DEFAULT_CERT_URI
, which obviously causes Firebase, and Service Account, tokens to fail to validate. To remedy this, I modified the code to retrieve theaud
(audience) value fromtoken_body
and used this to lookup the correctcert_uri
for each token type.Complete Function Reference
endpoints/user_id_token.py
The text was updated successfully, but these errors were encountered: