Sha256: 53bdff7d11b24857e5b914544654f04b6311aa07b26472181c12b1a9c343d42d

Contents?: true

Size: 803 Bytes

Versions: 23

Compression:

Stored size: 803 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.credentials.secret_key_base)

      render json: { token: token }
    end
  end
end

Version data entries

23 entries across 23 versions & 4 rubygems

Version Path
motor-admin-0.4.34 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.4.33 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.4.32 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.4.31 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.4.30 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.4.29 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.4.28 app/controllers/motor/auth_tokens_controller.rb
motor-admin-cstham8-0.4.35 app/controllers/motor/auth_tokens_controller.rb
motor-admin-cstham8-0.4.34 app/controllers/motor/auth_tokens_controller.rb
motor-admin-cstham8-0.4.33 app/controllers/motor/auth_tokens_controller.rb
motor-admin-cstham8-0.4.32 app/controllers/motor/auth_tokens_controller.rb
motor-admin-cstham8-0.4.31 app/controllers/motor/auth_tokens_controller.rb
motor-admin-cstham8-0.4.30 app/controllers/motor/auth_tokens_controller.rb
motor-admin-cstham8-0.4.29 app/controllers/motor/auth_tokens_controller.rb
motor-admin-cstham8-0.4.28 app/controllers/motor/auth_tokens_controller.rb
motor-admin-cstham8-0.4.27 app/controllers/motor/auth_tokens_controller.rb
motor-admin-0.4.27 app/controllers/motor/auth_tokens_controller.rb
motor-admin-unosquare-0.4.28 app/controllers/motor/auth_tokens_controller.rb
motor-admin-unosquare-0.4.27 app/controllers/motor/auth_tokens_controller.rb
motor-admin-pz-0.4.26 app/controllers/motor/auth_tokens_controller.rb