module Jm81auth::Models::AuthMethod

Public Class Methods

included(base) click to toggle source
# File lib/jm81auth/models/auth_method.rb, line 4
def self.included(base)
  base.extend ClassMethods

  base.class_eval do
    if respond_to? :belongs_to
      belongs_to :user
      has_many :auth_tokens
    else
      many_to_one :user
      one_to_many :auth_tokens
    end
  end
end

Public Instance Methods

create_token(access_token: nil) click to toggle source

Create AuthToken, setting user and last_used_at, and optionally access_token from the Oauth provider.

@return [AuthToken]

# File lib/jm81auth/models/auth_method.rb, line 22
def create_token access_token: nil
  auth_token = ::AuthToken.new
  auth_token.auth_method = self
  auth_token.user = user
  auth_token.last_used_at = Time.now.utc

  if auth_token.respond_to? :access_token=
    auth_token.access_token = access_token
  end

  auth_token.save
  auth_token
end