Commit 53d4dc1c53bf48223c9f093f396e2084dbf38fb1

Authored by Victor Costa
1 parent 756b3931

oauth_provider: customize views

plugins/oauth_provider/lib/oauth_provider_plugin.rb
@@ -9,18 +9,14 @@ class OauthProviderPlugin < Noosfero::Plugin @@ -9,18 +9,14 @@ class OauthProviderPlugin < Noosfero::Plugin
9 end 9 end
10 10
11 Doorkeeper.configure do 11 Doorkeeper.configure do
12 - # Change the ORM that doorkeeper will use.  
13 - # Currently supported options are :active_record, :mongoid2, :mongoid3, :mongo_mapper  
14 orm :active_record 12 orm :active_record
15 13
16 - # This block will be called to check whether the resource owner is authenticated or not.  
17 resource_owner_authenticator do 14 resource_owner_authenticator do
18 domain = Domain.find_by_name(request.host) 15 domain = Domain.find_by_name(request.host)
19 environment = domain ? domain.environment : Environment.default 16 environment = domain ? domain.environment : Environment.default
20 environment.users.find_by_id(session[:user]) || redirect_to('/account/login') 17 environment.users.find_by_id(session[:user]) || redirect_to('/account/login')
21 end 18 end
22 19
23 - # If you want to restrict access to the web interface for adding oauth authorized applications, you need to declare the block below.  
24 admin_authenticator do 20 admin_authenticator do
25 domain = Domain.find_by_name(request.host) 21 domain = Domain.find_by_name(request.host)
26 environment = domain ? domain.environment : Environment.default 22 environment = domain ? domain.environment : Environment.default
@@ -31,77 +27,7 @@ class OauthProviderPlugin < Noosfero::Plugin @@ -31,77 +27,7 @@ class OauthProviderPlugin < Noosfero::Plugin
31 user 27 user
32 end 28 end
33 29
34 - # Authorization Code expiration time (default 10 minutes).  
35 - # authorization_code_expires_in 10.minutes  
36 -  
37 - # Access token expiration time (default 2 hours).  
38 - # If you want to disable expiration, set this to nil.  
39 - # access_token_expires_in 2.hours  
40 -  
41 - # Reuse access token for the same resource owner within an application (disabled by default)  
42 - # Rationale: https://github.com/doorkeeper-gem/doorkeeper/issues/383  
43 - # reuse_access_token  
44 -  
45 - # Issue access tokens with refresh token (disabled by default)  
46 - # use_refresh_token  
47 -  
48 - # Provide support for an owner to be assigned to each registered application (disabled by default)  
49 - # Optional parameter :confirmation => true (default false) if you want to enforce ownership of  
50 - # a registered application  
51 - # Note: you must also run the rails g doorkeeper:application_owner generator to provide the necessary support  
52 - # enable_application_owner :confirmation => false  
53 -  
54 - # Define access token scopes for your provider  
55 - # For more information go to  
56 - # https://github.com/doorkeeper-gem/doorkeeper/wiki/Using-Scopes  
57 - # default_scopes :public  
58 - # optional_scopes :write, :update  
59 -  
60 - # Change the way client credentials are retrieved from the request object.  
61 - # By default it retrieves first from the `HTTP_AUTHORIZATION` header, then  
62 - # falls back to the `:client_id` and `:client_secret` params from the `params` object.  
63 - # Check out the wiki for more information on customization  
64 - # client_credentials :from_basic, :from_params  
65 -  
66 - # Change the way access token is authenticated from the request object.  
67 - # By default it retrieves first from the `HTTP_AUTHORIZATION` header, then  
68 - # falls back to the `:access_token` or `:bearer_token` params from the `params` object.  
69 - # Check out the wiki for more information on customization  
70 - # access_token_methods :from_bearer_authorization, :from_access_token_param, :from_bearer_param  
71 -  
72 - # Change the native redirect uri for client apps  
73 - # When clients register with the following redirect uri, they won't be redirected to any server and the authorization code will be displayed within the provider  
74 - # The value can be any string. Use nil to disable this feature. When disabled, clients must provide a valid URL  
75 - # (Similar behaviour: https://developers.google.com/accounts/docs/OAuth2InstalledApp#choosingredirecturi)  
76 - #  
77 - # native_redirect_uri 'urn:ietf:wg:oauth:2.0:oob'  
78 -  
79 - # Specify what grant flows are enabled in array of Strings. The valid  
80 - # strings and the flows they enable are:  
81 - #  
82 - # "authorization_code" => Authorization Code Grant Flow  
83 - # "implicit" => Implicit Grant Flow  
84 - # "password" => Resource Owner Password Credentials Grant Flow  
85 - # "client_credentials" => Client Credentials Grant Flow  
86 - #  
87 - # If not specified, Doorkeeper enables all the four grant flows.  
88 - #  
89 - # grant_flows %w(authorization_code implicit password client_credentials)  
90 -  
91 - # Under some circumstances you might want to have applications auto-approved,  
92 - # so that the user skips the authorization step.  
93 - # For example if dealing with trusted a application.  
94 - # skip_authorization do |resource_owner, client|  
95 - # client.superapp? or resource_owner.admin?  
96 - # end  
97 -  
98 - # WWW-Authenticate Realm (default "Doorkeeper").  
99 - # realm "Doorkeeper"  
100 -  
101 - # Allow dynamic query parameters (disabled by default)  
102 - # Some applications require dynamic query parameters on their request_uri  
103 - # set to true if you want this to be allowed  
104 - # wildcard_redirect_uri false 30 + default_scopes :public
105 end 31 end
106 32
107 Rails.configuration.to_prepare do 33 Rails.configuration.to_prepare do
@@ -117,4 +43,8 @@ class OauthProviderPlugin < Noosfero::Plugin @@ -117,4 +43,8 @@ class OauthProviderPlugin < Noosfero::Plugin
117 end 43 end
118 end 44 end
119 45
  46 + SCOPE_TRANSLATION = {
  47 + 'public' => _('Access your public data')
  48 + }
  49 +
