-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Generating many client tokens #210
Comments
Did you try this in your initializer :
|
SQL (0.5ms) UPDATE "users" SET "tokens" = $1, "updated_at" = $2 WHERE "users"."id" = $3 [["tokens", "{"Q4g1PZrCdBb18Ndxxli55A":{"token":"$2a$10$7BLPPqKnPCNiBZ.O8uWIkOELtUak88RO9lFhIKdex7AjI2RqrsH7K","expiry":1433030748},"EwsS1phl1A9_plCI02eB7w":{"token":"$2a$10$5xgFolVXRhtzYKKE2lIccO2ytgc65gVQN74JS2hYBUw72.bZgW7vS","expiry":1433030766},"93fuGltfv8LO3-2_g3RF2Q":{"token":"$2a$10$qD4NdH0yaLA4AXORuCZ59eyHzyL/bqKKvDjjKlvN3iMbw.rGZKbhO","expiry":1433030814},"8_SQvQe5zq-ICJa1e-biYw":{"token":"$2a$10$DqlURiArR8n.L6Xrv3bs2.fIj/WYqdhU3UsUCKaca6VK8HhijfnSa","expiry":1433030826},"oCThb8B-epVt5A2aOWKStA":{"token":"$2a$10$FaqquEXhCy5dxaGUFdxnxOHdIp5mqvJgKbaYpXUw/j5ptVXmAd7XG","expiry":1433030837},"OlQ-X6i5wXbTGHHgj5ceuw":{"token":"$2a$10$FjMZg4GykcJUVxqAv4FayuaLsul5cgljmEkAgDja6UKlpvDWP0jMG","expiry":1433030858},"DUqK_RA5dGLVq-cRY1Dnhg":{"token":"$2a$10$MA9SWeut0G1pBK6jwAfRTevwES/uh.tsh5gdQFof0b2sHuvcAKfu6","expiry":1433030870},"eY5gn1JuHfle4bI8wOddyQ":{"token":"$2a$10$qshqJ2s2PdSdD2JstZtq.uBckvOLhOnqlwRdWXobXENMN.yS6bkjK","expiry":1433031039,"last_token":"$2a$10$INZb8EVrslHc/af4W6UoSuR83yKpcdmEqkEWb5CN04v96RGgupRXW","updated_at":"2015-05-17T08:10:39.643+08:00"}}"], ["updated_at", "2015-05-17 00:10:39.646659"], ["id", 1]] Stil have so many tokens while sign in. |
Well, I can see many implementation to solve this:
|
The |
I'm aware of this behavior, but I think we need a way to handle this to avoid generating too many tokens who are not used. Can we modify Devise trackable capability to update a key in the token ? With something like "last_used" and delete useless token ? Or maybe it's already implemented thanks to "expiry" ? |
The tokens will be removed after they have expired, or updated if they are still in use. It looks like @qx has around 8 tokens - I don't think that's a cause for concern. And they will be removed once they expire. |
It can be an issue when you don't want your token to expiry and you set I'm not in this situation, but 8 tokens seems to be big for a single user On Mon, May 18, 2015 at 5:24 PM Lynn Dylan Hurley [email protected]
|
Right, but if the expiration is set to There should only be one token per connected device. If this is not the case, then there is something else going on with the client. @npearson72 and @qx - I think this issue is related to lynndylanhurley/ng-token-auth#119. I'll push a fix tonight. |
There's no way to identify a device uniquely. I can login 20 times on the
|
The tokens should be destroyed after logout. Are you saying that is not the case? |
Yes, is it the case. But on an iOS device you can ask your user to log in IMO, this is not a problem, but it seems to be a problem for some people. I
|
@lynndylanhurley Do you means this setting"#config.token_lifespan = 2.weeks" in devise_token_auth.rb, the the tokens will be removed after 2.weeks, or logout manual? If so,this problem will not be serious. |
@qx - that is correct. Most users will only connect with 1 or 2 devices, and so they will only have a few tokens max.
@nicolas-besnard - could this be solved by re-using the same |
This can be a solution, but the |
If they're already signed in, I think the |
Could be useful, but if you open your API to external developer, they won't On Tue, May 19, 2015 at 5:52 PM Lynn Dylan Hurley [email protected]
|
Can you elaborate on this please? |
I found that I have 192 tokens.... not sure how this is happening. How does ng-token-auth detect a unique client? A possibility is that I am building an ionic / cordova app. I'm wondering if it could be that everytime I create a new build, it's registering as a new client even though it's the same phone? (I guess it would view each build as a different browser?) I have my token expiry time to be large (essentially infinite) since I don't want a mobile user to have to re-login (just as in the case of a native app). |
I wonder...is there a way to customize expiry times depending on the type of client? e.g. if it's a mobile client, then I would have an infinite expiry time, but if it's a web client, then expire it after a finite time? |
I think I know what's happening now. With a hybrid app (e.g. using Ionic / Cordova), you have a native app with a WebView inside. Every time you launch the app, it is registered as a new client since there is essentially a new browser instance that is loaded within the app. Any ideas for workarounds? For example, would it be possible for me to save the clientID in some native storage and then use that clientID on initial app launch? |
I was having the same problem in my rails based api which is using this gem. The api client was using the angular counterpart, and some of its requests (for some reason I don't know yet) were arriving with 'client' header not set. Everytime it happened a new auth token were created, just like @qx commented. After some requests, I was getting a database error saying that my tokens column had reached the size limit. I think that if the the request 'client' header is empty (this could be a client's mistake) a new client token should be created/updated with client_id = 'default', thus avoiding the creation of unecessary tokens. I've already done this change in my fork. If you guys think that this makes sense for you, I would be glad to make a pull request. |
@paulosoares86 - i'd definitely be interested if you or anyone else were able to isolate the client-side issue in ng-token-auth, but I agree that we shouldn't be able to DOS the service due to unnecessary token creation. I'd be interested in seeing that PR if you'd like to put it together. |
@booleanbetrayal, can this issue be marked as closed because PR #434 ? |
I think so, yes. Thanks @paulosoares86 |
I apologize for the cross-post, but I'm not sure if the problem I'm experiencing is related to this gem or it's angular library counterpart (or my improper implementation), but I've posted my issue here also:
lynndylanhurley/ng-token-auth#140
What I'm seeing is that when I close the browser while logged in, and I then open the browser and log back into my app, it generates a new client token.
This causes many client tokens to be generated.
Is anyone else experiencing something like this? Any ideas on how to prevent this?
The text was updated successfully, but these errors were encountered: