Hi ,I am working on a Swift based server (vapor) to connect to Firebase. Since Firebase does not support server-side Swift SDK at the moment, I have decided use the REST API. However, as a mediocre programmer, I have found the documentation difficult to follow on how to exactly authenticate using JWT 3rd party libraries. Specifically this part:
- "Finally, ensure that the ID token was signed by the private key corresponding to the token's kid claim. Grab the public key fromhttps://www.googleapis.com/robot/v1/metadata/x509/secureto...@system.gserviceaccount.com and use a JWT library to verify the signature. Use the value of max-age in the Cache-Controlheader of the response from that endpoint to know when to refresh the public keys" (https://firebase.google.com/docs/auth/admin/verify-id-tokens)
Would it be possible to get a 'dummy' proof end-to-end example on how to do these steps? I have searched all over and can't figure it out. Any help would be greatly appreciate it.
--Thank You
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/d8933429-4637-4165-881c-7f2655a3b969%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hey there,I am not a Swift developer, but I did write those docs and can try my best to help get you unblocked. As noted in the docs, you'll have to use a third-party JWT library. One I found for Swift that supports the encryption algorithm we use is called JSONWebToken. You are going to want to look at the RSASSA-PKCS1-v1_5 Signature > Verify section to see an example of how to take a token, a public key, and a hash algorithm to see if the token was signed by public key's associated private key (that is, the token was minted by Firebase). Instead of .SHA256 in the code sample, you are going to want to use .RSA256 (both of those are just different types of encryption algorithms; as the docs mention, Firebase uses RSA 256).
As far as what to use for the public key, you need to fetch it from https://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com as the docs suggest. I'm not sure how to do this in Swift, but there should be a built-in primitive to fetch the contents of a URL in Swift. Instead of making a request to get this data every time you want to validate an ID token, you can cache the requested data. However, we do rotate keys fairly often and you should not cache them for too long or else they may become expired. That is why the docs mention looking at the Cache-Control header to know how long before you should make a new request to the public keys URL.
If it helps, you can check out the implementation of how we do this in the Admin Node.js SDK here. That is compiled JavaScript and is not our source code, but it might give you an idea of what you need to do. Just search for "verifyIdToken" on that page to see where the implementation starts.If you still can't figure things out, I will see if I can get someone on the Firebase team with more Swift experience to help you out further. Hopefully you have enough information to get unstuck though!Cheers,
Jacob
On Tue, Jan 31, 2017 at 5:27 PM, miamiHeat4life <ezeq...@gmail.com> wrote:
Hi ,I am working on a Swift based server (vapor) to connect to Firebase. Since Firebase does not support server-side Swift SDK at the moment, I have decided use the REST API. However, as a mediocre programmer, I have found the documentation difficult to follow on how to exactly authenticate using JWT 3rd party libraries. Specifically this part:
- "Finally, ensure that the ID token was signed by the private key corresponding to the token's kid claim. Grab the public key fromhttps://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com and use a JWT library to verify the signature. Use the value of max-age in the Cache-Controlheader of the response from that endpoint to know when to refresh the public keys" (https://firebase.google.com/docs/auth/admin/verify-id-tokens)
Would it be possible to get a 'dummy' proof end-to-end example on how to do these steps? I have searched all over and can't figure it out. Any help would be greatly appreciate it.
Thank You
--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
Hey there,I am not a Swift developer, but I did write those docs and can try my best to help get you unblocked. As noted in the docs, you'll have to use a third-party JWT library. One I found for Swift that supports the encryption algorithm we use is called JSONWebToken. You are going to want to look at the RSASSA-PKCS1-v1_5 Signature > Verify section to see an example of how to take a token, a public key, and a hash algorithm to see if the token was signed by public key's associated private key (that is, the token was minted by Firebase). Instead of .SHA256 in the code sample, you are going to want to use .RSA256 (both of those are just different types of encryption algorithms; as the docs mention, Firebase uses RSA 256).
As far as what to use for the public key, you need to fetch it from https://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com as the docs suggest. I'm not sure how to do this in Swift, but there should be a built-in primitive to fetch the contents of a URL in Swift. Instead of making a request to get this data every time you want to validate an ID token, you can cache the requested data. However, we do rotate keys fairly often and you should not cache them for too long or else they may become expired. That is why the docs mention looking at the Cache-Control header to know how long before you should make a new request to the public keys URL.
If it helps, you can check out the implementation of how we do this in the Admin Node.js SDK here. That is compiled JavaScript and is not our source code, but it might give you an idea of what you need to do. Just search for "verifyIdToken" on that page to see where the implementation starts.If you still can't figure things out, I will see if I can get someone on the Firebase team with more Swift experience to help you out further. Hopefully you have enough information to get unstuck though!Cheers,
Jacob
On Tue, Jan 31, 2017 at 5:27 PM, miamiHeat4life <ezeq...@gmail.com> wrote:
Hi ,I am working on a Swift based server (vapor) to connect to Firebase. Since Firebase does not support server-side Swift SDK at the moment, I have decided use the REST API. However, as a mediocre programmer, I have found the documentation difficult to follow on how to exactly authenticate using JWT 3rd party libraries. Specifically this part:
- "Finally, ensure that the ID token was signed by the private key corresponding to the token's kid claim. Grab the public key fromhttps://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com and use a JWT library to verify the signature. Use the value of max-age in the Cache-Controlheader of the response from that endpoint to know when to refresh the public keys" (https://firebase.google.com/docs/auth/admin/verify-id-tokens)
Would it be possible to get a 'dummy' proof end-to-end example on how to do these steps? I have searched all over and can't figure it out. Any help would be greatly appreciate it.
Thank You
--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
Hi,Would it be possible to get someone on the Firebase team with more Swift experience to help you out further?
Thanks
On Tuesday, January 31, 2017 at 9:09:50 PM UTC-5, Jacob Wenger wrote:
Hey there,I am not a Swift developer, but I did write those docs and can try my best to help get you unblocked. As noted in the docs, you'll have to use a third-party JWT library. One I found for Swift that supports the encryption algorithm we use is called JSONWebToken. You are going to want to look at the RSASSA-PKCS1-v1_5 Signature > Verify section to see an example of how to take a token, a public key, and a hash algorithm to see if the token was signed by public key's associated private key (that is, the token was minted by Firebase). Instead of .SHA256 in the code sample, you are going to want to use .RSA256 (both of those are just different types of encryption algorithms; as the docs mention, Firebase uses RSA 256).
As far as what to use for the public key, you need to fetch it from https://www.googleapis.com/robot/v1/metadata/x509/secureto...@system.gserviceaccount.com as the docs suggest. I'm not sure how to do this in Swift, but there should be a built-in primitive to fetch the contents of a URL in Swift. Instead of making a request to get this data every time you want to validate an ID token, you can cache the requested data. However, we do rotate keys fairly often and you should not cache them for too long or else they may become expired. That is why the docs mention looking at the Cache-Control header to know how long before you should make a new request to the public keys URL.
If it helps, you can check out the implementation of how we do this in the Admin Node.js SDK here. That is compiled JavaScript and is not our source code, but it might give you an idea of what you need to do. Just search for "verifyIdToken" on that page to see where the implementation starts.If you still can't figure things out, I will see if I can get someone on the Firebase team with more Swift experience to help you out further. Hopefully you have enough information to get unstuck though!Cheers,
Jacob
On Tue, Jan 31, 2017 at 5:27 PM, miamiHeat4life <ezeq...@gmail.com> wrote:
Hi ,I am working on a Swift based server (vapor) to connect to Firebase. Since Firebase does not support server-side Swift SDK at the moment, I have decided use the REST API. However, as a mediocre programmer, I have found the documentation difficult to follow on how to exactly authenticate using JWT 3rd party libraries. Specifically this part:
- "Finally, ensure that the ID token was signed by the private key corresponding to the token's kid claim. Grab the public key fromhttps://www.googleapis.com/robot/v1/metadata/x509/secureto...@system.gserviceaccount.com and use a JWT library to verify the signature. Use the value of max-age in the Cache-Controlheader of the response from that endpoint to know when to refresh the public keys" (https://firebase.google.com/docs/auth/admin/verify-id-tokens)
Would it be possible to get a 'dummy' proof end-to-end example on how to do these steps? I have searched all over and can't figure it out. Any help would be greatly appreciate it.
Thank You
--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/d8933429-4637-4165-881c-7f2655a3b969%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/f370d846-a28b-43c3-be97-b677b19965b8%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/CADypTEZvCc-Mi9e5%2BNHt8z4g71tS-PmZSzgGJn2w%3DOaCZRNU9w%40mail.gmail.com.