120 end 50 end
plugins/oauth_provider/views/doorkeeper/applications/_form.html.erb
1 <%= form_for [:oauth, application], html: {class: 'form-horizontal', role: 'form'} do |f| %> 1 <%= form_for [:oauth, application], html: {class: 'form-horizontal', role: 'form'} do |f| %>
2 <% if application.errors.any? %> 2 <% if application.errors.any? %>
3 - <div class="alert alert-danger" data-alert><p>Whoops! Check your form for possible errors</p></div> 3 + <div class="alert alert-danger" data-alert>
  4 + <p><%= _('Whoops! Check your form for possible errors') %></p>
  5 + </div>
4 <% end %> 6 <% end %>
5 7
6 <%= content_tag :div, class: "form-group#{' has-error' if application.errors[:name].present?}" do %> 8 <%= content_tag :div, class: "form-group#{' has-error' if application.errors[:name].present?}" do %>
@@ -17,7 +19,7 @@ @@ -17,7 +19,7 @@
17 <%= f.text_area :redirect_uri, class: 'form-control' %> 19 <%= f.text_area :redirect_uri, class: 'form-control' %>
18 <%= doorkeeper_errors_for application, :redirect_uri %> 20 <%= doorkeeper_errors_for application, :redirect_uri %>
19 <span class="help-block"> 21 <span class="help-block">
20 - Use one line per URI 22 + <%= _('Use one line per URI') %>
21 </span> 23 </span>
22 <% if Doorkeeper.configuration.native_redirect_uri %> 24 <% if Doorkeeper.configuration.native_redirect_uri %>
23 <span class="help-block"> 25 <span class="help-block">
@@ -29,8 +31,8 @@ @@ -29,8 +31,8 @@
29 31
30 <div class="form-group"> 32 <div class="form-group">
31 <div class="col-sm-offset-2 col-sm-10"> 33 <div class="col-sm-offset-2 col-sm-10">
32 - <%= f.submit 'Submit', class: "btn btn-primary" %>  
33 - <%= link_to "Cancel", oauth_applications_path, :class => "btn btn-default" %> 34 + <%= f.submit _('Submit'), class: "btn btn-primary" %>
  35 + <%= link_to _("Cancel"), oauth_applications_path, :class => "btn btn-default" %>
