Sha256: 83bbb40ab7ea872f9c035329c8f953182ec03b07b2dd1724be965bc5de915248

Contents?: true

Size: 799 Bytes

Versions: 181

Compression:

Stored size: 799 Bytes

Contents

# frozen_string_literal: true

module Motor
  class AuthTokensController < ApiBaseController
    GENERIC_TOKEN_TTL = 2.hours

    skip_authorization_check

    def create
      return render json: {} unless current_user

      if defined?(Devise::JWT)
        respond_with_devise_jwt
      elsif defined?(JWT)
        respond_with_generic_jwt
      else
        render json: {}
      end
    end

    private

    def respond_with_devise_jwt
      warden.set_user(current_user)

      render json: { token: request.env['warden-jwt_auth.token'] }
    end

    def respond_with_generic_jwt
      payload = { uid: current_user.id, exp: GENERIC_TOKEN_TTL.from_now.to_i }
      token = JWT.encode(payload, Rails.application.secrets.secret_key_base)

      render json: { token: token }
    end
  end
end

Version data entries

181 entries across 181 versions & 5 rubygems

Version Path
motor-admin-0.4.23 app/controllers/motor/auth_tokens_controller.rb
motor-admin-pz-0.4.22 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.4.22 app/controllers/motor/auth_tokens_controller.rb
motor-admin-pz-0.4.21 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.4.21 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.4.20 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.4.19 app/controllers/motor/auth_tokens_controller.rb
motor-admin-pz-0.4.18.1 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.4.18 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.4.17 app/controllers/motor/auth_tokens_controller.rb
motor-alexandermohan-admin-panel-0.4.161 app/controllers/motor/auth_tokens_controller.rb
alexandermohan-admin-panel-0.4.161 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.4.16 app/controllers/motor/auth_tokens_controller.rb
motor-admin-pz-0.4.14 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.4.15 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.4.14 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.4.13 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.4.12 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.4.11 app/controllers/motor/auth_tokens_controller.rb
motor-admin-pz-0.4.10 app/controllers/motor/auth_tokens_controller.rb