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

Add Apple JWT Token based authentication #43

Merged
merged 2 commits into from Sep 26, 2017
Merged

Conversation

sideshow
Copy link
Owner

@sideshow sideshow commented Sep 28, 2016

Work in progress for the purpose of gathering feedback on the API

  • Needs tests

@coveralls
Copy link

coveralls commented Sep 28, 2016

Coverage Status

Coverage decreased (-15.6%) to 70.833% when pulling 892c8a4 on feature-auth-token into 741a20d on master.

@vivangkumar
Copy link

Nice! I think the changes are simple and easy to understand! The API hasn't changed significantly either, a new method to get a client based on Token is as simple as it can get. I can look into helping out with the tests, however, it does depend on how much time I get :(

@vivangkumar
Copy link

@sideshow Any idea when this will be merged in?

@sideshow
Copy link
Owner Author

Within the next week hopefully! Just adding some tests.

@xjewer
Copy link
Contributor

xjewer commented Nov 1, 2016

Within the next week hopefully! Just adding some tests.

Do you have some news about tests? 😀

@coveralls
Copy link

coveralls commented Nov 2, 2016

Coverage Status

Coverage decreased (-2.5%) to 87.118% when pulling 59dc349 on feature-auth-token into e42f05d on master.

@coveralls
Copy link

coveralls commented Nov 3, 2016

Coverage Status

Coverage increased (+1.7%) to 91.304% when pulling 40fc7ef on feature-auth-token into e42f05d on master.

@sideshow sideshow changed the title [WIP] Add Apple JWT Token based authentication Add Apple JWT Token based authentication Nov 10, 2016
@coveralls
Copy link

coveralls commented Nov 10, 2016

Coverage Status

Coverage increased (+1.7%) to 91.304% when pulling 7f17f3a on feature-auth-token into e42f05d on master.

@vivangkumar
Copy link

@sideshow Tests look 👌 I expect this will be merged soon, then? If you want a final review or would like me to look at anything in particular, I'm happy to help!

@sideshow
Copy link
Owner Author

sideshow commented Nov 10, 2016

Thanks @vivangkumar

Yeah it's close. Two things i would appreciate help with;

  1. Running it in production. I have done so but would be good for others to check before we merge into master.
  2. I'm not too happy with the way we check every push if the token is expired and was considering changing to catch the 403 from apple and regenerate then instead, So any input/thoughts round this would be great https://github.com/sideshow/apns2/blob/feature-auth-token/client.go#L156

And of course anything else i've missed :)

@xjewer
Copy link
Contributor

xjewer commented Nov 11, 2016

I'm not too happy with the way we check every push if the token is expired and was considering changing to catch the 403 from apple and regenerate then instead, So any input/thoughts round this would be great https://github.com/sideshow/apns2/blob/feature-auth-token/client.go#L156

You also can change to catch the 403 from apple and add the autogenerator to update token before expiration. So it will call token.Generate on each time.Tick

@sideshow sideshow mentioned this pull request Nov 13, 2016
@knousere
Copy link

knousere commented Nov 26, 2016

We have been running in production for a year and a half using the legacy apns against multiple app targets. Not high volume but high variability. We already use dgrijalva/jwt-go for other authentication purposes. We most eagerly await your release of token based authentication. We are willing to be production test agents for you.
The connection must be fail-safe unattended. Recovery must be automatic. Anything that can be done locally should be done locally.
According to Apple documentation, a token expires after an hour.
Checking should proceed in the following order: 1. Is the token nearing expiration? (Creation time should be locally cached. Caching can be a user responsibility. Near should be a user settable parameter) 2. Catch the 403 from Apple as a safety. Apple does things for their own reasons, so sanity can not be assumed.
I always wrap connections with Apple in an object so that anything that needs to be cached is not globally accessible. I open multiple sockets per connection, and process everything asynchronously via channels so would find the 403 disruptive as it might cause redundant recovery efforts.

@sideshow
Copy link
Owner Author

sideshow commented Dec 17, 2016

I have run into the same issue as @nathany did in his buford library golang/go#13774

We need to find a decent enough workaround to this issue golang/go#13774 before I can merge this.

The problem is that Apple for some reason send a MAX_CONCURRENT_STREAMS=1 at the start which means they are limiting to one stream only. After you have sent one push they update the setting with MAX_CONCURRENT_STREAMS=500.

The problem is that if you send a second push notification (which opens another stream) before they have adjusted the setting, it will result in errors.

