Add OAuth client information page
Change-Id: Ib75d8f55e515ded75b930234a504f1a96fc27d1f
diff --git a/lib/Kalamar/Plugin/Auth.pm b/lib/Kalamar/Plugin/Auth.pm
index a419882..b9c97f8 100644
--- a/lib/Kalamar/Plugin/Auth.pm
+++ b/lib/Kalamar/Plugin/Auth.pm
@@ -678,7 +678,7 @@
}
)->finally(
sub {
- return $c->render(template => 'auth/tokens')
+ return $c->render(template => 'auth/clients')
}
);
}
@@ -712,7 +712,7 @@
else {
$c->notify(warn => $c->loc('Auth_paramError'));
};
- return $c->render(template => 'auth/tokens')
+ return $c->render(template => 'auth/clients')
};
# Wait for async result
@@ -737,8 +737,6 @@
my $json = $result->json;
- # TODO:
- # Respond in template
my $client_id = $json->{client_id};
my $client_secret = $json->{client_secret};
@@ -755,7 +753,7 @@
$c->notify(success => $c->loc('Auth_en_registerSuccess'));
- return $c->render(template => 'auth/register-success');
+ return $c->render(template => 'auth/client');
}
)->catch(
sub {
@@ -773,12 +771,14 @@
)->name('oauth-register');
+ # Unregister client
$r->get('/settings/oauth/unregister/:client_id')->to(
cb => sub {
shift->render(template => 'auth/unregister');
}
)->name('oauth-unregister');
+
# Unregister client
$r->post('/settings/oauth/unregister')->to(
cb => sub {
@@ -806,7 +806,7 @@
else {
$c->notify(warn => $c->loc('Auth_paramError'));
};
- return $c->render(template => 'auth/tokens')
+ return $c->render(template => 'auth/clients')
};
my $client_id = $v->param('client-id');
@@ -850,6 +850,50 @@
);
}
)->name('oauth-unregister-post');
+
+
+ # Show information of a client
+ $r->get('/settings/oauth/client/:client_id')->to(
+ cb => sub {
+ my $c = shift;
+
+ $c->render_later;
+
+ $c->auth->client_list_p->then(
+ sub {
+ my $json = shift;
+
+ my ($item) = grep {
+ $c->stash('client_id') eq $_->{clientId}
+ } @$json;
+
+ unless ($item) {
+ return Mojo::Promise->reject;
+ };
+
+ $c->stash(client_name => $item->{clientName});
+ $c->stash(client_desc => $item->{description});
+ $c->stash(client_url => $item->{url});
+ $c->stash(client_type => 'PUBLIC');
+
+ return Mojo::Promise->resolve;
+ }
+ )->catch(
+ sub {
+ return $c->reply->not_found;
+ }
+ )->finally(
+ sub {
+ # return $c->render(text => 'hui');
+
+
+ return $c->render(template => 'auth/client')
+ }
+ );
+
+ return;
+ }
+ )->name('oauth-tokens');
};
}
diff --git a/lib/Kalamar/Plugin/Auth/templates/auth/register-success.html.ep b/lib/Kalamar/Plugin/Auth/templates/auth/client.html.ep
similarity index 70%
rename from lib/Kalamar/Plugin/Auth/templates/auth/register-success.html.ep
rename to lib/Kalamar/Plugin/Auth/templates/auth/client.html.ep
index 527f370..38fa13d 100644
--- a/lib/Kalamar/Plugin/Auth/templates/auth/register-success.html.ep
+++ b/lib/Kalamar/Plugin/Auth/templates/auth/client.html.ep
@@ -11,8 +11,12 @@
% if (stash('client_desc')) {
<span class="client-desc"><%= stash 'client_desc' %></span>
% };
+ % if (stash('client_url')) {
+ <span class="client-url"><a href="<%= stash('client_url') %>"><%= stash('client_url') %></a></span>
+ % };
</li>
</ul>
+ <span class="button-group button-panel"><%= link_to Unregister => url_for('oauth-unregister', client_id => stash('client_id'))->query('name' => stash('client_name')) => {} => ( class => 'client-unregister' ) %></span>
<p><%= loc 'Auth_clientType' %>: <tt><%= stash 'client_type' %></tt></p>
%= label_for 'client_id' => loc('Auth_clientID')
%= text_field 'client_id', stash('client_id'), readonly => 'readonly'
diff --git a/lib/Kalamar/Plugin/Auth/templates/auth/tokens.html.ep b/lib/Kalamar/Plugin/Auth/templates/auth/clients.html.ep
similarity index 84%
rename from lib/Kalamar/Plugin/Auth/templates/auth/tokens.html.ep
rename to lib/Kalamar/Plugin/Auth/templates/auth/clients.html.ep
index d504daa..d646c89 100644
--- a/lib/Kalamar/Plugin/Auth/templates/auth/tokens.html.ep
+++ b/lib/Kalamar/Plugin/Auth/templates/auth/clients.html.ep
@@ -1,5 +1,7 @@
% extends 'settings', title => 'KorAP: '.loc('Auth_oauthSettings'), page => 'oauth';
+%# Rename to clients.html.ep
+
%= page_title
% my $list = stash('client_list');
@@ -7,9 +9,8 @@
<ul class="client-list">
% foreach (@$list) {
<li class="client">
- <span class="client-name"><%= $_->{clientName} %></span>
+ <span class="client-name"><%= link_to $_->{clientName} => url_for('oauth-tokens', client_id => $_->{clientId}) %></span>
<span class="client-desc"><%= $_->{description} %></span>
- <span class="button-group button-panel"><%= link_to Unregister => url_for('oauth-unregister', client_id => $_->{clientId})->query('name' => $_->{clientName}) => {} => ( class => 'client-unregister' ) %></span>
% if ($_->{url}) {
<span class="client-url"><a href="<%= $_->{url} %>"><%= $_->{url} %></a></span>
% }
diff --git a/t/plugin/auth-oauth.t b/t/plugin/auth-oauth.t
index cc52f9e..b211eab 100644
--- a/t/plugin/auth-oauth.t
+++ b/t/plugin/auth-oauth.t
@@ -415,7 +415,6 @@
# ->text_is('ul.client-list > li a.client-unregister', 'Unregister')
# ->attr_is('ul.client-list > li a.client-unregister', 'href', '/settings/oauth/unregister/9aHsGW6QflV13ixNpez?name=R+statistical+computing+tool')
;
-
$csrf = $t->post_ok('/settings/oauth/register' => form => {
name => 'MyApp',
type => 'PUBLIC',
@@ -443,11 +442,17 @@
$t->get_ok('/settings/oauth')
->text_is('form.form-table legend', 'Register new client application')
->attr_is('form.oauth-register','action', '/settings/oauth/register')
- ->text_is('ul.client-list > li > span.client-name', 'MyApp')
+ ->text_is('ul.client-list > li > span.client-name a', 'MyApp')
->text_is('ul.client-list > li > span.client-desc', 'This is my application')
->text_is('ul.client-list > li > span.client-url a', '')
- ->text_is('ul.client-list > li a.client-unregister', 'Unregister')
- ->attr_is('ul.client-list > li a.client-unregister', 'href', '/settings/oauth/unregister/fCBbQkA2NDA3MzM1Yw==?name=MyApp')
+ ;
+
+$t->get_ok('/settings/oauth/client/fCBbQkA2NDA3MzM1Yw==')
+ ->status_is(200)
+ ->text_is('form ul.client-list > li.client > span.client-name', 'MyApp')
+ ->text_is('form ul.client-list > li.client > span.client-desc', 'This is my application')
+ ->text_is('a.client-unregister', 'Unregister')
+ ->attr_is('a.client-unregister', 'href', '/settings/oauth/unregister/fCBbQkA2NDA3MzM1Yw==?name=MyApp')
;
$csrf = $t->get_ok('/settings/oauth/unregister/fCBbQkA2NDA3MzM1Yw==?name=MyApp')