-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Allow tokens with eternal TTL (value -1) #2841
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
Conversation
- Add a new User setting 'allowEternalTokens' - Enhance 'AccessToken.validate' to support eternal tokens with ttl value -1 when the user model allows it.
ritch
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
How to set allowEternalTokens = true? It is success to add "allowEternalTokens : true" inside options in node_modules/loopback/common/models/user.json, but it fail when add into common/models/user.json. |
|
@josephlaw you should create a new model inheriting from the built-in User model. Then you can change the setting in |
|
@bajtos Any idea why User is undefined in my previous message? |
Not really |
|
It's not passing the validation for me, I have a custom JSON model inherited from built-in model User. "name": "empresa",
"base": "User",
"idInjection": true,
"options": {
"validateUpsert": true,
"allowEternalTokens": true
}The User is defined but |
|
@brilvio have you updated the configuration of your @crandmck Google query loopback custom accesstoken model returns the mentioned blog post as the first result, it looks like we may not have this use case documented on loopback.io. Could you PTAL? |
|
@bajtos tried to do what is in the link, new custom model inherited of "relations": {
"empresa": {
"type": "belongsTo",
"model": "empresa",
"foreignKey": "userId"
}
}Setting the same relation on the |
|
@brilvio I am afraid I have run out of easy answers. Please open a new issue, provide a sample app reproducing the problem (see http://loopback.io/doc/en/contrib/Reporting-issues.html#bug-report) and include a link to this discussion (#2841) in issue's description. |
|
Thank you for your time. I will do that. |
|
Added it to the reference http://loopback.io/doc/en/lb3/Model-definition-JSON-file.html#advanced-options but we need a more thorough explanation, too. |
|
@Shyri In my configuration I have extended both the User and AccessToken and I have verified that this feature works. Here are my settings: As you can see I have extended both User and AccessToken Model, now when the function AccessToken.prototype.validate is called, User.settings.allowEternalTokens returns true. Without extending AccessToken, User.settings.allowEternalTokens returns false because the AccessToken model is not related to the extended user model where the property allowEternalTokens is set. @crandmck should the documentation be updated? |
Yes please. Would you mind contributing this patch yourself, @jdhrivas? See http://loopback.io/doc/en/contrib/doc-contrib.html to get started. |
|
@bajtos sure I can. This time I'll take a look at the guidelines before any pull request. |
|
Awesome! Please make a note in loopbackio/loopback.io#200 when you open a PR... thanks. |
|
You can also add this line in the boot folder if you don't want to create a custom AccessToken model, I tried this and it definitely does the trick. User.settings.allowEternalTokens = true; |
|
@IbrahimAmin Thanks, this works, but I still had to create a "belongsTo" relationship for the AccessToken model :
Keep in mind, that if you have included |
|
Thank you @Legited for the instructions. FWIW, we have updated the documentation for setting up custom user/token models, see http://loopback.io/doc/en/lb3/Authentication-authorization-and-permissions.html#preparing-access-control-models. There is no need to manipulate AccessToken relations in a boot script, the relation can be re-configured via |
|
Thanks, setting up relations in the model-config worker for me |

allowEternalTokensAccessToken.validate()to support eternal tokens with ttl value -1 when the user model allows it.This patch supersedes #1797.
@ritch please review