And unfortunately because the http2 transport doesn't yet respect the MAX_CONCURRENT_STREAMS we don't have a decent way to pause or lock until we are allowed to send.

I have tested this on the development and production APNs gateways and the same happens for both.

@mitkodev
Copy link

hey, just checking, what is the status of this pull request?

@nathany
Copy link

nathany commented Jan 23, 2017

@ddimitrov90 We are blocked on not having access to the number of allowed concurrent streams sent from Apple. That's going to require some work on Go's x/net/http2 library, which will first require learning how it works. So it's a ways off 😦

"The problem is that Apple for some reason send a MAX_CONCURRENT_STREAMS=1"

The reason is to do with authentication:

"When you connect to APNs without a client certificate, the connection is essentially unauthenticated until APNs receives a push with a token authenticating the provider. This is why the connection is limited to a single stream initially." - Mayur Mahajan, Apple

It makes sense, it's just makes the API somewhat difficult to work with.

@coveralls
Copy link

coveralls commented Jul 11, 2017

Coverage Status

Coverage increased (+1.6%) to 91.543% when pulling b2315eb on feature-auth-token into 7588e8f on master.

@nordicdyno
Copy link

appleboy/gorush#247 (comment)

@sideshow My pardon, but code that works for most cases until it's not – it sounds very dangerous for me. Personally, I think the merge of this code is a trap for newcomers and their production environments.

@luismfonseca
Copy link
Contributor

So, this has been merged and is now part of the master branch golang/net@1c05540.

@sideshow, how does that affect this ticket?

@felipejfc
Copy link

@sideshow any updates here?

@sideshow
Copy link
Owner Author

@nordicdyno I agree with you, it would be a trap and would be painful to explain. Decided against it in the end.

@luismfonseca @felipejfc - Cool good to see progress. I'm not sure if this gets us all the way there but will try it out later this week to determine exactly what we need to do.

@sideshow
Copy link
Owner Author

sideshow commented Aug 23, 2017

@luismfonseca @felipejfc
Thanks, i was able to check this branch and can confirm it fixes the issue.
We are close. The only outstanding thing is that golang/net@1c05540 modifies the golang connection pool so that it blocks and doesnt dial a new connection. This is good in terms of fixing the above problem, however may have negative implications on throughput. Trying to evaluate this over the coming week before i merge.

@ehsannm
Copy link

ehsannm commented Sep 2, 2017

@sideshow why you don't merge master with the Key Auth ?!

@Xzya
Copy link

Xzya commented Sep 21, 2017

Any update on this? Thanks!

@sideshow sideshow force-pushed the feature-auth-token branch 2 times, most recently from f26d6f5 to 2cf793a Compare September 26, 2017 04:56
@coveralls
Copy link

Coverage Status

Coverage increased (+1.5%) to 91.667% when pulling 2cf793a on feature-auth-token into d8025ed on master.

Repository owner deleted a comment from coveralls Sep 26, 2017
Repository owner deleted a comment from coveralls Sep 26, 2017
Repository owner deleted a comment from coveralls Sep 26, 2017
Repository owner deleted a comment from coveralls Sep 26, 2017
@coveralls
Copy link

coveralls commented Sep 26, 2017

Coverage Status

Coverage increased (+1.5%) to 91.667% when pulling 3afa5a2 on feature-auth-token into d8025ed on master.

@coveralls
Copy link

coveralls commented Sep 26, 2017

Coverage Status

Coverage increased (+1.5%) to 91.667% when pulling 8d55eb2 on feature-auth-token into d8025ed on master.

@sideshow sideshow merged commit a3ce9c6 into master Sep 26, 2017
@sideshow
Copy link
Owner Author

Finally merged!! Have tested this on production and development gateways and it no longer returns errors as it was before.

cc/ @vivangkumar @xjewer @ddimitrov90 @nordicdyno @luismfonseca @felipejfc @ehsannm @Xzya

@sideshow sideshow deleted the feature-auth-token branch September 26, 2017 09:42
@felipejfc
Copy link

Awesome @sideshow!

Thanks!

@alissonsales
Copy link
Collaborator

💃

@nathany
Copy link

nathany commented Dec 1, 2018

FYI

https://go-review.googlesource.com/c/net/+/151857/ "http2: revert Transport's strict interpretation of MAX_CONCURRENT_STREAMS"

golang/go#27753

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.

None yet