Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Unable to execute the get method from app.psgi file for Dancer2 app.

by chandantul (Scribe)
on Jun 21, 2021 at 15:35 UTC ( #11134115=note: print w/replies, xml ) Need Help??


in reply to Re: Unable to execute the get method from app.psgi file for Dancer2 app.
in thread Unable to execute the get method from app.psgi file for Dancer2 app.

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>

Replies are listed 'Best First'.
Re^3: Unable to execute the get method from app.psgi file for Dancer2 app.
by 1nickt (Abbot) on Jun 21, 2021 at 15:59 UTC

    Why don;t you have your route declarations (and the client() sub for that matter) in webapp.pm ? I do not ever place route declarations inside the builder() sub; I've never seen that. My app.psgi is almost empty except for use statements and to_app().


    The way forward always starts with a minimal test.
    A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11134115]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2021-12-08 00:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (34 votes). Check out past polls.

    Notices?