Module: Authpwn::UserExtensions::ApiTokenField

Extended by:
ActiveSupport::Concern
Defined in:
lib/authpwn_rails/user_extensions/api_token_field.rb

Overview

Augments the User model with a password virtual attribute.

Instance Method Summary collapse

Instance Method Details

#api_tokenObject

The code from the user’s API token credential.

Creates an API token if the user doesn’t already have one.



22
23
24
25
# File 'lib/authpwn_rails/user_extensions/api_token_field.rb', line 22

def api_token
  credential = self.api_token_credential || Tokens::Api.random_for(self)
  credential.code
end

#api_token_credentialObject

Credentials::Password instance associated with this user.



15
16
17
# File 'lib/authpwn_rails/user_extensions/api_token_field.rb', line 15

def api_token_credential
  credentials.find { |c| c.instance_of?(Tokens::Api) }
end