34 </div> 36 </div>
35 </div> 37 </div>
36 <% end %> 38 <% end %>
plugins/oauth_provider/views/doorkeeper/applications/edit.html.erb
1 <div class="page-header"> 1 <div class="page-header">
2 - <h1>Edit application</h1> 2 + <h1><%= _('Edit application') %></h1>
3 </div> 3 </div>
4 4
5 <%= render 'form', application: @application %> 5 <%= render 'form', application: @application %>
plugins/oauth_provider/views/doorkeeper/applications/index.html.erb
1 <div class="page-header"> 1 <div class="page-header">
2 - <h1>Your applications</h1> 2 + <h3><%= link_to _('Oauh Provider'), '/admin/plugin/oauth_provider' %></h3>
3 </div> 3 </div>
4 4
5 -<p><%= link_to 'New Application', new_oauth_application_path, class: 'btn btn-success' %></p> 5 +<p><%= link_to _('New Application'), new_oauth_application_path, class: 'btn btn-success' %></p>
6 6
7 <table class="table table-striped"> 7 <table class="table table-striped">
8 <thead> 8 <thead>
9 <tr> 9 <tr>
10 - <th>Name</th>  
11 - <th>Callback URL</th> 10 + <th><%= _('Name') %></th>
  11 + <th><%= _('Callback URL') %></th>
12 <th></th> 12 <th></th>
13 <th></th> 13 <th></th>
14 </tr> 14 </tr>
@@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
18 <tr id="application_<%= application.id %>"> 18 <tr id="application_<%= application.id %>">
19 <td><%= link_to application.name, [:oauth, application] %></td> 19 <td><%= link_to application.name, [:oauth, application] %></td>
20 <td><%= application.redirect_uri %></td> 20 <td><%= application.redirect_uri %></td>
21 - <td><%= link_to 'Edit', edit_oauth_application_path(application), class: 'btn btn-link' %></td> 21 + <td><%= link_to _('Edit'), edit_oauth_application_path(application), class: 'btn btn-link' %></td>
22 <td><%= render 'delete_form', application: application %></td> 22 <td><%= render 'delete_form', application: application %></td>
23 </tr> 23 </tr>
24 <% end %> 24 <% end %>
plugins/oauth_provider/views/doorkeeper/applications/show.html.erb
1 <div class="page-header"> 1 <div class="page-header">
2 - <h1>Application: <%= @application.name %></h1> 2 + <h1><%= _('Application: %s' % @application.name) %></h1>
3 </div> 3 </div>
4 4
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 8
9 <p><code id="application_id"><%= @application.uid %></code></p> 9 <p><code id="application_id"><%= @application.uid %></code></p>
10 10
11 - <h4>Secret:</h4> 11 + <h4><%= _('Secret:') %></h4>
12 12
13 <p><code id="secret"><%= @application.secret %></code></p> 13 <p><code id="secret"><%= @application.secret %></code></p>
14 14
15 - <h4>Callback urls:</h4> 15 + <h4><%= _('Callback urls:') %></h4>
16 16
17 <table> 17 <table>
18 <% @application.redirect_uri.split.each do |uri| %> 18 <% @application.redirect_uri.split.each do |uri| %>
@@ -21,7 +21,6 @@ @@ -21,7 +21,6 @@
21 <code><%= uri %></code> 21 <code><%= uri %></code>
22 </td> 22 </td>
23 <td> 23 <td>
24 - <%= link_to 'Authorize', oauth_authorization_path(client_id: @application.uid, redirect_uri: uri, response_type: 'code'), class: 'btn btn-success', target: '_blank' %>  
25 </td> 24 </td>
26 </tr> 25 </tr>
27 <% end %> 26 <% end %>
@@ -29,9 +28,12 @@ @@ -29,9 +28,12 @@
29 </div> 28 </div>
30 29
31 <div class="col-md-4"> 30 <div class="col-md-4">
32 - <h3>Actions</h3> 31 + <h3><%= _('Actions') %></h3>
33 32
34 - <p><%= link_to 'Edit', edit_oauth_application_path(@application), class: 'btn btn-primary' %></p> 33 + <p>
  34 + <%= link_to _('Edit'), edit_oauth_application_path(@application), class: 'btn btn-primary' %>
  35 + <%= link_to _("Cancel"), oauth_applications_path, :class => "btn btn-default" %>
  36 + </p>
