Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hello PerlMonks, I would like to know the way we can export symbolic subroutine "'/got/:site_id' => sub" and use its array or variable in order to utilize the same at other package for calling APIs. I can return the value that i am trying access but I have dependencies of landing page from the same subroutine. Your advices are appreciated. Please check my code below

package webapp; use Dancer2; use Op; use Op1; use URI; use Net::OAuth2::Client; use HTML::Entities; use Data::Dumper; use parent 'Exporter'; our $accestoken = ""; our @access_token; sub client { Net::OAuth2::Profile::WebServer->new( client_id => 'xxxxxxxxxxxxxxxxxxx', client_secret => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx', authorize_url => 'https://dev.oktapreview.com/oauth2/ +v1/authorize', access_token_url => 'https://dev.oktapreview.com/oauth2/v1/token +', redirect_uri => uri_for ("/got/$site_id"), grant_type => 'authorization_code', ); } get '/got/:site_id' => sub { my $p = params->{code}; defined params->{code} or print "Error: Missing access code"; my $id = route_parameters->get('site_id'); my $site_id = params->{$id}; @access_token = client($site_id)->get_access_token($p); template 'query2' => { 'title' => 'webapp' }; }; post '/'=> sub { my $r2 = Op::result3({OKTAUsersList => param('OKTA-Users-List'), Email => param('Email')}); template result3 => { title => 'webapp', result3 => $r2 } }; true;

My other code where i would like to utilize @access_token in $value2 in api_call3 through my post

package Op; use strict; use warnings; use Win32::Process; use Storable; 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 webapp qw/@access_token/; use Spreadsheet::XLSX; use Spreadsheet::ParseXLSX; use Excel::Writer::XLSX; sub api_call3 { $client->default_header( 'content-type' => 'application/json' ); $client->default_header( 'Accept' => 'application/json' ); $client->default_header( 'Authorization' => "Bearer $value2" ); $client->request(HTTP::Request->new('GET', "$_[0]")); } sub result3 { my ($args) = @_; my $oktadev = $args->{OKTAUsersList}; my $email = $args->{Email}; my @responsetext; my @responsalter; $strExcelFilename1 = "C:/PERL/" . "OKTADev-Profile-User-Details" . + $date . ".xlsx"; my $apiurlapplog2 = "https://dev.oktapreview.com" ."/api/v1/users? +"; my $response = api_call3($apiurlapplog2); print "Response:\n"; @responsetext = parse_json ($response->content); my $workbook = Excel::Writer::XLSX->new( $strExcelFilename1 ); for my $i (0..$#responsetext) { my $responseid = $responsetext[$i]{id}; my $responsests = $responsetext[$i]{status}; if ($responsests ne "DEPROVISIONED") { $worksheet->write(0, 0, 'OKTA-ID'); $worksheet->write(0, 1, 'FIRST NAME'); $worksheet->write(0, 2, 'LAST NAME'); $worksheet->write($r, 0, $responseid); $worksheet->write($r, 1, $responsetext[$i]{profile}{firstName}); $worksheet->write($r, 2, $responsetext[$i]{profile}{lastName}); $r += 1; } } }

I would like to use the @access_token value in my other package. Please let me know if you need other details


In reply to Need to know the export process of Dancer 2 app. by chandantul

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-20 05:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found