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.3.13 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.3.12 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.3.11 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.3.10 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.3.9 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.3.8 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.3.7 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.3.6 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.3.5 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.3.4 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.3.3 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.3.2 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.3.1 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.3.0 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.2.89 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.2.88 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.2.87 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.2.86 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.2.85 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.2.84 app/controllers/motor/auth_tokens_controller.rb