Commit 7836ee6ed1a316a6a0cad99e830f7d1f9903a3e9
Exists in
staging
and in
4 other branches
Merge branch 'fix_oauth' into 'master'
Fix oauth_client and oauth_provider See merge request !990
Showing
15 changed files
with
47 additions
and
33 deletions
Show diff stats
plugins/oauth_client/lib/oauth_client_plugin.rb
| @@ -72,6 +72,7 @@ class OauthClientPlugin < Noosfero::Plugin | @@ -72,6 +72,7 @@ class OauthClientPlugin < Noosfero::Plugin | ||
| 72 | strategy.options.merge! consumer_key: provider.client_id, consumer_secret: provider.client_secret | 72 | strategy.options.merge! consumer_key: provider.client_id, consumer_secret: provider.client_secret |
| 73 | strategy.options.merge! client_id: provider.client_id, client_secret: provider.client_secret | 73 | strategy.options.merge! client_id: provider.client_id, client_secret: provider.client_secret |
| 74 | strategy.options.merge! options | 74 | strategy.options.merge! options |
| 75 | + strategy.options.merge! provider.options | ||
| 75 | 76 | ||
| 76 | request.session[:provider_id] = provider_id | 77 | request.session[:provider_id] = provider_id |
| 77 | } | 78 | } |
plugins/oauth_provider/Gemfile
plugins/oauth_provider/controllers/doorkeeper/application_controller.rb
| @@ -2,7 +2,6 @@ module Doorkeeper | @@ -2,7 +2,6 @@ module Doorkeeper | ||
| 2 | class ApplicationController < ApplicationController | 2 | class ApplicationController < ApplicationController |
| 3 | 3 | ||
| 4 | include Helpers::Controller | 4 | include Helpers::Controller |
| 5 | - helper 'doorkeeper/form_errors' | ||
| 6 | 5 | ||
| 7 | end | 6 | end |
| 8 | end | 7 | end |
plugins/oauth_provider/controllers/public/oauth_provider_plugin_public_controller.rb
| 1 | class OauthProviderPluginPublicController < PublicController | 1 | class OauthProviderPluginPublicController < PublicController |
| 2 | 2 | ||
| 3 | - doorkeeper_for :me | 3 | + before_action :doorkeeper_authorize! |
| 4 | 4 | ||
| 5 | def me | 5 | def me |
| 6 | user = environment.users.find(doorkeeper_token.resource_owner_id) if doorkeeper_token | 6 | user = environment.users.find(doorkeeper_token.resource_owner_id) if doorkeeper_token |
plugins/oauth_provider/db/migrate/20160727164530_add_scopes_to_oauth_applications.rb
0 → 100644
plugins/oauth_provider/views/doorkeeper/applications/_delete_form.html.erb
| 1 | <%- submit_btn_css ||= 'btn btn-link' %> | 1 | <%- submit_btn_css ||= 'btn btn-link' %> |
| 2 | -<%= form_tag [:oauth, application] do %> | 2 | +<%= form_tag oauth_application_path(application) do %> |
| 3 | <input type="hidden" name="_method" value="delete"> | 3 | <input type="hidden" name="_method" value="delete"> |
| 4 | - <%= submit_tag 'Destroy', onclick: "return confirm('Are you sure?')", class: submit_btn_css %> | 4 | + <%= submit_tag _('Destroy'), onclick: "return confirm('#{ _('Are you sure?') }')", class: submit_btn_css %> |
| 5 | <% end %> | 5 | <% end %> |
plugins/oauth_provider/views/doorkeeper/applications/_form.html.erb
| 1 | -<%= form_for [:oauth, application], html: {class: 'form-horizontal', role: 'form'} do |f| %> | 1 | +<% extend Doorkeeper::DashboardHelper %> |
| 2 | +<%= form_for application, url: doorkeeper_submit_path(application), html: {class: 'form-horizontal', role: 'form'} do |f| %> | ||
| 2 | <% if application.errors.any? %> | 3 | <% if application.errors.any? %> |
| 3 | - <div class="alert alert-danger" data-alert> | ||
| 4 | - <p><%= _('Whoops! Check your form for possible errors') %></p> | ||
| 5 | - </div> | 4 | + <div class="alert alert-danger" data-alert><p><%= _('Whoops! Check your form for possible errors') %></p></div> |
| 6 | <% end %> | 5 | <% end %> |
| 7 | 6 | ||
| 8 | <%= content_tag :div, class: "form-group#{' has-error' if application.errors[:name].present?}" do %> | 7 | <%= content_tag :div, class: "form-group#{' has-error' if application.errors[:name].present?}" do %> |
| 9 | - <%= f.label :name, class: 'col-sm-2 control-label', for: 'application_name' %> | 8 | + <%= f.label :name, class: 'col-sm-2 control-label' %> |
| 10 | <div class="col-sm-10"> | 9 | <div class="col-sm-10"> |
| 11 | <%= f.text_field :name, class: 'form-control' %> | 10 | <%= f.text_field :name, class: 'form-control' %> |
| 12 | <%= doorkeeper_errors_for application, :name %> | 11 | <%= doorkeeper_errors_for application, :name %> |
| @@ -14,26 +13,36 @@ | @@ -14,26 +13,36 @@ | ||
| 14 | <% end %> | 13 | <% end %> |
| 15 | 14 | ||
| 16 | <%= content_tag :div, class: "form-group#{' has-error' if application.errors[:redirect_uri].present?}" do %> | 15 | <%= content_tag :div, class: "form-group#{' has-error' if application.errors[:redirect_uri].present?}" do %> |
| 17 | - <%= f.label :redirect_uri, class: 'col-sm-2 control-label', for: 'application_redirect_uri' %> | 16 | + <%= f.label :redirect_uri, class: 'col-sm-2 control-label' %> |
| 18 | <div class="col-sm-10"> | 17 | <div class="col-sm-10"> |
| 19 | <%= f.text_area :redirect_uri, class: 'form-control' %> | 18 | <%= f.text_area :redirect_uri, class: 'form-control' %> |
| 20 | <%= doorkeeper_errors_for application, :redirect_uri %> | 19 | <%= doorkeeper_errors_for application, :redirect_uri %> |
| 21 | <span class="help-block"> | 20 | <span class="help-block"> |
| 22 | <%= _('Use one line per URI') %> | 21 | <%= _('Use one line per URI') %> |
| 23 | - </span> | 22 | + </span> |
| 24 | <% if Doorkeeper.configuration.native_redirect_uri %> | 23 | <% if Doorkeeper.configuration.native_redirect_uri %> |
| 25 | <span class="help-block"> | 24 | <span class="help-block"> |
| 26 | - Use <code><%= Doorkeeper.configuration.native_redirect_uri %></code> for local tests | 25 | + <%= raw _('Use %s to local tests') % "<code>#{ Doorkeeper.configuration.native_redirect_uri }</code>" %> |
| 27 | </span> | 26 | </span> |
| 28 | <% end %> | 27 | <% end %> |
| 29 | </div> | 28 | </div> |
| 30 | <% end %> | 29 | <% end %> |
| 31 | 30 | ||
| 31 | + <%= content_tag :div, class: "form-group#{' has-error' if application.errors[:scopes].present?}" do %> | ||
| 32 | + <%= f.label :scopes, class: 'col-sm-2 control-label' %> | ||
| 33 | + <div class="col-sm-10"> | ||
| 34 | + <%= f.text_field :scopes, class: 'form-control' %> | ||
| 35 | + <%= doorkeeper_errors_for application, :scopes %> | ||
| 36 | + <span class="help-block"> | ||
| 37 | + <%= _('Separate scopes with spaces. Leave blank to use the default scopes.') %> | ||
| 38 | + </span> | ||
| 39 | + </div> | ||
| 40 | + <% end %> | ||
| 41 | + | ||
| 32 | <div class="form-group"> | 42 | <div class="form-group"> |
| 33 | <div class="col-sm-offset-2 col-sm-10"> | 43 | <div class="col-sm-offset-2 col-sm-10"> |
| 34 | <%= f.submit _('Submit'), class: "btn btn-primary" %> | 44 | <%= f.submit _('Submit'), class: "btn btn-primary" %> |
| 35 | - <%= link_to _("Cancel"), oauth_applications_path, :class => "btn btn-default" %> | 45 | + <%= link_to _('Cancel'), oauth_applications_path, :class => "btn btn-default" %> |
| 36 | </div> | 46 | </div> |
| 37 | </div> | 47 | </div> |
| 38 | <% end %> | 48 | <% end %> |
| 39 | - |
plugins/oauth_provider/views/doorkeeper/applications/index.html.erb
| 1 | <div class="oauth-provider"> | 1 | <div class="oauth-provider"> |
| 2 | <div class="page-header"> | 2 | <div class="page-header"> |
| 3 | - <h3><%= link_to _('Oauh Provider'), '/admin/plugin/oauth_provider' %></h3> | 3 | + <h1><%= _('Oauh Provider') %></h1> |
| 4 | </div> | 4 | </div> |
| 5 | 5 | ||
| 6 | <p><%= link_to _('New Application'), new_oauth_application_path, class: 'btn btn-success' %></p> | 6 | <p><%= link_to _('New Application'), new_oauth_application_path, class: 'btn btn-success' %></p> |
| @@ -17,7 +17,7 @@ | @@ -17,7 +17,7 @@ | ||
| 17 | <tbody> | 17 | <tbody> |
| 18 | <% @applications.each do |application| %> | 18 | <% @applications.each do |application| %> |
| 19 | <tr id="application_<%= application.id %>"> | 19 | <tr id="application_<%= application.id %>"> |
| 20 | - <td><%= link_to application.name, [:oauth, application] %></td> | 20 | + <td><%= link_to application.name, oauth_application_path(application) %></td> |
| 21 | <td><%= application.redirect_uri %></td> | 21 | <td><%= application.redirect_uri %></td> |
| 22 | <td><%= link_to _('Edit'), edit_oauth_application_path(application), class: 'btn btn-link' %></td> | 22 | <td><%= link_to _('Edit'), edit_oauth_application_path(application), class: 'btn btn-link' %></td> |
| 23 | <td><%= render 'delete_form', application: application %></td> | 23 | <td><%= render 'delete_form', application: application %></td> |
plugins/oauth_provider/views/doorkeeper/applications/new.html.erb
plugins/oauth_provider/views/doorkeeper/applications/show.html.erb
| @@ -5,13 +5,14 @@ | @@ -5,13 +5,14 @@ | ||
| 5 | <div class="row"> | 5 | <div class="row"> |
| 6 | <div class="col-md-8"> | 6 | <div class="col-md-8"> |
| 7 | <h4><%= _('Application Id:') %></h4> | 7 | <h4><%= _('Application Id:') %></h4> |
| 8 | - | ||
| 9 | <p><code id="application_id"><%= @application.uid %></code></p> | 8 | <p><code id="application_id"><%= @application.uid %></code></p> |
| 10 | 9 | ||
| 11 | <h4><%= _('Secret:') %></h4> | 10 | <h4><%= _('Secret:') %></h4> |
| 12 | - | ||
| 13 | <p><code id="secret"><%= @application.secret %></code></p> | 11 | <p><code id="secret"><%= @application.secret %></code></p> |
| 14 | 12 | ||
| 13 | + <h4><%= _('Scopes') %>:</h4> | ||
| 14 | + <p><code id="scopes"><%= @application.scopes %></code></p> | ||
| 15 | + | ||
| 15 | <h4><%= _('Callback urls:') %></h4> | 16 | <h4><%= _('Callback urls:') %></h4> |
| 16 | 17 | ||
| 17 | <table> | 18 | <table> |
| @@ -21,6 +22,7 @@ | @@ -21,6 +22,7 @@ | ||
| 21 | <code><%= uri %></code> | 22 | <code><%= uri %></code> |
| 22 | </td> | 23 | </td> |
| 23 | <td> | 24 | <td> |
| 25 | + <%= link_to _('Authorize'), oauth_authorization_path(client_id: @application.uid, redirect_uri: uri, response_type: 'code'), class: 'btn btn-success', target: '_blank' %> | ||
| 24 | </td> | 26 | </td> |
| 25 | </tr> | 27 | </tr> |
| 26 | <% end %> | 28 | <% end %> |
plugins/oauth_provider/views/doorkeeper/authorizations/error.html.erb
plugins/oauth_provider/views/doorkeeper/authorizations/new.html.erb
| 1 | <div class="oauth-provider-authorize"> | 1 | <div class="oauth-provider-authorize"> |
| 2 | - | ||
| 3 | <header class="page-header" role="banner"> | 2 | <header class="page-header" role="banner"> |
| 4 | <h1><%= _('Authorize required') %></h1> | 3 | <h1><%= _('Authorize required') %></h1> |
| 5 | </header> | 4 | </header> |
| 6 | 5 | ||
| 7 | <main role="main"> | 6 | <main role="main"> |
| 8 | <p class="h4"> | 7 | <p class="h4"> |
| 9 | - <%= _('Authorize %s to use your account?') % "<strong class=\"text-info\">#{@pre_auth.client.name}</strong>" %> | 8 | + <%= _('Authorize %s to use your account?') % "<strong class=\"text-info\">#{@pre_auth.client.name}</strong>" %> |
| 10 | </p> | 9 | </p> |
| 11 | 10 | ||
| 12 | - <% if @pre_auth.scopes %> | 11 | + <% if @pre_auth.scopes.count > 0 %> |
| 13 | <div id="oauth-permissions"> | 12 | <div id="oauth-permissions"> |
| 14 | <p><%= _('This application will be able to:') %></p> | 13 | <p><%= _('This application will be able to:') %></p> |
| 15 | 14 | ||
| 16 | <ul class="text-info"> | 15 | <ul class="text-info"> |
| 17 | <% @pre_auth.scopes.each do |scope| %> | 16 | <% @pre_auth.scopes.each do |scope| %> |
| 18 | - <li><%= OauthProviderPlugin::SCOPE_TRANSLATION[scope] %></li> | 17 | + <li><%= t scope, scope: [:doorkeeper, :scopes] %></li> |
| 19 | <% end %> | 18 | <% end %> |
| 20 | </ul> | 19 | </ul> |
| 21 | </div> | 20 | </div> |
| @@ -28,7 +27,7 @@ | @@ -28,7 +27,7 @@ | ||
| 28 | <%= hidden_field_tag :state, @pre_auth.state %> | 27 | <%= hidden_field_tag :state, @pre_auth.state %> |
| 29 | <%= hidden_field_tag :response_type, @pre_auth.response_type %> | 28 | <%= hidden_field_tag :response_type, @pre_auth.response_type %> |
| 30 | <%= hidden_field_tag :scope, @pre_auth.scope %> | 29 | <%= hidden_field_tag :scope, @pre_auth.scope %> |
| 31 | - <%= submit_button :ok, _("Authorize") %> | 30 | + <%= submit_tag _('Authorize'), class: "btn btn-success btn-lg btn-block" %> |
| 32 | <% end %> | 31 | <% end %> |
| 33 | <%= form_tag oauth_authorization_path, method: :delete do %> | 32 | <%= form_tag oauth_authorization_path, method: :delete do %> |
| 34 | <%= hidden_field_tag :client_id, @pre_auth.client.uid %> | 33 | <%= hidden_field_tag :client_id, @pre_auth.client.uid %> |
| @@ -36,7 +35,7 @@ | @@ -36,7 +35,7 @@ | ||
| 36 | <%= hidden_field_tag :state, @pre_auth.state %> | 35 | <%= hidden_field_tag :state, @pre_auth.state %> |
| 37 | <%= hidden_field_tag :response_type, @pre_auth.response_type %> | 36 | <%= hidden_field_tag :response_type, @pre_auth.response_type %> |
| 38 | <%= hidden_field_tag :scope, @pre_auth.scope %> | 37 | <%= hidden_field_tag :scope, @pre_auth.scope %> |
| 39 | - <%= submit_button :cancel, _("Deny") %> | 38 | + <%= submit_tag _('Deny'), class: "btn btn-danger btn-lg btn-block" %> |
| 40 | <% end %> | 39 | <% end %> |
| 41 | </div> | 40 | </div> |
| 42 | </main> | 41 | </main> |
plugins/oauth_provider/views/doorkeeper/authorizations/show.html.erb
plugins/oauth_provider/views/doorkeeper/authorized_applications/_delete_form.html.erb
| 1 | <%- submit_btn_css ||= 'btn btn-link' %> | 1 | <%- submit_btn_css ||= 'btn btn-link' %> |
| 2 | <%= form_tag oauth_authorized_application_path(application) do %> | 2 | <%= form_tag oauth_authorized_application_path(application) do %> |
| 3 | <input type="hidden" name="_method" value="delete"> | 3 | <input type="hidden" name="_method" value="delete"> |
| 4 | - <%= submit_tag 'Revoke', onclick: "return confirm('Are you sure?')", class: submit_btn_css %> | 4 | + <%= submit_tag _('Revoke'), onclick: "return confirm('#{ _('Are you sure?') }')", class: submit_btn_css %> |
| 5 | <% end %> | 5 | <% end %> |
plugins/oauth_provider/views/doorkeeper/authorized_applications/index.html.erb
| 1 | <div class="oauth-provider"> | 1 | <div class="oauth-provider"> |
| 2 | <header class="page-header"> | 2 | <header class="page-header"> |
| 3 | - <h1>Your authorized applications</h1> | 3 | + <h1><%= _('Your authorized applications') %></h1> |
| 4 | </header> | 4 | </header> |
| 5 | 5 | ||
| 6 | <main role="main"> | 6 | <main role="main"> |
| 7 | <table class="table table-striped"> | 7 | <table class="table table-striped"> |
| 8 | <thead> | 8 | <thead> |
| 9 | <tr> | 9 | <tr> |
| 10 | - <th>Application</th> | ||
| 11 | - <th>Created At</th> | 10 | + <th><%= _('Application') %></th> |
| 11 | + <th><%= _('Created at') %></th> | ||
| 12 | <th></th> | 12 | <th></th> |
| 13 | <th></th> | 13 | <th></th> |
| 14 | </tr> | 14 | </tr> |
| @@ -24,7 +24,6 @@ | @@ -24,7 +24,6 @@ | ||
| 24 | </tbody> | 24 | </tbody> |
| 25 | </table> | 25 | </table> |
| 26 | </main> | 26 | </main> |
| 27 | - | ||
| 28 | <div class="actions"> | 27 | <div class="actions"> |
| 29 | <%= button(:back, _('Go back'), :back) %> | 28 | <%= button(:back, _('Go back'), :back) %> |
| 30 | </div> | 29 | </div> |