Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

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

Hello Master, Sorry, Please check the latest code that is working fine in webapp.pm in order to generate the access token but my goal is to run the code snippet from app.psgi and land to main page query2.tt and export the access_token from app.psgi and use it for different subroutine in op.pm through webapp.pm. is that possible for you to help me Master?

My current app.psgi. and only last line is working webapp->to_app;

#!/usr/bin/env perl use strict; use warnings; use FindBin; use lib "$FindBin::Bin/../lib"; use webapp; use Net::OAuth2::Client; use Plack::Builder; use Plack::Request; use Dancer2; use URI; use HTML::Entities; use Data::Dumper; builder { #get '/:site_id' => sub { # my $id = route_parameters->get('site_id'); # print "$id" . "\n"; #}; get '/:site_id' => sub { my $id = route_parameters->get('site_id'); redirect client(params->{$id})->authorize; }; get '/got/:site_id' => sub { my $p = params->{code}; #template 'query2' => { 'title' => 'webapp' }; defined params->{code} or print "Error: Missing access code"; my $id = route_parameters->get('site_id'); my $site_id = params->{$id}; #my $site_id = params->{site_id}; my $access_token = client($site_id)->get_access_token(params->{cod +e}); print "Error: " . $access_token->to_string if $access_token->{err +or}; my $accestk = $access_token->to_string; my $content = "<h2>Access token retrieved successfully!</h2>\n +" . '<p>'.encode_entities($access_token->to_string)."</p +>\n"; #template 'query2' => { 'title' => 'webapp' }; $content =~ s[\n][<br/>\n]g; print "My content: $content" . "\n"; }; sub client ($){ my $id = route_parameters->get('site_id'); my $site_id = $id; #my $site_config = config->{sites}{$site_id} || {}; my $redirect = uri_for("/got/$site_id"); Net::OAuth2::Profile::WebServer->new( client_id => 'xxxxxxxxxxxxxxxxxxxxx', client_secret => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xx', authorize_url => 'https://dev.oktapreview.com/oauth2/ +v1/authorize', access_token_url => 'https://dev.oktapreview.com/oauth2/v1/token +', response_type => 'code', grant_type => 'authorization_code', scope => 'openid', state => '1234', redirect_uri => $redirect ); } webapp->to_app; }

My urrent webapp.pm

package webapp; use Dancer2; use Op; use Op1; use URI; use Net::OAuth2::Client; use HTML::Entities; use Data::Dumper; our $VERSION = '0.1'; get '/:site_id' => sub { route_parameters->get('site_id'); template 'query2' => { 'title' => 'webapp' }; }; post '/'=> sub { my $r2 = Op::result4({OKTAUsersList => param('OKTA-Users-List'), Email => param('Email')}); template result2 => { title => 'webapp', result2 => $r2 } }; true;

My query2.tt

<form id="f1" method="post" action="/"> <style> body { background-color: #ABBAEA; } div { height: 200px; background-color: #FBD603; } </style> <body> <div> <input type="radio" name="OKTAUsersList"> <label for="OKTAUsersList">OKTA-Users-List</label> <label for="Email">Recipient Email</label> <input id="email" name="Email"> <button>Submit</button> </div> </body> </form>

In reply to Re^2: Unable to execute the get method from app.psgi file for Dancer2 app. by chandantul
in thread Unable to execute the get method from app.psgi file for Dancer2 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 browsing the Monastery: (7)
As of 2024-04-25 11:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found