Lumen-jwt<\/a>\u00a0is a great library that easily adds JavaScript Web Token<\/a>\u00a0(JWT) authentication to any Lumen<\/a> application. I recently had the opportunity to submit my second pull request to the project<\/a>, allowing user accounts to be uniquely identified via fields other than There is now a key called So if the primary key field in your user table is My original use case for this feature was to allow using hashids<\/a>\u00a0to identify users without exposing database ids publicly. If an alternative unique id field such as this is persisted in your user model then you’re already done.<\/p>\n Another option is for the hashids to be computed properties, calculated via Eloquent mutators<\/a>\u00a0whenever a user instance is loaded. The down side to this approach is that there isn’t a straightforward method for retrieving the model corresponding to a given hashid. Instead, you can write a custom user provider<\/a> to decode the hashid before retrieving the user\u2015that will be the subject of a future post.<\/p>\n","protected":false},"excerpt":{"rendered":" Lumen-jwt\u00a0is a great library that easily adds JavaScript Web Token\u00a0(JWT) authentication to any Lumen application. I recently had the opportunity to submit my second pull request to the project, allowing user accounts to be uniquely identified via fields other than id, which was previously the only option. (As of this writing the PR has been … [Read more…]<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[11,10,8],"_links":{"self":[{"href":"https:\/\/www.munderwood.ca\/index.php\/wp-json\/wp\/v2\/posts\/195"}],"collection":[{"href":"https:\/\/www.munderwood.ca\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.munderwood.ca\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.munderwood.ca\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.munderwood.ca\/index.php\/wp-json\/wp\/v2\/comments?post=195"}],"version-history":[{"count":5,"href":"https:\/\/www.munderwood.ca\/index.php\/wp-json\/wp\/v2\/posts\/195\/revisions"}],"predecessor-version":[{"id":200,"href":"https:\/\/www.munderwood.ca\/index.php\/wp-json\/wp\/v2\/posts\/195\/revisions\/200"}],"wp:attachment":[{"href":"https:\/\/www.munderwood.ca\/index.php\/wp-json\/wp\/v2\/media?parent=195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.munderwood.ca\/index.php\/wp-json\/wp\/v2\/categories?post=195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.munderwood.ca\/index.php\/wp-json\/wp\/v2\/tags?post=195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}id<\/code>, which was previously the only option. (As of this writing the PR has been approved, but not yet merged.)<\/p>\n
JWT_ID_FIELD<\/code>\u00a0that can optionally be added to a project’s
.env<\/code> file to specify the name of the field that should be used to look up and uniquely identify users. The default is of course
id<\/code>, so any existing applications that don’t specify a value will continue to work without any changes.<\/p>\n
user_id<\/code>,\u00a0
username<\/code>, or indeed anything else, then using lumen-jwt is straightforward:<\/p>\n
# Specify accounts should be looked up by username\r\nJWT_ID_FIELD=username<\/pre>\n