Skip to content

Support hashed tokens #300

@jeremywadsack

Description

@jeremywadsack

This is related to #217 but I thought it was worth a separate discussion.

I'd like to have a callback that lets me add more security around token storage. As the token is effectively a password, I'd like to be able to one-way hash it.

I think the easiest implementation for that would be to create a custom TokenComparator that hashes the provided token before comparing to the stored one. But currently SimpleTokenAuthentication :: TokenAuthenticationHandler#token_comparator is private.

Additionally, I would add some before_save handler that happens after the token is created (although see my comments on #292). That would be where I'd add my hashing logic. I can add that to the model myself, by adding after acts_as_token_authenticatable, so it may not need to be a hook, just a documented example to show how to do it.

But I feel that this should be a strategy that simple_token_authentication includes. That is, a configuration option:

class User < ActiveRecord::Base
  acts_as_token_authenticatable hashed_token: true

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestThis issue requests a new feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions