0

I have a User entity, which may have a RefreshToken (for authentication).

Notes:

  • A refresh token doesn't have "identity", but is related to a single user - it is only valid for that user. In the db that means a foreign key to users table. In Entity Framework I can however model it as an "owned" type so that it's part of the users table.
  • A refresh token can be revoked, i.e. deleted from the database
  • A refresh token can be renewed - at the domain level that means replacing the old with a new one, but at the db level that means simply updating the existing record (unless it's an "owned" type in which case I'll update the user record)

So, is the RefreshToken an entity or a value object?

  • Why do you think the token does not have an identity? Doesn't it have some kind of ID? – user330854 May 22 at 7:50
  • @LutzHorn Like I typed above, it is related to the user via an FK. But if I model it as an "owned" type then it won't even need that and won't have any identity. – lonix May 22 at 7:51
  • 1
    @LutzHorn The token itself may be an identifier, but I wouldn't think of it as having an identity of its own, unless it has attributes that change over time (which is not the case here since OP is replacing old tokens with new ones). – casablanca May 22 at 7:59
4

The refresh token is solely defined by its values. And there is no continuity of the object when the values change, because it would be replaced by a new token. This is why it is a value object.

This does not prevent that one of the value refers to a given user-id, which gives the impression of continuity between successive values. But it is not sufficient to make it an entity.

Worthwhile to note: tokens are designed for a value semantic, because once they are issued, they are copied and sent across the net to systems that may not have access to the original source, and using protocols that do not allow update.

P.S: if the refresh token would be an entity, it would be called “token”, and could have a state “refreshed token”. And then it would not be replaced by a new token, but updated.

  • Yeah that's a good analysis, thanks Christophe! – lonix May 22 at 7:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.