sub access_to_protected_resource {
my $your_app = shift;
my ($args) = @_;
my $dev = $args->{OKTAUsersList};
my $email = $args->{Email};
my $date = strftime '%Y-%m-%d-%H-%M-%S', localtime;
my @responsetext;
my @responsetextall;
my $strExcelFilename1;
my $linkheader;
my $pagecount1 = "limit=200";
my $r = 1;
my @apiurlapplog2 = $baseurl2 ."/api/v1/users?" . $pagecount1;
$strExcelFilename1 = "C:/PERL/" . "Profile-User-Details" . $date . ".xlsx";
my $access_token = $your_app->store->get("access_token");
my $expires_at = $your_app->store->get("expires_at");
my $refresh_token = $your_app->store->get("refresh_token");
unless ($access_token) {
$your_app->start_authorize();
return;
}
if ($expires_at < time()) {
$your_app->refresh_access_token();
return;
}
# my $req = HTTP::Request->new( ('GET', "$_[0]"));
my $req = HTTP::Request->new( GET => q{https://dev.preview.com/api/v1/users?limit=200});
#$req->header( Authorization => sprintf(q{Bearer}, $access_token) );
$req->header( Authorization => sprintf(q{OAuth %s}, $access_token) );
my $agent = LWP::UserAgent->new;
my $res = $agent->request($req);
print "Response:$res\n";
}
####
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../lib";
use Plack::Middleware;
# use this block if you don't need middleware, and only have a single target Dancer app to run here
use webapp;
use Plack::Builder;
use Authen::Simple::ActiveDirectory;
use OIDC::Lite::Client::WebServer;
use Log::Log4perl;
my $client1 = OIDC::Lite::Client::WebServer->new(
id => q{xxxxxxxxxxxx},
secret => q{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx},
authorize_uri => q{https://dev.preview.com/oauth2/v1/authorize},
access_token_uri => q{https://dev.preview.com/oauth2/v1/token},
);
sub start_authorize {
my $your_app = shift;
my $redirect_url = $client1->uri_to_redirect(
redirect_uri => q{https://testchandan.com:5001/callback},
scope => q{openid},
);
}
builder {
enable "Plack::Middleware" , start_authorize, webapp->to_app;
};
####
Can't locate object method "call" via package "Plack::Middleware" at C:/Strawberry/perl/site/lib/Plack/Component.pm line 50, line 755.
at C:\Strawberry\perl\site\lib\Plack\Component.pm line 50
in Plack::Component::__ANON__ at C:\Strawberry\perl\site\lib\Plack\Component.pm line 50
47: sub to_app {
48: my $self = shift;
49: $self->prepare_app;
50: return sub { $self->call(@_) };
51: }
52:
53:
Show function arguments
in Plack::Middleware::Lint::call at C:\Strawberry\perl\site\lib\Plack\Middleware\Lint.pm line 24
21: my $env = shift;
22:
23: $self->validate_env($env);
24: my $res = $self->app->($env);
25: return $self->validate_res($res);
26: }
27:
Show function arguments
in Plack::Middleware::StackTrace::try {...} at C:\Strawberry\perl\site\lib\Plack\Component.pm line 50
47: sub to_app {
48: my $self = shift;
49: $self->prepare_app;
50: return sub { $self->call(@_) };
51: }
52:
53:
in (eval) at C:\Strawberry\perl\vendor\lib\Try\Tiny.pm line 100
97: if ( $wantarray ) {
98: @ret = $try->();
99: } elsif ( defined $wantarray ) {
100: $ret[0] = $try->();
101: } else {
102: $try->();
103: };
in Plack::Middleware::StackTrace::call at C:\Strawberry\perl\vendor\lib\Try\Tiny.pm line 93
90:
91: # failed will be true if the eval dies, because 1 will not be returned
92: # from the eval body
93: my $failed = not eval {
94: $@ = $prev_error;
95:
96: # evaluate the try block in the correct context
Show function arguments
in Plack::Component::__ANON__ at C:\Strawberry\perl\site\lib\Plack\Component.pm line 50
47: sub to_app {
48: my $self = shift;
49: $self->prepare_app;
50: return sub { $self->call(@_) };
51: }
52:
53:
Show function arguments
in Plack::Middleware::AccessLog::call at C:\Strawberry\perl\site\lib\Plack\Middleware\AccessLog.pm line 27
24: my $self = shift;
25: my($env) = @_;
26:
27: my $res = $self->app->($env);
28:
29: if ( ref($res) && ref($res) eq 'ARRAY' ) {
30: my $content_length = Plack::Util::content_length($res->[2]);
Show function arguments
in Plack::Component::__ANON__ at C:\Strawberry\perl\site\lib\Plack\Component.pm line 50
47: sub to_app {
48: my $self = shift;
49: $self->prepare_app;
50: return sub { $self->call(@_) };
51: }
52:
53:
Show function arguments
in Plack::Middleware::ContentLength::call at C:\Strawberry\perl\site\lib\Plack\Middleware\ContentLength.pm line 10
7:
8: sub call {
9: my $self = shift;
10: my $res = $self->app->(@_);
11:
12: return $self->response_cb($res, sub {
13: my $res = shift;
Show function arguments
in Plack::Component::__ANON__ at C:\Strawberry\perl\site\lib\Plack\Component.pm line 50
47: sub to_app {
48: my $self = shift;
49: $self->prepare_app;
50: return sub { $self->call(@_) };
51: }
52:
53:
Show function arguments
in (eval) at C:\Strawberry\perl\site\lib\Plack\Util.pm line 145
142: sub run_app($$) {
143: my($app, $env) = @_;
144:
145: return eval { $app->($env) } || do {
146: my $body = "Internal Server Error";
147: $env->{'psgi.errors'}->print($@);
148: [ 500, [ 'Content-Type' => 'text/plain', 'Content-Length' => length($body) ], [ $body ] ];
in Plack::Util::run_app at C:\Strawberry\perl\site\lib\Plack\Util.pm line 145
142: sub run_app($$) {
143: my($app, $env) = @_;
144:
145: return eval { $app->($env) } || do {
146: my $body = "Internal Server Error";
147: $env->{'psgi.errors'}->print($@);
148: [ 500, [ 'Content-Type' => 'text/plain', 'Content-Length' => length($body) ], [ $body ] ];
Show function arguments
in HTTP::Server::PSGI::handle_connection at C:\Strawberry\perl\site\lib\HTTP\Server\PSGI.pm line 182
179: $env->{'psgi.input'} = $input;
180: }
181:
182: $res = Plack::Util::run_app $app, $env;
183: last;
184: }
185: if ($reqlen == -2) {
Show function arguments
in HTTP::Server::PSGI::accept_loop at C:\Strawberry\perl\site\lib\HTTP\Server\PSGI.pm line 141
138: 'psgix.io' => $conn,
139: };
140:
141: $self->handle_connection($env, $conn, $app);
142: $conn->close;
143: last if $env->{'psgix.harakiri.commit'};
144: }
Show function arguments
in HTTP::Server::PSGI::run at C:\Strawberry\perl\site\lib\HTTP\Server\PSGI.pm line 63
60: sub run {
61: my($self, $app) = @_;
62: $self->setup_listener();
63: $self->accept_loop($app);
64: }
65:
66: sub prepare_socket_class {
Show function arguments
in Plack::Handler::HTTP::Server::PSGI::run at C:\Strawberry\perl\site\lib\Plack\Handler\HTTP\Server\PSGI.pm line 14
11:
12: sub run {
13: my($self, $app) = @_;
14: $self->_server->run($app);
15: }
16:
17: sub _server {
Show function arguments
in Plack::Loader::run at C:\Strawberry\perl\site\lib\Plack\Loader.pm line 84
81:
82: sub run {
83: my($self, $server, $builder) = @_;
84: $server->run($self->{app});
85: }
86:
87: 1;
Show function arguments
in Plack::Runner::run at C:\Strawberry\perl\site\lib\Plack\Runner.pm line 279
276: $loader->preload_app($app);
277:
278: my $server = $self->load_server($loader);
279: $loader->run($server);
280: }
281:
282: 1;
Show function arguments
at C:\Strawberry\perl\site\bin\plackup line 7
4:
5: my $runner = Plack::Runner->new;
6: $runner->parse_options(@ARGV);
7: $runner->run;
8:
9: __END__
10: