-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMojoliciousAPI.pm
51 lines (40 loc) · 1.64 KB
/
MojoliciousAPI.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package MojoliciousAPI;
use strict;
use warnings;
use Mojo::Base 'Mojolicious';
use Log::Log4perl;
use Mojolicious::Plugin::OAuth2;
sub startup {
my $self = shift;
my $config = $self->plugin( 'JSONConfig' => { file => 'MojoliciousAPI.json' } );
$self->config($config);
$self->mode($config->{mode});
$self->secrets([$config->{secret}]);
push @{$self->static->paths} => 'public';
Log::Log4perl::init('log4perl.conf');
my $log = Log::Log4perl::get_logger("MojoliciousAPI");
$self->log($log);
if($config->{ssl_ca_path}) {
$self->app->log->debug("Setting SSL_ca_path: ".$config->{ssl_ca_path});
IO::Socket::SSL::set_defaults(
SSL_ca_path => $config->{ssl_ca_path}
);
}
$self->plugin("OAuth2" => {
oauthprovider => {
key => $config->{auth}->{oauth}->{client_id},
secret => $config->{auth}->{oauth}->{client_secret},
authorize_url => "https://".$config->{auth}->{oauth}->{authorization_server}."/authorize?response_type=code",
token_url => "https://".$config->{auth}->{oauth}->{authorization_server}."/token"
}
});
my $r = $self->routes;
$r->namespaces(['MojoliciousAPI::Controller']);
$r->route('/') ->via('get') ->to('authn#index');
$r->route('connect') ->via('get') ->to('authn#connect');
$r->route('logout') ->via('get') ->to('authn#logout');
my $check_auth = $r->under('/')->to('authn#authenticate');
$check_auth->route('profile') ->via('get') ->to('authn#profile');
return $self;
}
1;