ruby-on-railsdoorkeeper

Checkbox scopes in doorkeeper


I want to allow users to select scopes from a checkbox list. I've setup the form like so:

  <%= f.label :scopes, class: 'col-sm-2 control-label' %>
    <% Doorkeeper.configuration.scopes.each do |scope| %>
      <%= check_box_tag("doorkeeper_application[scopes][#{scope}]", scope, @application.scopes.include?(scope)) %>
      <%= scope %><br>
    <% end %>
  <% end %>

which produces

image

doorkeeper_application[scopes] is accepted by Oauth::ApplicationsController. While users should be able to select multiple scopes, parameters like doorkeeper_application[scopes][foo] are not accepted.

What's the best practice for passing these params to the controller? Or is there a better practice to achieve checkboxed scopes in Doorkeeper?


Solution

  • According to the OAuth2 specification, multiple scopes should be joined by space characters. So you should get the names of the checked scopes from params, join them with a space " ", and assign that single value as the doorkeeper_application[scopes] value.