35 37
36 <p><%= render 'delete_form', application: @application, submit_btn_css: 'btn btn-danger' %></p> 38 <p><%= render 'delete_form', application: @application, submit_btn_css: 'btn btn-danger' %></p>
37 </div> 39 </div>
plugins/oauth_provider/views/doorkeeper/authorizations/new.html.erb
1 <header class="page-header" role="banner"> 1 <header class="page-header" role="banner">
2 - <h1>Authorize required</h1> 2 + <h1><%= _('Authorize required') %></h1>
3 </header> 3 </header>
4 4
5 <main role="main"> 5 <main role="main">
6 <p class="h4"> 6 <p class="h4">
7 - Authorize <strong class="text-info"><%= @pre_auth.client.name %></strong> to use your account? 7 + <%= _('Authorize %s to use your account?' % "<strong class=\"text-info\">#{@pre_auth.client.name}</strong>") %>
8 </p> 8 </p>
9 9
10 <% if @pre_auth.scopes %> 10 <% if @pre_auth.scopes %>
11 <div id="oauth-permissions"> 11 <div id="oauth-permissions">
12 - <p>This application will be able to:</p> 12 + <p><%= _('This application will be able to:') %></p>
13 13
14 <ul class="text-info"> 14 <ul class="text-info">
15 <% @pre_auth.scopes.each do |scope| %> 15 <% @pre_auth.scopes.each do |scope| %>
16 - <li><%= t scope, scope: [:doorkeeper, :scopes] %></li> 16 + <li><%= OauthProviderPlugin::SCOPE_TRANSLATION[scope] %></li>
17 <% end %> 17 <% end %>
18 </ul> 18 </ul>
19 </div> 19 </div>
@@ -26,7 +26,7 @@ @@ -26,7 +26,7 @@
26 <%= hidden_field_tag :state, @pre_auth.state %> 26 <%= hidden_field_tag :state, @pre_auth.state %>
27 <%= hidden_field_tag :response_type, @pre_auth.response_type %> 27 <%= hidden_field_tag :response_type, @pre_auth.response_type %>
28 <%= hidden_field_tag :scope, @pre_auth.scope %> 28 <%= hidden_field_tag :scope, @pre_auth.scope %>
29 - <%= submit_tag "Authorize", class: "btn btn-success btn-lg btn-block" %> 29 + <%= submit_tag _("Authorize"), class: "btn btn-success btn-lg btn-block" %>
30 <% end %> 30 <% end %>
31 <%= form_tag oauth_authorization_path, method: :delete do %> 31 <%= form_tag oauth_authorization_path, method: :delete do %>
32 <%= hidden_field_tag :client_id, @pre_auth.client.uid %> 32 <%= hidden_field_tag :client_id, @pre_auth.client.uid %>
@@ -34,7 +34,7 @@ @@ -34,7 +34,7 @@
34 <%= hidden_field_tag :state, @pre_auth.state %> 34 <%= hidden_field_tag :state, @pre_auth.state %>
35 <%= hidden_field_tag :response_type, @pre_auth.response_type %> 35 <%= hidden_field_tag :response_type, @pre_auth.response_type %>
36 <%= hidden_field_tag :scope, @pre_auth.scope %> 36 <%= hidden_field_tag :scope, @pre_auth.scope %>
37 - <%= submit_tag "Deny", class: "btn btn-danger btn-lg btn-block" %> 37 + <%= submit_tag _("Deny"), class: "btn btn-danger btn-lg btn-block" %>
38 <% end %> 38 <% end %>
39 </div> 39 </div>
40 </main> 40 </main>
plugins/oauth_provider/views/oauth_provider_plugin_admin/index.html.erb
1 <div class="oauth-provider"> 1 <div class="oauth-provider">
2 - <h3><%= _('Oauh Provider') %></h3> 2 +<h3><%= _('Oauh Provider') %></h3>
3 3
4 <div class="applications"> 4 <div class="applications">
5 <%= link_to _('Applications'), oauth_applications_path %> 5 <%= link_to _('Applications'), oauth_applications_path %>