Class: Admin::DeviceAuthorizationsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/admin/device_authorizations_controller.rb

Constant Summary collapse

EXPIRES_IN =
10.minutes
INTERVAL =
5

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#device_authorizationObject (readonly)

Returns the value of attribute device_authorization.



13
14
15
# File 'app/controllers/admin/device_authorizations_controller.rb', line 13

def device_authorization
  @device_authorization
end

Instance Method Details

#createObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/admin/device_authorizations_controller.rb', line 21

def create
  device_authorization, device_code = Admin::DeviceAuthorization.issue!(
    requested_ip: request.remote_ip,
    user_agent:   request.user_agent,
  )

  render json: {
    device_code:,
    user_code:                 device_authorization.user_code,
    verification_uri:          admin_device_authorization_url(device_authorization.user_code),
    verification_uri_complete: admin_device_authorization_url(device_authorization.user_code),
    expires_in:                EXPIRES_IN.to_i,
    interval:                  INTERVAL,
  }
end

#showObject



17
18
19
# File 'app/controllers/admin/device_authorizations_controller.rb', line 17

def show
  render locals: { device_authorization: }
end

#updateObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/admin/device_authorizations_controller.rb', line 37

def update
  if device_authorization.actionable?
    case params[:decision]
    when "approve"
      device_authorization.approve!(admin_user:)
    else
      device_authorization.deny!(admin_user:)
    end

    redirect_to(admin_device_authorization_path(device_authorization.user_code), status: :see_other)
  else
    render(:show, status: :unprocessable_content, locals: { device_authorization: })
  end
end