Hello Sir, Thanks for asking. Please check below OP.pm ,webapp.pm , app.psgi and query2.tt. I will need to know how i can connect to my authorization server and access the scopes by access token .

Op.pm

#!/usr/bin/env perl package Op; use strict; no warnings; use Win32::Process; use Storable; ##use Net::LDAP; use IO::Socket::SSL; use REST::Client; use JSON::Parse ':all'; use MIME::Base64; use Term::ReadKey; use Data::Dumper; use MIME::Lite; use Net::SMTP; use Spreadsheet::XLSX; use Spreadsheet::ParseXLSX; use Excel::Writer::XLSX; use Config::Properties; use Data::Dumper; use List::Compare; use Array::Compare; use Storable qw/freeze/; use Data::Validate::IP; use Data::Table::Excel; use Excel::Writer::XLSX::Chart; use Win32::OLE::Const; use Spreadsheet::WriteExcel::Utility qw( xl_range_formula ); use Win32::OLE; use POSIX 'strftime'; use POSIX qw(strftime); use DateTime; use DateTime::Format::Strptime; use OIDC::Lite::Client::WebServer; use Try::Tiny; use feature qw{ say }; use Mail::Sender ; use LWP; use LWP::UserAgent; use HTML::LinkExtor; use HTML::LinkExtractor; sub access_to_protected_resource { my $your_app = shift; my ($args) = @_; my $oktadev = $args->{OKTAUsersList}; #my $datver = $args->{date}; my $email = $args->{Email}; my $date = strftime '%Y-%m-%d-%H-%M-%S', localtime; my @responsetext; my @responsetextall; my $sortor = "filter=eventType+eq+%22"; my $filter = "user.authentication.sso"; my @responsalter; my $target = "%22+and+target.id+eq+%22"; my $strExcelFilename1; my $linkheader; my $pagecount1 = "limit=200"; my $r = 1; my @apiurlapplog2 = $baseurl2 ."/api/v1/users?" . $pagecount1; $strExcelFilename1 = "C:/PERL/" . "Dev-Profile-User-Details" . $date . + ".xlsx"; # my @your_app; # my $access_token = $your_app->store->get("access_token"); 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_to +ken) ); my $agent = LWP::UserAgent->new; my $res = $agent->request($req); print "Response:$res\n"; @responsetext = parse_json ($res->content); my $workbook = Excel::Writer::XLSX->new( $strExcelFilename1 ); my $my_format = $workbook->add_format( bold => 1, color => 'blue', size => 18, ); my $worksheet = $workbook->add_worksheet('UserSSO-Data'); for my $i (0..$#responsetext) { # print Dumper @responsetextall; $responsetext[$i] =~ s/]\[/,/g; #print Dumper @responsetextall; my $responseid = $responsetextall[$i]{id}; #my $responseid = $responsetextall[$i]{id}; my $responsests = $responsetextall[$i]{status}; if ($responsests ne "DEPROVISIONED") { $worksheet->write(0, 0, 'ID', $my_form +at); $worksheet->write(0, 1, 'FIRST NAME', +$my_format); $worksheet->write(0, 2, 'LAST NAME', $ +my_format); $worksheet->write($r, 0, $responseid); $worksheet->write($r, 1, $responsetext[$i]{profile}{fi +rstName}); $worksheet->write($r, 2, $responsetext[$i]{profile}{la +stName}); } } $workbook->close; print "Spreadsheet saved.\n"; my $sender1= "chandan.ghosh\@abc.com"; my $recipient3 = "$email"; my $msg1 = "<html><body><p>Dear " . $recipient3 . ",</p>"; $msg1 .= qq|<p>Please find attached Users lists details.This report wa +s generated automatically</p>|; $msg1 .= qq|<p>Regards,</p>|; $msg1 .= qq|<p>My TEAM</p>|; $msg1 .= " </body></html>"; my $sender1 = new Mail::Sender {smtp => 'relay.myorg.com', port => '25', from => $sender1}; $sender1->OpenMultipart({to => "$recipient3", subject => 'Analysis Report - For Team', }); $sender1->Part({ ctype => 'text/html', disposition => 'NONE', msg => $msg1, }); $sender1->Attach({file => "$strExcelFilename1"}); $sender1->EndPart("text/html"); $sender1->Close; }

webapp.pm

package webapp; use Dancer2; #use Dancer::Plugin::RequireSSL; use Op; use Op1; our $VERSION = '0.1'; #require_ssl(); #get '/' => sub { # template 'query' => { 'title' => 'webapp' }; #}; #post '/' => sub { # my $r = Op::result({APPID => param('APPID'), # date => param('date'), # Email => param('Email')}); # template result => { title => 'webapp', result => $r } #}; #true; get '/' => sub { template 'query2' => { 'title' => 'webapp' }; }; post '/' => sub { my $r2 = Op::access_to_protected_resource({UsersList => param('Use +rs-List'), Email => param('Email')}); template access_to_protected_resource => { title => 'webapp', acce +ss_to_protected_resource => $r2 } }; true;

I was unable to redirect to our authirization page and its giving error hence i commented the line

app.psgi

#!/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 $ad = Authen::Simple::ActiveDirectory->new( host => 'ldap://ad.myorg.com', #basedn => 'dc=ad,dc=myorg,dc=com', principal => 'ad.myorg.com', timeout => '60', log => Log::Log4perl->get_logger('Authen::Simple::ActiveDirectory' +) ); my $client1 = OIDC::Lite::Client::WebServer->new( id => q{xxxxxxxxxxxxxxxxxxxxxxxx}, secret => q{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +x}, 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::Auth::OIDC::ProtectedResource", data_handler => "webapp::DataHandler", error_uri => q{http://example.org/error/description}; enable "Plack::Middleware::JSONP"; enable "Plack::Middleware::ContentLength"; webapp->to_app; };code> <p>query.tt code</p> <code><form id="f1" method="post" action="/"> <style> body { background-color: #ABBAEA; } div { height: 200px; background-color: #FBD603; } </style> <body> <div> <input type="radio" name="UsersList"> <label for="UsersList">Users-List</label> <label for="Email">Recipient Email</label> <input id="email" name="Email"> <button>Submit</button> </div> </body> </form>

Error: Its not redirecting to authoruzation page and nothing is happening.


In reply to Re^18: Need to know the process to implement perl script into web application server. by chandantul
in thread Need to know the process to implement perl script into web application server. by chandantul

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.